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

索引系统需要通过主查询来获取全部的文档信息,一种简单的实现是将整个表的数据读入内存,但是这可能导致整个表被锁定并使得其他操作被阻止(例如:在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. 干货!如何正确使用Git Flow

    我们已经从SVN 切换到Git很多年了,现在几乎所有的项目都在使用Github管理, 本篇文章讲一下为什么使用Git, 以及如何在团队中正确使用. Git的优点 Git的优点很多,但是这里只列出我认为 ...

  2. WinForm------自定义YearMonthEdit组件

    转载: http://www.cnblogs.com/axing/p/3201066.html 注意: 1.需要在vs里面,添加一个YearMonthEdit组件,然后将链接里面的代码拷贝到里面 2. ...

  3. form与action之setter与getter(转)

    对于表单提交数据给action时候,可以简单的用setter与getter函数实现值的传递. 例如在jsp里有这么个form: <s:form action="login"& ...

  4. BA/PM Competency Module

    No Competency Description BA Weight% PM Weight% 1 Business Analysis:BA   Track Maps   process flows, ...

  5. Java学习笔记六(I/O流)

    1.介绍 在实际开发过程中经常会用到数据的输入/输出操作,本篇博客着重分析一下,java中经经常使用到的有关IO操作的类.而在java中能够将经常使用的流分为两个部分:字节流和字符流. 1.流的抽象基 ...

  6. Codeforces Beta Round #10 D. LCIS(DP&amp;LCIS)

    D. LCIS time limit per test 1 second memory limit per test 256 megabytes input standard input output ...

  7. Java语言基础(一)

    Java语言基础(一) 在这里说明一下,有基础的跳过 高手跳过.在这里我想复习以前的东西,以及给正在学java的一些帮助 我用的MyEclipse8.5编写java代码,有需要联系我  QQ:9035 ...

  8. 亲测apache

    http://www.cnblogs.com/bluewelkin/p/3805107.html 里面是纠正了原文的一些小错误,即可正常安装  1.su 命令 2.安装apr-1.3.5.tar.gz ...

  9. c#中jeson字符串和OBJECT对象的相互转换

    对于本问题   我用三步来分别说明实现过程 1.定义一个类---- 实现转换的具体方法 using System; using System.Collections.Generic; using Sy ...

  10. iOS的内存管理

    在Objective-C 这种面向对象的语言里,内存管理是个重要的概念.要想用一门语言写出内存使用效率高而且又没有bug的代码,就得掌握其内存管理模型的种种细节. 一旦理解了这些规则,你就会发现,其实 ...