第 11 章 Sphinx

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

http://sphinxsearch.com/

sudo apt-get install sphinxsearch
	

/etc/sphinxsearch/sphinx.conf

sudo cp /etc/sphinxsearch/sphinx-min.conf.dist /etc/sphinxsearch/sphinx.conf
	

创建测试数据库并导入测试数据

	
$ wget http://sphinxsearch.googlecode.com/svn/trunk/example.sql
$ mysql -h localhost -uroot -p < example.sql
$ mysql -h localhost -uroot -p
CREATE USER 'test'@'localhost' IDENTIFIED BY  '';
GRANT SELECT ON test.* TO 'test'@'localhost';
FLUSH PRIVILEGES;
mysql> quit


$ echo "select * from documents" | mysql -utest -p test
Enter password:
id      group_id        group_id2       date_added      title   content
1       1       5       2011-02-12 15:29:34     test one        this is my test document number one. also checking search within phrases.
2       1       6       2011-02-12 15:29:34     test two        this is my test document number two
3       2       7       2011-02-12 15:29:34     another doc     this is another group
4       2       8       2011-02-12 15:29:34     doc number four this is to test groups

	
	

创建索引

sudo indexer <index>

	
$ sudo indexer test1

Sphinx 0.9.8.1-release (r1533)
Copyright (c) 2001-2008, Andrew Aksyonoff

using config file '/etc/sphinxsearch/sphinx.conf'...
indexing index 'test1'...
collected 4 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 4 docs, 193 bytes
total 0.012 sec, 16531.05 bytes/sec, 342.61 docs/sec
	
	
$ sudo /etc/init.d/sphinxsearch start
Starting sphinx: Sphinx 0.9.8.1-release (r1533)
Copyright (c) 2001-2008, Andrew Aksyonoff

using config file '/etc/sphinxsearch/sphinx.conf'...
creating server socket on 0.0.0.0:3312
sphinx.
	

测试

search "keyword"

	
$ search test
Sphinx 0.9.8.1-release (r1533)
Copyright (c) 2001-2008, Andrew Aksyonoff

using config file '/etc/sphinxsearch/sphinx.conf'...
index 'test1': query 'test ': returned 3 matches of 3 total in 0.000 sec

displaying matches:
1. document=1, weight=2, group_id=1, date_added=Sat Feb 12 15:29:34 2011
        id=1
        group_id=1
        group_id2=5
        date_added=2011-02-12 15:29:34
        title=test one
        content=this is my test document number one. also checking search within phrases.
2. document=2, weight=2, group_id=1, date_added=Sat Feb 12 15:29:34 2011
        id=2
        group_id=1
        group_id2=6
        date_added=2011-02-12 15:29:34
        title=test two
        content=this is my test document number two
3. document=4, weight=1, group_id=2, date_added=Sat Feb 12 15:29:34 2011
        id=4
        group_id=2
        group_id2=8
        date_added=2011-02-12 15:29:34
        title=doc number four
        content=this is to test groups

words:
1. 'test': 3 documents, 5 hits

	
	
wget http://sphinxsearch.googlecode.com/svn/trunk/api/sphinxapi.php
wget http://sphinxsearch.googlecode.com/svn/trunk/api/test.php
php test.php test
	





原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
SQL 存储 自然语言处理
sphinx(一)全文检索引擎sphinx
Sphinx是一个基于SQL的全文检索引擎,可以结合MySQL,PostgreSQL做全文搜索,它可以提供比数据库本身更专业的搜索功能,使得应用 程序更容易实现专业化的全文检索。Sphinx特别为一些脚本语言设计搜索API接口,如PHP,Python,Perl,Ruby等,同时为MySQL 也设计了一个存储引擎插件。
538 0
sphinx(一)全文检索引擎sphinx
|
关系型数据库 MySQL Linux
sphinx(三)centos7编译安装sphinx-for-chinese
Coreseek目前官方网站已经不能访问了,大概率估计后期就不会有人维护了。对于长期发展来看,可能是不要好。 所以我的博客中使用了sphinx-for-chinese。是基于sphinx2.3.1开发的。 下载地址:gitee.com/mz/sphinx
327 0
sphinx(三)centos7编译安装sphinx-for-chinese
|
自然语言处理 关系型数据库 MySQL
php sphinx 全文检索 中文分词
php sphinx 全文检索 中文分词
146 0
|
自然语言处理 算法 Java
【Solr】之中文分词及IK库的安装使用-4
【Solr】之中文分词及IK库的安装使用-4
153 0
【Solr】之中文分词及IK库的安装使用-4
|
自然语言处理 PHP 索引
sphinx(七)sphinx匹配模式
Sphinx匹配模式 语法: $sp -> SetMatchMode(常量) SPH_MATCH_ALL 匹配所有词(默认) SPH_MATCH_ANY 匹配一个词 SPH_MATCH_PHRASE 匹配整一个词 SPH_MATCH_BOOLEAN 将查询看作一个布尔表达式 SPH_MATCH_EXTENDED 查询看做一个sphinx的表达式
219 0
sphinx(七)sphinx匹配模式
|
索引
sphinx(六)sphinx 配置文件sphinx.conf配置项全解析
source:数据源,数据是从什么地方来的。 index:索引,当有数据源之后,从数据源处构建索引。索引实际上就是相当于一个字典检索。有了整本字典内容以后,才会有字典检索。 searchd:提供搜索查询服务。它一般是以deamon的形式运行在后台的。 indexer:构建索引的服务。当要重新构建索引的时候,就是调用indexer这个命令。
263 0
sphinx(六)sphinx 配置文件sphinx.conf配置项全解析
|
搜索推荐 数据库 索引
sphinx(八)sphinx增量索引
主索引的更新频率可以设置的长一些(例如设置在每天的凌晨进行),而增量索引的更新频率,我们可以将时间设置的很短(几分钟左右),这样在用户搜索的时候,我们可以同时查询这两个索引的数据。 使用“主索引+增量索引”方法有个简单的实现,在数据库中增加一个计数表,记录每次重新构建主索引时,被索引表的最后一个数据id,这样在增量索引时只需要索引这个id以后的数据即可,每次重新构建主索引时都更新这个表。
192 0
sphinx(八)sphinx增量索引
|
SQL 自然语言处理 Linux
sphinx(四)centos7安装sphinx3.3.1
Sphinx3.3.1版本是不需要编译安装的,下载下来,解压,直接就能用。 这个和我目前正在使用的sphinx-for-chinese 是有不同的。
286 0
sphinx(四)centos7安装sphinx3.3.1
|
jenkins Linux 持续交付
sphinx(五)php执行sphinx更新索引rotate命令
选择在更新数据的时候更新索引,这样做是为了保证数据检索的实时性,但是如果您的数据需要比较频繁的更新且数据量比较大,并且对数据检索没有实时性的要求,那么可以使用linux的定时任务,在使用人数较少的时候来更新索引,
109 0
sphinx(五)php执行sphinx更新索引rotate命令
|
关系型数据库 MySQL 测试技术