您的位置:首页 > 编程语言 > PHP开发

Sphinx站内搜索

2016-03-01 00:00 726 查看
摘要: Sphinx检索

一、Sphinx流程

Mysql数据 -》 sphinx -》 索引数据

二、sphinx概述



三、Sphinx使用地方

1、网站中的搜索(站内搜索)

2、系统后台中的搜索



四、为什么要使用Sphinx

当数据超过100W时,我们需要使用第三方工具,Sphinx。

1、做搜索时当数据量大单纯的Mysql搜索比较慢(如果进行了分表会更慢)

如200W数据,查询记录中带某个字的数据:

mysql> select * from article where title like '%孩子';

模糊查询耗费时间:9.28s

2、搜索时中文分词

如搜:刘德华,会将刘德华,刘华,马德华相关的搜索匹配出来。

3、Sphinx快

高速的建立索引(在当代CPU中,峰值性能高达10M/s)

高性能的搜索(在2-4G的文本数据上,平均每次检索时间小于0.1s)

可处理海量数据

五、获取Sphinx

官方地址:http://sphinxsearch.com/ ,Sphinx必须安装在服务器中

Deb packages:

Sphinx requires a few libraries to be installed on Debian/Ubuntu. Use apt-get to download and install these dependencies:
$ sudoapt-get install mysql-client unixodbc libpq5


Now you can install Sphinx:
$ sudo
apt-get install sphinxsearch

start sphinxsearch

root@iZ9:/# sudo service sphinxsearch start

To enable sphinxsearch, edit /etc/default/sphinxsearch and set START=yes

编辑sphinx配置:

root@iZ94j7ehy5oZ:/# vim /etc/default/sphinxsearch



使用命令搜索:

root@iZ94j7:/# whereis sphinxsearch

sphinxsearch: /etc/sphinxsearch // 用来存放sphinx当中的一些配置文件

安装好后,还会有2个工具,存放在/usr/bin/下边

root@iZ94j7:/# usr/bin$ indexer 创建索引

root@iZ94j7:/# usr/bin$ searched 后端的进程

六、Sphinx配置



1、尝试开启sphinx服务

root@iZ94j7:/usr/share# sudo service sphinxsearch start

Starting sphinxsearch:

// 提示需要先进行配置

Please create an /etc/sphinxsearch/sphinx.conf configuration file.

A template is provided as /etc/sphinxsearch/sphinx.conf.sample.

root@iZ94j7:/usr/share#



七、Indexer

通过Indexer工具产生索引数据

八、searched

该工具默认安装在:root@112: cd /usr/bin 目录下
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  php sphinx