sphinx(coreseek)——1、增量索引
首先介绍一下 CoreSeek/Sphinx的发布包
indexer: 用于创建全文索引;
search: 一个简单的命令行(CLI) 的测试程序,用于测试全文索引;
searchd: 一个守护进程,其他软件(例如WEB程序)可以通过这个守护进程进行全文检索;
sphinxapi: 一系列searchd 的客户端API 库,用于流行的Web脚本开发语言(PHP, Python, Perl, Ruby, Java).
spelldump: 一个简单的命令行工具,用于从 ispell 或者 MySpell (OpenOffice内置绑定) 格式的字典中提取词条。当使用 wordforms时可用这些词条对索引进行定制.
indextool: 工具程序,用来转储关于索引的多项调试信息。此工具是从版本Coreseek 3.1(Sphinx 0.9.9-rc2)开始加入的。
mmseg: 工具程序和库,Coreseek用于提供中文分词和词典处理。
在Sphinx+LibMMSeg搭建中文全文搜索引擎_安装配置中安装试验了Sphinx 的使用,但是还有几方面的问题有待处理。
- 动态增量索引
- 区段查询
- 实时索引
- 匹配到的字段在前端界面表现
本篇主要是对动态增量更新的一些研究
在利用 Sphinx 做搜索引擎的时候,一般他的索引建立构成有如下几个部分:
- 固定不变的主索引
- 增量索引重建
- 索引数据合并
- 在实际操作中,需要为增量索引的建立创建辅助表,这样才可以记住最后建立索引的记录ID,做实际的增量部分的索引建立。
CREATE TABLE `sph_counter` (
`counter_id` int(11) NOT NULL,
`max_doc_id` int(11) NOT NULL,
PRIMARY KEY (`counter_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
- 在主索引的数据源中作如下方式的取数据设置
source src
{
# data source type. mandatory, no default value
# known types are mysql, pgsql, mssql, xmlpipe, xmlpipe2, odbc
type = mysql
sql_host = localhost
sql_user = root
sql_pass = xxxxx
sql_db = test
sql_port = # optional, default is
sql_query_pre = SET NAMES utf8
sql_query_pre = SET SESSION query_cache_type=OFF
sql_query_pre = REPLACE INTO sph_counter SELECT , MAX(id) FROM cn
sql_query = SELECT id,title,content from cn where id<=(SELECT max_doc_id FROM sph_counter WHERE counter_id=)
sql_query_info = SELECT * FROM cn WHERE id=$id
}
- 在增量索引的数据源中作如下方式的取数据设置,需要注意的是sql_query_pre要和主索引数量相同,不然查询结果不是想要的内容
#表示增量数据源
source moresrc : src
{
sql_query_pre = SET NAMES utf8
sql_query_pre = SET SESSION query_cache_type=OFF
sql_query = SELECT id,title,content from cn where id>(SELECT max_doc_id FROM sph_counter WHERE counter_id=)
#sql_ranged_throttle =
}
- 主索引index定义配置
index src
{
source = src
path = /usr/local/coreseek/var/data/test1
docinfo = extern
mlock =
morphology = none
# 启用中文分词功能source 数据源中需要 设置读取的数据编码字符集为UTF-,否则无
法正确处理;如果是xml,则正确输出为UTF-8编码格式即可;如果是MySQL,则设置读取数据输出
字符集为UTF-8即可
charset_type = zh_cn.utf-
# 中文分词词库位置
charset_dictpath =/usr/local/mmseg/etc/
}
- 增量索引index定义配置
index moresrc : src
{
source = moresrc
path = /usr/local/coreseek/var/data/moresrc
morphology = stem_en
}
indexer
{
# memory limit, in bytes, kiloytes (16384K) or megabytes (256M)
# optional, default is 32M, max is 2047M, recommended is 256M to 1024M
mem_limit = 32M
}
- 创建更新全部索引
root@timeless-HP-Pavilion-g4-Notebook-PC:/usr/local/coreseek/bin# /usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft.increment.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.increment.conf'...
indexing index 'src'...
WARNING: Attribute count is : switching to none docinfo
collected docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total docs, bytes
total 0.011 sec, bytes/sec, 531.82 docs/sec
indexing index 'moresrc'...
WARNING: Attribute count is : switching to none docinfo
collected docs, 0.0 MB
total docs, bytes
total 0.001 sec, bytes/sec, 0.00 docs/sec
total reads, 0.000 sec, 0.1 kb/call avg, 0.0 msec/call avg
total writes, 0.000 sec, 0.1 kb/call avg, 0.0 msec/call avg
rotating indices: succesfully sent SIGHUP to searchd (pid=).
- 更新增量索引
数据库中添加数据 然后运行,更新增量索引 记得 执行 indeser search 还有启动searchd时候要 要指定-c 配置文件。
root@timeless-HP-Pavilion-g4-Notebook-PC:/usr/local/coreseek/bin# /usr/local/coreseek/bin/indexer moresrc -c /usr/local/coreseek/etc/csft.increment.conf --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.increment.conf'...
indexing index 'moresrc'...
WARNING: Attribute count is : switching to none docinfo
collected docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total docs, bytes
total 0.008 sec, bytes/sec, 115.24 docs/sec
total reads, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg
total writes, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg
rotating indices: succesfully sent SIGHUP to searchd (pid=).
- 合并增量索引到主索引
root@timeless-HP-Pavilion-g4-Notebook-PC:/usr/local/coreseek/bin# /usr/local/coreseek/bin/indexer --merge src moresrc -c /usr/local/coreseek/etc/csft.increment.conf --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.increment.conf'...
read 0.0 of 0.0 MB, 100.0% done
merged 0.0 Kwords
merged in 0.000 sec
total reads, 0.000 sec, 6.4 kb/call avg, 0.0 msec/call avg
total writes, 0.000 sec, 0.1 kb/call avg, 0.0 msec/call avg
rotating indices: succesfully sent SIGHUP to searchd (pid=).
- 测试数据如下所示
root@timeless-HP-Pavilion-g4-Notebook-PC:/usr/local/coreseek/bin# ./search -c /usr/local/coreseek/etc/csft.increment.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.increment.conf'...
index 'src': query '测试 ': returned matches of total in 0.000 sec displaying matches:
. document=, weight=
id=
title=?????
content=?? ?????? ???? ??
addtime=
. document=, weight=
id=
title=??
content=????????
addtime=
. document=, weight=
id=
title=???
content=???????? ?????? ????
addtime= words:
. '测试': documents, hits index 'moresrc': query '测试 ': returned matches of total in 0.000 sec displaying matches:
. document=, weight=
id=
title=??
content=????????
addtime= words:
. '测试': documents, hits
通过测试数据看到 index moresrc 增量索引 查询到 “测试” 关键字 5 次 合并之后的住索引变为 14个匹配。 之前是 9个 匹配。
sphinx(coreseek)——1、增量索引的更多相关文章
- sphinx (coreseek)——3、区段查询 与 增量索引实例
首先本文测试数据100多万的域名的wwwtitle 信息 检索数据: 首先建立临时表格: CREATE TABLE `sph_counter` ( `index_id` ) NOT NULL, `m ...
- sphinx增量索引
首先建立一个计数表,保存数据表的最新记录ID CREATE TABLE `sph_counter` ( `id` int(11) unsigned NOT NULL, `max_id` int(1 ...
- Coreseek:部门查询和增量索引代替实时索引
1.行业调查 索引系统需要通过主查询来获取所有的文档信息,一个简单的实现是整个表的数据到内存,但是这可能会导致整个表被锁定,并且使其它操作被阻止(例如:在MyISAM格款式上INSERT操作).同时, ...
- Sphinx主索引和增量索引来实现索引实时更新的关键步骤
1.配置csft.conf文件 vim /etc/csft.conf # # Minimal Sphinx configuration sample (clean, simple, functiona ...
- sphinx增量索引和主索引来实现索引的实时更新
项目中文章的信息内容因为持续有新增,而文章总量的基数又比较大,所以做搜索的时候,用了主索引+增量索引这种方式来实现索引的实时更新. 实现原理: 1. 新建一张表,记录一下上一次已经创建好索引的最后一条 ...
- Coreseek:区段查询及增量索引取代实时索引
1.区段查询 索引系统须要通过主查询来获取所有的文档信息,一种简单的实现是将整个表的数据读入内存,可是这可能导致整个表被锁定并使得其它操作被阻止(比如:在MyISAM格式上的INSERT操作),同一时 ...
- sphinx增量索引使用
sphinx在使用过程中如果表的数据量很大,新增加的内容在sphinx索引没有重建之前都是搜索不到的. 这时可以通过建立sphinx增量索引,通过定时更新增量索引,合并主索引的方式,来实现伪实时更新. ...
- coreseek增量索引合并
重建主索引和增量索引: [plain] view plain copy /usr/local/coreseek/bin/indexer--config /usr/local/coreseek/etc/ ...
- coreseek增量索引
1.在多数情况下,因为Coreseek索引速度高达10MB/s,所以只需要创建一个索引源即可满足需求,但是在数据量随时激增的大型应用中(如SNS.评论系统等),单一的索引源将会给indexer造成极大 ...
随机推荐
- PHP中Content-type的MIME类型大全说明
<?php $mimetypes = array( 'ez' => 'application/andrew-inset', 'hqx' => 'application ...
- UVAlive7141 BombX 14年上海区域赛D题 线段树+离散化
题意:一个无限大的棋盘, 有n个小兵, 给出了n个兵的坐标, 现在有一个长为width 高为height的炸弹放在棋盘上, 炸弹只能上下左右平移, 不能旋转. 且放炸弹的区域不能含有士兵, 炸弹可以一 ...
- 《A First Course in Probability》-chaper4-离散型随机变量-随机变量和或积的期望
基于随机变量一系列最基本的概念,我们便会开始探讨一些随机变量函数的期望.多个随机变量和的期望.多个随机变量乘积的期望. 这里我们就简单的讨论后两个期望. 这两个问题可以基于如下的一个现实模型: 同时掷 ...
- Little shop of flowers - SGU 104 (DP)
题目大意:把 M 朵花插入 N 个花瓶中,每个花插入不同的花瓶都有一个价值A[Mi][Nj],要使所有的花都插入花瓶,求出来最大的总价值(花瓶为空时价值是0). 分析:dp[i][j]表示前i朵花插入 ...
- Codeforces Round #100(140~~)
140 A. New Year Table 题目大意:有一个大圆桌子,半径是R, 然后有n个半径是r的盘子,现在需要把这些盘子摆放在桌子上,并且只能摆放在桌子边缘,但是不能超出桌子的范围....问能放 ...
- winform 播放声音方式 分类: WinForm 2014-07-25 14:16 194人阅读 评论(0) 收藏
声音文件folder.wav放置在bin目录下debug下 1.通过API调用 [c-sharp] view plaincopy using System.Runtime.InteropService ...
- eclipse GWT开发环境的离线布置方法
安装方法http://blog.csdn.net/u011029071/article/details/10143841 用eclipse自动更新安装失败N次,还是得手动来 以Google Plugi ...
- 无法将类型“System.Collections.Generic.IEnumerable<EmailSystem.Model.TemplateInfo>”隐式转换为“System.Collections.Generic.List<EmailSystem.Model.TemplateInf
List<Model.Template> templateList = templateBLL.RecommendTemplateByOrder(modelEbay); List<M ...
- 用网页server实现钢琴弹奏(使用Wizwiki-W7500)
我将为大家介绍一个能够弹钢琴的网页server. 你仅仅须要打开网页,跟着以下步骤,用这个WIZwiki-W7500项目,就能轻松实现用网页server弹钢琴. 很easy. 我们開始吧! 第 ...
- DSPack各种使用方法
1. DSPack 2.3.4 安装 一. 下载由于sourceforge最近不能访问,所以可以去 http://www.progdigy.com/ 下载.下载 http://www.progdi ...