sphinx (coreseek)——2、区段查询实例
- 首先需要知道区段查询的定义:
索引系统需要通过主查询来获取全部的文档信息,一种简单的实现是将整个表的数据读入内存,但是这可能导致整个表被锁定并使得其他操作被阻止(例如:在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次:
- 将
$start
替换为1,并且将$end
替换为 1000; - 将
$start
替换为1001,并且将$end
替换为 2000; - 将
$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、区段查询实例的更多相关文章
- sphinx (coreseek)——3、区段查询 与 增量索引实例
首先本文测试数据100多万的域名的wwwtitle 信息 检索数据: 首先建立临时表格: CREATE TABLE `sph_counter` ( `index_id` ) NOT NULL, `m ...
- Coreseek:区段查询及增量索引取代实时索引
1.区段查询 索引系统须要通过主查询来获取所有的文档信息,一种简单的实现是将整个表的数据读入内存,可是这可能导致整个表被锁定并使得其它操作被阻止(比如:在MyISAM格式上的INSERT操作),同一时 ...
- 【PHP高效搜索专题(1)】sphinx&Coreseek的介绍与安装
我们已经知道mysql中带有"%keyword%"条件的sql是不走索引的,而不走索引的sql在大数据量+大并发量的时候,不仅效率极慢还很有可能让数据库崩溃.那我们如何通过某些关键 ...
- Sphinx(coreseek) 安装使用以及词库的扩展
1.Sphinx(coreseek) 是啥 一般而言,Sphinx是一个独立的全文搜索引擎:而Coreseek是一个支持中文的全文搜索引擎,意图为其他应用提供高速.低空间占用.高结果相关度的中文全文搜 ...
- Sphinx + Coreseek 实现中文分词搜索
Sphinx + Coreseek 实现中文分词搜索 Sphinx Coreseek 实现中文分词搜索 全文检索 1 全文检索 vs 数据库 2 中文检索 vs 汉化检索 3 自建全文搜索与使用Goo ...
- sphinx,coreseek安装
sphinx是国外的一款搜索软件. coreseek是在sphinx的基础上,增加了中文分词功能,换句话说,就是支持了中文. Coreseek发布了3.2.14版本和4.1版本,其中的3.2.14版本 ...
- SqlSugar-执行Sql语句查询实例
使用SqlSugar执行sql语句 1.简单查询 SqlSugarClient db = SugarContext.GetInstance(); //执行sql语句,处理 //1.执行sql,转成li ...
- 【MySQL】分页查询实例讲解
MySQL分页查询实例讲解 1. 前言 本文描述了团队在工作中遇到的一个MySQL分页查询问题,顺带讲解相关知识点,为后来者鉴.本文的重点不是"怎样"优化表结构和SQL语句,而是探 ...
- 使用ssm(spring+springMVC+mybatis)创建一个简单的查询实例(三)(错误整理篇)
使用ssm(spring+springMVC+mybatis)创建一个简单的查询实例(一) 使用ssm(spring+springMVC+mybatis)创建一个简单的查询实例(二) 以上两篇已经把流 ...
随机推荐
- C++Primer第5版学习笔记(一)
C++Primer第5版学习笔记(一) 第一.二章的重难点内容 这个笔记本主要记录了我在学习C++Primer(第5版,中文版)的过程中遇到的重难点及其分析.因为第一.二章都比较简单,因 ...
- db2 alter table 语法
DB2 alter:add/delete/reset column 1.添加字段 alter table [table_name] add [column_name] [column_type] ...
- linux —— 启动引导程序 lilo 与 grub
目录:1.启动引导程序概要 2.lilo 的安装与配置 3.grub的安装与配置 4.两种引导程序的切换 5.附:编译内核时的lilo 设置 1.启动引导程序概要 2.lilo 的安装与配置 3.g ...
- [kuangbin带你飞]专题十 匹配问题 二分图多重匹配
二分图的多重匹配问题不同于普通的最大匹配中的"每个点只能有最多一条边" 而是"每个点连接的边数不超过自己的限定数量" 最大匹配所解决的问题一般是"每个 ...
- UVa1151 Buy or Build
填坑(p.358) 以前天真的以为用prim把n-1条边求出来就可以 现在看来是我想多了 #include<cstdio> #include<cstring> #include ...
- c#基础语言编程-正则表达式应用
引言 在不同语言中虽正则表达式一样,但应用函数还是有所区别,在c#语言中使用Regex. 可以通过以下两种方式之一使用正则表达式引擎: 通过调用 Regex 类的静态方法. 方法参数包含输入字符串和正 ...
- windows下安装pip
1.在安装pip前,请确认win系统中已经安装好了python,和easy_install工具,如果系统安装成功,easy_install在目录C:\Python27\Scripts 下面,确认截图如 ...
- 解决方法:未能加载文件或程序集“Microsoft.Office.Interop.Excel。。
.NET错误提示:未能加载文件或程序集“Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral, PublicKeyToke ...
- javascript 的基本优化
http://www.ruanyifeng.com/blog/2010/01/12_javascript_syntax_structures_you_should_not_use.html
- 《Linux内核分析》-----张超
http://www.cnblogs.com/zhangchao0515/category/797954.html MOOC课程 http://mooc.study.163.com/course/US ...