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

索引系统需要通过主查询来获取全部的文档信息,一种简单的实现是将整个表的数据读入内存,但是这可能导致整个表被锁定并使得其他操作被阻止(例如:在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. Nova 无法向虚机注入密钥

    欢迎各位关注我的博客:http://weibo.com/u/216633637 废话开头: 之前参考这位同学的博客http://www.cnblogs.com/awy-blog/p/3447176.h ...

  2. linux0.12 编译过程

    感谢这篇文章的作者:    http://www.cnblogs.com/strugglesometimes/p/4231359.html 编译是个很蛋疼的事情,本想把linux0.12在bochs上 ...

  3. 又是一道水题 hdu背包

    Problem Description 电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额.如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负) ...

  4. mac 别名 ll

    在 Linux 下习惯使用 ll.la.l 等ls别名的童鞋到 mac os 可就郁闷了~~ 其实只要在用户目录下建立一个脚本“.bash_profile”, vim .bash_profile 并输 ...

  5. thymeleaf 和其它标签组合 获取数据

    thymeleaf 有很多的内置标签, 但是我们在开发中会引入其它很多标签, 这个时候, 后台数据过来了,前端 页面要怎么显示呢? 网上资料真的很少. 不过还是找到了答案:  th:attr 这个标签 ...

  6. 使用PullToRefresh实现下拉刷新和上拉加载

    使用PullToRefresh实现下拉刷新和上拉加载 分类: Android2013-12-20 15:51 78158人阅读 评论(91) 收藏 举报 Android下拉刷新上拉加载PullToRe ...

  7. [Javascript] Array - Conact

    For example there are two array of object and you want to print out each element, it is bad if you u ...

  8. [转] 在React Native中使用ART

    http://bbs.reactnative.cn/topic/306/%E5%9C%A8react-native%E4%B8%AD%E4%BD%BF%E7%94%A8art 前半个月捣腾了一下Rea ...

  9. [转] EF Configuring a DbContext

    本文转自:https://docs.microsoft.com/en-us/ef/core/miscellaneous/configuring-dbcontext Note This document ...

  10. Conversion Between DataTable and List in C#

    1.List to DataTable public static DataTable ToDataTable<TSource>(this IList<TSource> dat ...