• 首先需要知道区段查询的定义:

索引系统需要通过主查询来获取全部的文档信息,一种简单的实现是将整个表的数据读入内存,但是这可能导致整个表被锁定并使得其他操作被阻止(例如:在MyISAM格式上的INSERT操作),同时,将浪费大量内存用于存储查询结果,诸如此类的问题吧。 为了避免出现这种情况,CoreSeek/Sphinx支持一种被称为 区段查询的技术. 首先,CoreSeek/Sphinx从数据库中取出文档ID的最小值和最大值,将由最大值和最小值定义自然数区间分成若干份,一次获取数据,建立索引。现举例如下:

例 3.1. 范围查询用法举例

# in sphinx.conf

sql_query_range    = SELECT MIN(id),MAX(id) FROM documents
sql_range_step =
sql_query = SELECT * FROM documents WHERE id>=$start AND id<=$end

如果这个表(documents)中,字段ID的最小值和最大值分别是1 和2345,则sql_query将执行3次:

  1. $start 替换为1,并且将 $end 替换为 1000;
  2. $start 替换为1001,并且将 $end 替换为 2000;
  3. $start 替换为2001,并且将 $end 替换为 2345.

显然,这对于只有2000行的表,分区查询与整个读入没有太大区别,但是当表的规模扩大到千万级(特别是对于MyISAM格式的表),分区区段查询将提供一些帮助。

  • 以上是coreseek 文档上的定义,分享一下本机测试实例:

之前做一套域名MX解析系统的时候获取过几百万的域名www title 信息,下面就用检索www 网站titile 数据来测试。

编辑用于测试的 coreseek 配置文件 csft.range.conf

source src
{
type = mysql
# some straightforward parameters for SQL source types
sql_host = localhost
sql_user = root
sql_pass = xxxxxxxxxxxxx
sql_db = whomx
sql_port = # optional, default is 3306
        sql_query_pre          = SET NAMES utf8
        sql_query_pre          = SET SESSION query_cache_type=OFF
     sql_query              = \
     SELECT i.id,title \
            FROM  mx_domain_wwwinfo i \
           WHERE id>=$start AND id<=$end   
         sql_query_range      = SELECT MIN(id),MAX(id) FROM mx_domain_wwwinfo
}

index 配置只需要配置中文字符编码   还有中文词库的位置就可

indexer searchd 不需要更改。

接下来测试一下,

  • 生成索引:
