coreseek的简单介绍
本文目录一览:
- 1、请教coreseek的问题
- 2、windows下怎么安装coreseek
- 3、coreseek和lucence 的区别在哪里,各自有什么优点,相关性哪个好,百万级和千万级索引应该选用哪个?
- 4、coreseek 安装完成后 怎么调用接口
- 5、怎么吧coreseek-3.2.14加入到服务里
请教coreseek的问题
必须用ID值回查数据
因为coreseek只保存了你索引字段的信息
你可以通过多索引几个字段,来保证在列表输出的相关信息不用再次回查数据库实现你的效果
windows下怎么安装coreseek
1、下载,我这里下的是“Win64 binaries w/MySQL+PgSQL+libstemmer+id64 support”,下载后文件名:sphinx-2.0.6-release-win64-id64-full.zip;
2、将其解压到D: \ sphinx,并在D:\sphinx下新建目录data(用来存放索引文件)与log(用来存放日志文件);
3、将D:\sphinx\sphinx.conf.in复制到D:\sphinx\bin\sphinx.conf.in,并重命名为sphinx.conf;
4、修改 D:\sphinx\bin\sphinx.conf 如下:
4.1、搜索source src1修改{...}中的内容
# 使用的数据库类型
type = mysql
# 服务器
sql_host = localhost
# 数据库登录名
sql_user = root
# 数据库登录密码
sql_pass = root
# 操作的数据库名称
sql_db = test
# 数据库服务器端口
sql_port = 3306
# 设置编码,如果用的是utf-8编码
sql_query_pre = SET NAMES utf-8
(以上7条前如有#将其删除)
4.2、搜索index test1修改{...}中的内容
# 放索引的目录
path = D:/sphinx/data/
# 编码
charset_type = utf-8
# 指定utf-8编码表
charset_table = 0..9, A..Z-a..z, _, a..z, U+410..U+42F-U+430..U+44F, U+430..U+44F
# 简单分词,只有0和1,需要搜索中文必须置1
ngram_len = 1
# 需要分词的字符,搜索中文时必须
ngram_chars = U+3000..U+2FA1F
(以上5条前如有#将其删除)
5、导入测试数据将D:\sphinx\example.sql中语句执行到test数据库中,注意:test数据库创建时需要指定为utf-8格式;
6、打开cmd窗口,进入目录D:\sphinx\bin;
7、建立索引,执行indexer.exe test1,test1即为sphinx.conf中index test1
Sphinx 2.0.6-id64-release (r3473)
Copyright (c) 2001-2012, Andrew Aksyonoff
Copyright (c) 2008-2012, Sphinx Technologies Inc (
using config file './sphinx.conf'...
indexing index 'test1'...
collected 4 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 4 docs, 222 bytes
total 0.019 sec, 11252 bytes/sec, 202.74 docs/sec
total 2 reads, 0.000 sec, 0.2 kb/call avg, 0.0 msec/call avg
total 9 writes, 0.000 sec, 0.1 kb/call avg, 0.0 msec/call avg
成功...
8、搜索'test',执行search.exe test
Sphinx 2.0.6-id64-release (r3473)
Copyright (c) 2001-2012, Andrew Aksyonoff
Copyright (c) 2008-2012, Sphinx Technologies Inc ()
using config file './sphinx.conf'...
index 'test1': query 'test ': returned 3 matches of 3 total in 0.000 sec
displaying matches:
1. document=1, weight=2421, group_id=1, date_added=Tue Feb 26 10:25:31 2013
id=1
group_id=1
group_id2=5
date_added=2013-02-26 10:25:31
title=test one
content=this is my test document number one. also checking search within
phrases.
2. document=2, weight=1442, group_id=3, date_added=Tue Feb 26 10:25:31 2013
id=2
group_id=3
group_id2=6
date_added=2013-02-26 10:25:31
title= ????
content=this is my test document number two ???????
3. document=4, weight=1442, group_id=2, date_added=Tue Feb 26 10:25:31 2013
id=4
group_id=2
group_id2=8
date_added=2013-02-26 10:25:31
title=doc number four
content=this is to test groups
words:
1. 'test': 3 documents, 4 hits
index 'test1stemmed': search error: failed to open D:/sphinx/data/test1stemmed.s
ph: No such file or directory.
最后面的一句error可忽略;
9、搜索中文,首先将数据库中的内容update含有中文,执行sql语句:
UPDATE documents SET title='中文', content='this is my test document number one. also checking search within phrases.含有中文。' WHERE id=1;
UPDATE documents SET title='中文标题', content='this is my test document number one. also checking search within phrases.含有中文内容。' WHERE id=2;
UPDATE documents SET title='中文标题测试', content='this is my test document number one. also checking search within phrases.含有中文内容。' WHERE id=3;
重新建立索引(执行第7步);
然后执行search.exe 中文
Sphinx 2.0.6-id64-release (r3473)
Copyright (c) 2001-2012, Andrew Aksyonoff
Copyright (c) 2008-2012, Sphinx Technologies Inc ()
using config file './sphinx.conf'...
indexing index 'test1'...
collected 4 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 4 docs, 349 bytes
total 0.025 sec, 13808 bytes/sec, 158.26 docs/sec
total 2 reads, 0.000 sec, 0.3 kb/call avg, 0.0 msec/call avg
total 9 writes, 0.000 sec, 0.2 kb/call avg, 0.0 msec/call avg
D:\sphinx\binsearch.exe 中文
Sphinx 2.0.6-id64-release (r3473)
Copyright (c) 2001-2012, Andrew Aksyonoff
Copyright (c) 2008-2012, Sphinx Technologies Inc ()
using config file './sphinx.conf'...
index 'test1': query '中文 ': returned 0 matches of 0 total in 0.000 sec
words:
index 'test1stemmed': search error: failed to open D:/sphinx/data/test1stemmed.s
ph: No such file or directory.
没有搜索到,因为windows命令行中的中文时GBK编码格式,所以没有匹配内容。我们可以使用PHP程序来试试;
10、进入D:\sphinx\api\目录,可以发现sphinx支持php、java、ruby调用,并提供对应的test例子,这里我们使用php来操作,首先将api复制到D:\www\下并重命名为sphinxapi,因为我本机上apache的web目录为D:\www,在D:\www\sphinxapi\下新建search.php,内容为:
?php
require 'sphinxapi.php';
$s = new SphinxClient();
$s-SetServer('localhost', 9312);
$result = $s-Query('中国');
print_r($result);
echo 'br /br /';
$result = $s-Query('中文');
print_r($result);
?
然后回到cmd命令行中,开启sphinx服务,执行searchd.exe(这个必须要执行的)
Sphinx 2.0.6-id64-release (r3473)
Copyright (c) 2001-2012, Andrew Aksyonoff
Copyright (c) 2008-2012, Sphinx Technologies Inc ()
using config file './sphinx.conf'...
WARNING: compat_sphinxql_magics=1 is deprecated; please update your applicatiON
and config
WARNING: preopen_indexes=1 has no effect with seamless_rotate=0
listening on all interfaces, port=9312
listening on all interfaces, port=9306
precaching index 'test1'
precaching index 'test1stemmed'
WARNING: index 'test1stemmed': preload: failed to open D:/sphinx/data/test1stemm
ed.sph: No such file or directory; NOT SERVING
precaching index 'rt'
WARNING: index 'rt': preload: failed to open @CONFDIR@/data/rt.lock: No such fil
e or directory; NOT SERVING
precached 3 indexes in 0.018 sec
成功...
然后在浏览器中执行,打印出来的数组结果可以很清晰的看见搜索的结果比对。。。
11、至此sphinx在windows下的简单安装与使用就完成了。
coreseek和lucence 的区别在哪里,各自有什么优点,相关性哪个好,百万级和千万级索引应该选用哪个?
1.php用coreseek,java用lucene。 2.coreseek支持高速建立索引:10MB/秒;lucene为1.8MB/秒 3.coreseek具有高扩展性(最高可对100GB文件建立索引),支持分布式检索,支持不同的搜索模式(“完全匹配”,“短语匹配”和”任一匹配“),支持作为Mysql的存储引擎 lucene索引文件格式独立于应用平台;在传统全文检索引擎的倒排索引的基础上,实现了分块索引;查询实现中默认实现了布尔操作、模糊查询、分组查询等。 相关性都还过得去,根据你团队的技术水平、程序、需求来选择
coreseek 安装完成后 怎么调用接口
然后重新运行aclocal和autoconf
aclocal autoconf
最后再次运行automake
automake
然后继续mmseg的安装
./configure --prefix=/usr/local/mmseg
make make install
如果make 报错
There is an easy fix when you get such messages as "X--tag=CXX: command not found".
Just type:
export echo=echo
And try again.
所以输入
export echo=echo
然后再次运行安装
make make install
安装csft
./configure --prefix=/usr/local/coreseek --with-mysql=/usr/local/mysql --with-mmseg=/usr/local/mmseg --with-mmseg-includes=/usr/local/mmseg/include/mmseg/ --with-mmseg-libs=/usr/local/mmseg/lib/
make make install
安装完毕后 注意 coreseek 中的配置文件也是csft.conf 而不是 sphinx.conf
cd /usr/local/coreseek/etc
cp sphinx.conf.dist csft.conf
vim csft.conf
有些配置改动如下其他配置内容如上文的sphinx.conf
在索引源中注释掉txt
index main{
#stopwords = G:\data\stopwords.txt
#wordforms =G:\data\wordforms.txt
#exceptions =/data/exceptions.txt
#charset_type = sbcs
#添加下面2行 意思是把中文分词加入到配置文件中
char_type = zh_cn.utf-8
charset_dictpath =/usr/local/mmseg/etc/ #你安装mmseg的目录
}
保存配置
建立索引
cd /usr/local/coreseek/bin
./indexer --all
./search 中文词缀
如何用php去使用sphinx
Sphinx集成到php程序中有两种方式
1.Sphinx php 模块(这次我们选择使用的方式)
2.Sphinx api 类(位于coreseek源码包里的csft里的api文件夹里有一个sphinxapi.php,使用的时候包含这个php文件即可)
我们要使用sphinx需要做以下几件事:
1.首先要有数据
2.建立sphinx配置文件
3.生成索引
4,启动searchd 服务进程,并开启端口9312
5.用php客户程序去链接sphinx服务
/usr/local/coreseek/bin/searchd
启动进程命令 searchd
-c 指定配置文件
--stop 停止服务
--pidfile 显示指定pid文件
-p 指定端口(默认9312)
注意:这里启动的服务是searchd
使用php sphinx的模块
下载 sphinx-1.1.0.tgz
tar zvxf sphinx-1.1.0.tgz
cd sphinx-1.1.0
/usr/local/php/bin/phpize #用于生成一个configure的脚本
进入coreseek源码包的csft/api/libsphinxclent 目录下执行configure
./configure
make make install
进入sphinx-1.1.0.gzt的源码包目录下 执行configure用于生成so 的shpinx模块
./configure --with-php-config=/usr/local/webserver/php/bin/php-config --with-sphinx
make make install
安装成功后会有提示
Build complete.
Don't forget to run 'make test'.
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/ (这个目录是sphinx.so所在的目录)
然后我们编辑php的ini文件 在extension中加入
extension=sphinx.so
然后重启nginx和php的服务
最后打印一下phpinfo 查看sphinx是否开启成功
如果成功开启 就可以使用php手册里的sphinx的方法和代码了
怎么吧coreseek-3.2.14加入到服务里
自持中文分词的包叫做coreseek,其实就是带了中文分词插件的sphinx,在此处下载:稳定版3.2.14
先写个结论,sphinx本身是可以支持中文搜索的,只是不支持中文分词,需要安装中文分词插件,coreseek就是一个打包了mmseg中文分词插件和sphinx源码的安装包
目前coreseek已经很久不更新了,稳定版3.2.14内带的的sphinx还是 0.9.9 release版本的;而sphinx可以通过设置为“一元切分模式”来支持搜索中文
在实际使用中,搜索非中文的话,sphinx比coreseek要快;搜索短中文字符串的话,开启了“一元切分模式”的sphinx比coreseek要快;只有在搜索长中文字串时,coreseek的分词优势才能显现,比sphinx要快
所以根据你的应用场景来选择用哪个,如果是索引英文、数字、字符较多的数据,就用源生sphinx;如果是索引中文非常多非常长的数据,还是用coreseek
coreseek的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、coreseek的信息别忘了在万域城进行查找喔。
相关文章
发表评论
评论列表
- 这篇文章还没有收到评论,赶紧来抢沙发吧~