Sphinx 全文搜索引擎

  • 格式:doc
  • 大小:53.02 KB
  • 文档页数:10

下载文档原格式

  / 10
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Sphinx 全文搜索引擎

1:索引与全文索引的概念

数据库中,表中的行特别多,如何快速的查询某一行,或者某一个文章中的单词,

索引--->查询速度快

全文索引-->针对文章内容中的单词各做索引

2:mysql支不支持全文索引?

答:支持, 但是

A:innoDB引擎在5.5,及之前的版本不支持(5.7实测可以在innodb上建fulltext),只能在myisam 引擎上用fulltext

B: mysql的全文索引功能不够强大

C: 无法对中文进行合理的全文索引----- mysql.无法进行中文分词.

注意:

全文索引的停止词

停止词是指出现频率极高的单词, 不予索引.

如果某单词出现频率50%以上,列为停止词

或者是经过统计的常用词,也列为停止词---如is, are , she, he, this 等等

就像中文中: “的”,”是”,”呵呵”

总结: 我们要对中文做全文搜索引擎,需要解决2个问题

1: 性能提高,用第3方的全文搜索引擎工具,如sphinx, solr等

2: 中文分词! (如mmseg)

编译安装sphinx+mmseg == coreseek

官网:

0: 安装工具包

yum install make gcc gcc-c++ libtool autoconf automake imake libxml2-devel expat-devel

1: 下载解压源码,ls查看

csft-4.1 mmseg-3.2.14 README.txt testpack

其中--

csft-4.1是修改适应了中文环境后的sphinx

Mmseg 是中文分词插件

Testpack是测试用的软件包

2: 先安装mmseg

2.1: cd mmseg

2.2: 执行bootstrap脚本

2.3: ./configure --prefix=/usr/local/mmseg

2.4: make && make install

3: 再安装sphinx(coreseek)

3.1: 到其目录下执行buildconf.sh

3.2: ./configure --prefix=/usr/local/sphinx

--with-mysql=/usr/local/mysql

--with-mmseg

--with-mmseg-includes=/usr/local/mmseg/include/mmseg/

--with-mmseg-libs=/usr/local/mmseg/lib/

3.3: make install

Sphinx的使用

分三个部分:

1: 数据源---要让sphinx知道,查哪些数据,即针对哪些数据做索引(可以定义多个源)

2: 索引配置--针对哪个源做索引, 索引文件放在哪个目录?? 等等

3: 搜索服务器----sphinx可以在某个端口(默认9312),以其自身的协议,与外部程序做交互.

具体的步骤:

1: 数据源典型配置

source test {

type = mysql

sql_host = localhost

sql_user = root

sql_pass =

sql_db = test

sql_query_pre = set names utf8

sql_query_pre = set session query_cache_type=off

sql_query = select id,catid,pubtime,title,content from news

sql_attr_uint = id

sql_attr_uint = catid

sql_attr_timestamp = pubtime

sql_query_info = select * from news where id=$id

}

2: 索引典型配置

index test {

type = plain

source = test

path = /usr/local/sphinx/var/data/test #生成索引放在哪

docinfo = extern

charset_dictpath = /usr/local/mmseg/etc/

charset_type = zh_cn.utf-8

}

2.1: 生成索引文件

/path/sphinx/bin/indexer -c ./etc/sphinx.test.conf test (test是索引名)

2.2: 查询测试

A:在命令下,用path/bin/search -c ./path/conf 关键词

B:开启搜索服务器,利用客户端连接搜索服务器来查询,见下

3: 配置搜索服务器接口,启动搜索服务器

searchd {

listen = localhost:9312

pid_file = /usr/local/sphinx/var/log/searchd.pid

log = /usr/local/sphinx/var/log/test.log

query_log =/usr/local/sphinx/var/log/test.query.log

client_timeout = 5

max_children = 5

max_matches = 1000

seamless_rotate = 1

}

3.2 : 使用客户端连接搜索服务器