root@timeless-HP-Pavilion-g4-Notebook-PC:/usr/local/coreseek/etc# /usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft.range.conf   --all --rotate
Coreseek Fulltext 4.1 [ Sphinx 2.0.-dev (r2922)]
Copyright (c) -,
Beijing Choice Software Technologies Inc (http://www.coreseek.com) using config file '/usr/local/coreseek/etc/csft.range.conf'...
WARNING: failed to open pid_file '/usr/local/coreseek/var/log/searchd.pid'.
indexing index 'src'...
WARNING: Attribute count is : switching to none docinfo
collected docs, 92.2 MB
sorted 17.5 Mhits, 100.0% done
total docs, bytes
total 34.680 sec, bytes/sec, 43275.54 docs/sec
total reads, 0.023 sec, 3631.5 kb/call avg, 1.4 msec/call avg
total writes, 0.105 sec, 912.1 kb/call avg, 0.7 msec/call avg
  • 根据某个关键词测试:
  • root@timeless-HP-Pavilion-g4-Notebook-PC:/usr/local/coreseek/bin# ./search -c /usr/local/coreseek/etc/csft.range.conf  济南
    Coreseek Fulltext 4.1 [ Sphinx 2.0.-dev (r2922)]
    Copyright (c) -,
    Beijing Choice Software Technologies Inc (http://www.coreseek.com) using config file '/usr/local/coreseek/etc/csft.range.conf'...
    index 'src': query '济南 ': returned matches of total in 0.005 sec displaying matches:
    . document=, weight=
    id=
    domain_id=
    title=?????????????,??????,??????,?????????????????????????????????????,??????,??????,????,????,??????,??????,??????,??????,????????,????,??????,??????,??????,??????,????????,????????,?????????,?????????
    addtime=
    . document=, weight=
    id=
    domain_id=
    title=??--??????,?????,????????,????????,??????,??????,?????,?????,???,?????,?????,?????,?????,????,????,??????,??????,??????,?????,?????,?????,???,???????,
    addtime=
    . document=, weight=
    id=
    domain_id=
    title=???????-???.??.???.???????/?????/?????/?????????/?????/?????/???? ????? ????? ????? ????? ????? ????? ??POS??? ????? ????? ????? ??POS?
    addtime=
    . document=, weight=
    id=
    domain_id=
    title=???????-???.??.???.???????/?????/?????/?????????/?????/?????/???? ????? ????? ????? ????? ????? ????? ??POS??? ????? ????? ????? ??POS?
    addtime=
    . document=, weight=
    id=
    domain_id=
    title=?????? - ???? | ????? | ????? | ?????? | ?????? | ?????? | ?????? | ?????? | ?????? | ?????? | ?????? | ?????? | ?????? | ??????
    addtime=
    . document=, weight=
    id=
    domain_id=
    title=????????|????????|?????????|?????????|??????|?????|????????????????|????????|?????????|?????????|??????|?????|????????
    addtime=
    . document=, weight=
    id=
    domain_id=
    title=???????????????????????????????????????????????????????????????????????????????????????????????????????
    addtime=
    . document=, weight=
    id=
    domain_id=
    title=????|??????|????????|??????|??????|??????|??????|??????|??????|??????|??????-????????
    addtime=
    . document=, weight=
    id=
    domain_id=
    title=????????????????????????????????????????????????????????????????????
    addtime=
    . document=, weight=
    id=
    domain_id=
    title=??????|??????|??SKF??|??NSK??|??FAG??|??NTN??|??KOYO??|??TIMKEN??|??FAG??|????|????????|????????|??????|-??
    addtime=
    . document=, weight=
    id=
    domain_id=
    title=???????|??????????|???????|??????????|??????|???????|?????????|????????|?????????|???????|??????????
    addtime=
    . document=, weight=
    id=
    domain_id=
    title=???? ?????? ?????? ?????? ????? ?????? ???? ???? ?????? ???? ??????
    addtime=
    . document=, weight=
    id=
    domain_id=
    title=??????|????|?????|?????????|???????????|??????|??????|????|?????|?????|?????|?????
    addtime=
    . document=, weight=
    id=
    domain_id=
    title=??????????????????????????????????????????????????????????????????????????????_??????????????
    addtime=
    . document=, weight=
    id=
    domain_id=
    title=?????????????????????????????????????????????????????????????????????????_??????????????
    addtime=
    . document=, weight=
    id=
    domain_id=
    title=????????????????????????????????????????????????????????????????????????????_??????????????
    addtime=
    . document=, weight=
    id=
    domain_id=
    title=??????|??????|??????|??????|??????|?????|??????|????????|???????????|????????????|???--
    addtime=
    . document=, weight=
    id=
    domain_id=
    title=????????? ???????????? ??????? ?????????? ??????? ??????? ????????? ??????? ??????? ???????_?????????
    addtime=
    . document=, weight=
    id=
    domain_id=
    title=????-|??????|??????????????|????????|???????|??????|????T1|????T3|????T6|????U8
    addtime=
    . document=, weight=
    id=
    domain_id=
    title=????|?????|?????|?????|?????|?????|?????|?????|????|??????????
    addtime= words:
    . '济南': documents, hits

    可以看到结果 :1. '济南': 11040 documents, 22214 hits  以上显示只是 编码问题。

      接下来还有个问题  比如 现在 要增量索引跟区段查询综合在一起怎么办?  下面文章根据百度文库里找到的一篇关于

《千万级Discuz!数据全文检索方案(Sphinx)》 综合使用coreseek 实现检索。

sphinx (coreseek)——2、区段查询实例的更多相关文章

  1. sphinx (coreseek)——3、区段查询 与 增量索引实例

    首先本文测试数据100多万的域名的wwwtitle 信息  检索数据: 首先建立临时表格: CREATE TABLE `sph_counter` ( `index_id` ) NOT NULL, `m ...

  2. Coreseek:区段查询及增量索引取代实时索引

    1.区段查询 索引系统须要通过主查询来获取所有的文档信息,一种简单的实现是将整个表的数据读入内存,可是这可能导致整个表被锁定并使得其它操作被阻止(比如:在MyISAM格式上的INSERT操作),同一时 ...

  3. 【PHP高效搜索专题(1)】sphinx&Coreseek的介绍与安装

    我们已经知道mysql中带有"%keyword%"条件的sql是不走索引的,而不走索引的sql在大数据量+大并发量的时候,不仅效率极慢还很有可能让数据库崩溃.那我们如何通过某些关键 ...

  4. Sphinx(coreseek) 安装使用以及词库的扩展

    1.Sphinx(coreseek) 是啥 一般而言,Sphinx是一个独立的全文搜索引擎:而Coreseek是一个支持中文的全文搜索引擎,意图为其他应用提供高速.低空间占用.高结果相关度的中文全文搜 ...

  5. Sphinx + Coreseek 实现中文分词搜索

    Sphinx + Coreseek 实现中文分词搜索 Sphinx Coreseek 实现中文分词搜索 全文检索 1 全文检索 vs 数据库 2 中文检索 vs 汉化检索 3 自建全文搜索与使用Goo ...

  6. sphinx,coreseek安装

    sphinx是国外的一款搜索软件. coreseek是在sphinx的基础上,增加了中文分词功能,换句话说,就是支持了中文. Coreseek发布了3.2.14版本和4.1版本,其中的3.2.14版本 ...

  7. SqlSugar-执行Sql语句查询实例

    使用SqlSugar执行sql语句 1.简单查询 SqlSugarClient db = SugarContext.GetInstance(); //执行sql语句,处理 //1.执行sql,转成li ...

  8. 【MySQL】分页查询实例讲解

    MySQL分页查询实例讲解 1. 前言 本文描述了团队在工作中遇到的一个MySQL分页查询问题,顺带讲解相关知识点,为后来者鉴.本文的重点不是"怎样"优化表结构和SQL语句,而是探 ...

  9. 使用ssm(spring+springMVC+mybatis)创建一个简单的查询实例(三)(错误整理篇)

    使用ssm(spring+springMVC+mybatis)创建一个简单的查询实例(一) 使用ssm(spring+springMVC+mybatis)创建一个简单的查询实例(二) 以上两篇已经把流 ...

随机推荐

  1. UVA 753 - A Plug for UNIX(网络流)

      A Plug for UNIX  You are in charge of setting up the press room for the inaugural meeting of the U ...

  2. C#中的线程(下)-多线程

    1.  单元模式和Windows Forms 单元模式线程是一个自动线程安全机制, 非常贴近于COM——Microsoft的遗留下的组件对象模型.尽管.NET最大地放弃摆脱了遗留下的模型,但很多时候它 ...

  3. 20169210《Linux内核原理与分析》第一周作业

    第一次接触Linux,还是有点不适应的,与Windows区别还是比较大的.在免费与收费.软件与支持.安全性.使用习惯.可定制性和应用范畴等方面都有区别. 通过实验楼的<Linux基础入门(新版) ...

  4. JQuery ajax调用asp.net的webMethod

    本文章转载:http://www.cnblogs.com/zengxiangzhan/archive/2011/01/16/1936938.html 在vs2010中,用JQuery ajax调用as ...

  5. JAVA Calendar具体解释

    (在文章的最后,将会介绍Date类,假设有兴趣,能够直接翻到最后去阅读) 到底什么是一个 Calendar 呢?中文的翻译就是日历,那我们立马能够想到我们生活中有阳(公)历.阴(农)历之分.它们的差别 ...

  6. 廖雪锋笔记2:list,tuble

    list:元素值不固定,元素类型不固定 apend(xx) insert(INDEX,xx) pop(index) 索引元素: [0] [1] [2] [-1] [-2] LIST,TUBLE变量值是 ...

  7. easy ui example

    http://www.jeasyui.com/tutorial/index.php http://www.w3cschool.cc/jeasyui/jqueryeasyui-tutorial.html

  8. java文件处理工具类

    import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.BufferedRead ...

  9. iBatis 的插入一个实体

    Student.xml 这个制定参数的属性 <insert id="insertStudent" parameterClass="Student" > ...

  10. mybatis for .net

    MyBatis For .NET学习笔记:开篇 http://chenkai.blog.51cto.com/2023960/763806 MyBatis For .NET学习笔记[2]:配置环境 ht ...