在Centos or redhat 安装Sphinx
.首先安装依赖包
$ yum install postgresql-libs unixODBC
.安装软件
$ rpm -Uhv sphinx-2.2.-.rhel6.x86_64.rpm
.启动服务
$ service searchd start [root@face sphinx-2.2.]# find / -name sphinx
/var/run/sphinx
/var/log/sphinx
/var/lib/sphinx
/etc/logrotate.d/sphinx
/etc/sphinx
/usr/share/sphinx
/usr/share/sphinx/api/ruby/spec/sphinx
/usr/share/sphinx/api/ruby/lib/sphinx mysql> #创建测试库
mysql> create database test;
Query OK, row affected (0.00 sec)
#插入测试数据
mysql -uroot -ppassword test < /usr/share/doc/sphinx-2.2./example.sql mysql> desc tags;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| docid | int() | NO | PRI | NULL | |
| tagid | int() | NO | PRI | NULL | |
+-------+---------+------+-----+---------+-------+
rows in set (0.00 sec)
#表结构
mysql> desc documents;
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| id | int() | NO | PRI | NULL | auto_increment |
| group_id | int() | NO | | NULL | |
| group_id2 | int() | NO | | NULL | |
| date_added | datetime | NO | | NULL | |
| title | varchar() | NO | | NULL | |
| content | text | NO | | NULL | |
+------------+--------------+------+-----+---------+----------------+
rows in set (0.00 sec)
#表数据
mysql> select * from documents;
+----+----------+-----------+---------------------+-----------------+---------------------------------------------------------------------------+
| id | group_id | group_id2 | date_added | title | content |
+----+----------+-----------+---------------------+-----------------+---------------------------------------------------------------------------+
| | | | -- :: | test one | this is my test document number one. also checking search within phrases. |
| | | | -- :: | test two | this is my test document number two |
| | | | -- :: | another doc | this is another group |
| | | | -- :: | doc number four | this is to test groups |
+----+----------+-----------+---------------------+-----------------+---------------------------------------------------------------------------+
rows in set (0.00 sec) mysql> select * from tags;
+-------+-------+
| docid | tagid |
+-------+-------+
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
+-------+-------+
rows in set (0.00 sec) #sphinx的配置文件
[root@face sphinx]# grep "^$\|^#" -v sphinx.conf
source src1
{
    #数据库类型 数据来源信息
type = mysql
    #数据库的IP
sql_host = localhost
#数据库用户
     sql_user = root
    #数据库密码
sql_pass =xxxxxx
#数据库库名
sql_db = test
     #默认的配置文件没有这一句 需要注意
sql_sock = /tmp/mysql.sock
sql_port = # optional, default is 3306
     #定义取数据的SQL,第一列ID列必须为唯一的正整数值
     sql_query = SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content \
                FROM documents
sql_attr_uint = group_id
sql_attr_timestamp = date_added
}
index test1
{
    #定义索引的源
source = src1
#设置生成的索引存放路径
path = /var/lib/sphinx/test1
}
index testrt
{
#实时索引类型
type = rt
rt_mem_limit = 128M
path = /var/lib/sphinx/testrt
rt_field = title
rt_field = content
rt_attr_uint = gid
}
#定义indexer配置选项
indexer
{
     #定义生成索引过程使用索引的限制
mem_limit = 128M
}
##定义searchd守护进程的相关选项
searchd
{
     #tcp        0      0 0.0.0.0:9312                0.0.0.0:*                   LISTEN      9289/searchd    
listen =
listen = :mysql41
#进程服务日志
     log = /var/log/sphinx/searchd.log
     #查询日志
query_log = /var/log/sphinx/query.log
     #网络客服端请求的读超时 时间
read_timeout =
#子进程数
max_children =
#进程文件的路径
pid_file = /var/run/sphinx/searchd.pid

#启用无缝seamless轮转,防止searchd轮转在需要预取大量数据的索引时停止响应
#也就是说在任何时刻查询都可用,或者使用旧索引,或者使用新索引

        seamless_rotate         =
preopen_indexes =
unlink_old =
workers = threads # for RT to work
binlog_path = /var/lib/sphinx/
}
[root@face sphinx]# service searchd start
Starting searchd: Sphinx 2.2.-id64-release (2c212e0)
Copyright (c) -, Andrew Aksyonoff
Copyright (c) -, Sphinx Technologies Inc (http://sphinxsearch.com) using config file '/etc/sphinx/sphinx.conf'...
listening on all interfaces, port=
listening on all interfaces, port=
precaching index 'test1'
WARNING: index 'test1': preload: /var/lib/sphinx/test1.sph is invalid header file (too old index version?); NOT SERVING
precaching index 'testrt'
precached indexes in 0.004 sec
[ OK ]
#如果启动有warning 注意这儿的权限
[root@face sphinx]# pwd
/var/lib/sphinx
[root@face sphinx]# chown sphinx.sphinx ./ -R
[root@face sphinx]#
[root@face sphinx]# ll
total
-rw-------. sphinx sphinx Jan : binlog.
-rw-------. sphinx sphinx Jan : binlog.lock
-rw-------. sphinx sphinx Jan : binlog.meta
-rw-r--r--. sphinx sphinx Jan : test1.spa
-rw-r--r--. sphinx sphinx Jan : test1.spd
-rw-r--r--. sphinx sphinx Jan : test1.spe
-rw-r--r--. sphinx sphinx Jan : test1.sph
-rw-r--r--. sphinx sphinx Jan : test1.spi
-rw-r--r--. sphinx sphinx Jan : test1.spk
-rw-r--r--. sphinx sphinx Jan : test1.spm
-rw-r--r--. sphinx sphinx Jan : test1.spp
-rw-r--r--. sphinx sphinx Jan : test1.sps
-rw-------. sphinx sphinx Jan : testrt.lock #不能有warning 开始的时候
[root@face sphinx]# service searchd restart
Stopping searchd: [ OK ]
Starting searchd: Sphinx 2.2.-id64-release (2c212e0)
Copyright (c) -, Andrew Aksyonoff
Copyright (c) -, Sphinx Technologies Inc (http://sphinxsearch.com) using config file '/etc/sphinx/sphinx.conf'...
listening on all interfaces, port=
listening on all interfaces, port=
precaching index 'test1'
precaching index 'testrt'
precached indexes in 0.001 sec
[ OK ]
#不+ --rotate有可能起不来
[root@face sphinx]# indexer --all --rotate
Sphinx 2.2.-id64-release (2c212e0)
Copyright (c) -, Andrew Aksyonoff
Copyright (c) -, Sphinx Technologies Inc (http://sphinxsearch.com) using config file '/etc/sphinx/sphinx.conf'...
indexing index 'test1'...
collected docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total docs, bytes
total 0.003 sec, bytes/sec, 1221.74 docs/sec
skipping non-plain index 'testrt'...
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: successfully sent SIGHUP to searchd (pid=).
#连接server 查看数据状态
[root@face sphinx]# mysql -h0 -P9306
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 2.2.-id64-release (2c212e0) Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show tables;
+--------+-------+
| Index | Type |
+--------+-------+
| test1 | local |
| testrt | rt |
+--------+-------+
rows in set (0.00 sec) mysql> select * from test1;
+------+----------+------------+
| id | group_id | date_added |
+------+----------+------------+
| | | |
| | | |
| | | |
| | | |
+------+----------+------------+
rows in set (0.00 sec)
mysql> select * from testrt;
Empty set (0.00 sec)

mysql> INSERT INTO testrt VALUES ( 1, 'first record', 'test one', 123 );

Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO testrt VALUES ( 2, 'second record', 'test two', 234 );
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO testrt VALUES ( 3, 'three record', 'three', 334 );
Query OK, 1 row affected (0.00 sec)

mysql> SELECT * FROM testrt;
+------+------+
| id | gid |
+------+------+
| 1 | 123 |
| 2 | 234 |
| 3 | 334 |
+------+------+
3 rows in set (0.00 sec)

mysql> SELECT * FROM testrt WHERE MATCH('test');
+------+------+
| id | gid |
+------+------+
| 1 | 123 |
| 2 | 234 |
+------+------+
2 rows in set (0.00 sec)


#模糊匹配
mysql> SELECT * FROM test1 WHERE MATCH('my document');
+------+----------+------------+
| id | group_id | date_added |
+------+----------+------------+
| | | |
| | | |
+------+----------+------------+
rows in set (0.00 sec) mysql> SELECT *, WEIGHT() FROM test1 WHERE MATCH('"document one"/1');SHOW META;
+------+----------+------------+----------+
| id | group_id | date_added | weight() |
+------+----------+------------+----------+
| | | | |
| | | | |
+------+----------+------------+----------+
rows in set (0.18 sec)
#相关的元数据信息
+---------------+----------+
| Variable_name | Value |
+---------------+----------+
| total | |
| total_found | |
| time | 0.175 |
| keyword[] | document |
| docs[] | |
| hits[] | |
| keyword[] | one |
| docs[] | |
| hits[] | |
+---------------+----------+
rows in set (0.00 sec) #相关的统计信息
mysql> SET profiling=;SELECT * FROM test1 WHERE id IN (,,);SHOW PROFILE;
Query OK, rows affected (0.00 sec) +------+----------+------------+
| id | group_id | date_added |
+------+----------+------------+
| | | |
| | | |
| | | |
+------+----------+------------+
rows in set (0.00 sec) +--------------+----------+----------+---------+
| Status | Duration | Switches | Percent |
+--------------+----------+----------+---------+
| unknown | 0.000206 | | 65.61 |
| net_read | 0.000004 | | 1.27 |
| local_search | 0.000040 | | 12.74 |
| sql_parse | 0.000027 | | 8.60 |
| fullscan | 0.000002 | | 0.64 |
| finalize | 0.000015 | | 4.78 |
| aggregate | 0.000008 | | 2.55 |
| net_write | 0.000012 | | 3.82 |
| eval_post | 0.000000 | | 0.00 |
| total | 0.000314 | | |
+--------------+----------+----------+---------+
rows in set (0.00 sec) mysql> SELECT id, id% idd FROM test1 WHERE MATCH('this is | nothing') GROUP BY idd;SHOW PROFILE;
+------+------+
| id | idd |
+------+------+
| | |
| | |
| | |
+------+------+
rows in set (0.18 sec) +--------------+----------+----------+---------+
| Status | Duration | Switches | Percent |
+--------------+----------+----------+---------+
| unknown | 0.000430 | | 0.24 |
| net_read | 0.000014 | | 0.01 |
| local_search | 0.000192 | | 0.11 |
| sql_parse | 0.000056 | | 0.03 |
| dict_setup | 0.000002 | | 0.00 |
| parse | 0.000040 | | 0.02 |
| transforms | 0.000003 | | 0.00 |
| init | 0.177525 | | 99.51 |
| read_docs | 0.000053 | | 0.03 |
| get_docs | 0.000008 | | 0.00 |
| get_hits | 0.000005 | | 0.00 |
| filter | 0.000002 | | 0.00 |
| rank | 0.000001 | | 0.00 |
| sort | 0.000014 | | 0.01 |
| finalize | 0.000004 | | 0.00 |
| aggregate | 0.000017 | | 0.01 |
| net_write | 0.000027 | | 0.02 |
| eval_post | 0.000001 | | 0.00 |
| total | 0.178394 | | |
+--------------+----------+----------+---------+
rows in set (0.00 sec) mysql> CALL KEYWORDS ('one two three', 'test1');
+------+-----------+------------+
| qpos | tokenized | normalized |
+------+-----------+------------+
| | one | one |
| | two | two |
| | three | three |
+------+-----------+------------+
rows in set (0.00 sec)
#hits表示是否命中
mysql> CALL KEYWORDS ('one two three', 'test1', );
+------+-----------+------------+------+------+
| qpos | tokenized | normalized | docs | hits |
+------+-----------+------------+------+------+
| | one | one | | |
| | two | two | | |
| | three | three | | |
+------+-----------+------------+------+------+
rows in set (0.00 sec)

试验到这儿吧

Sphinx初探之安装的更多相关文章

  1. sphinx 简介以及安装 以及php拓展开启

    一 sphinx 简介   在 使用mysql数据库过程中,如果想实现全文检索的优化,可以使用mysql自带全文索引,但是不支持中文..关于sphinx的安装网上很多教程写的都 不错比如:http:/ ...

  2. Sphinx下载、安装、配置、Hello World、文档阅读

    sphinx下载.安装.配置.Hello World.查看文档

  3. Sphinx中文分词安装配置及API调用

    这几天项目中需要重新做一个关于商品的全文搜索功能,于是想到了用Sphinx,因为需要中文分词,所以选择了Sphinx for chinese,当然你也可以选择coreseek,建议这两个中选择一个,暂 ...

  4. sphinx 全文搜索引擎安装与配置

    sphinx 全文搜索引擎 sphinx的安装与配置 ------------------------------------------------------------------------- ...

  5. Thrift入门初探--thrift安装及java入门实例

    什么是thrift? 简单来说,是Facebook公布的一款开源跨语言的RPC框架. 那么问题来了. 什么是RPC框架? RPC全称为Remote Procedure Call,意为远程过程调用. 假 ...

  6. (转)Sphinx中文分词安装配置及API调用

    这几天项目中需要重新做一个关于商品的全文搜索功能,于是想到了用Sphinx,因为需要中文分词,所以选择了Sphinx for chinese,当然你也可以选择coreseek,建议这两个中选择一个,暂 ...

  7. 搭建coreseek(sphinx+mmseg3)详细安装配置+php之sphinx扩展安装+php调用示例(转)

    一个文档包含了安装.增量备份.扩展.api调用示例,省去了查找大量文章的时间. 搭建coreseek(sphinx+mmseg3)安装 [第一步] 先安装mmseg3 cd /var/install ...

  8. ansible 初探nginx安装

    我的配置: /etc/hosts: /etc/ansible/hosts: nglinx安装包: ansible自动化安装nginx: 1.安装ansible. 2.创建目录结构: mkdir -p ...

  9. 初探ansible安装

    一.ansible介绍常用的自动化运维工具 Puppet —基于 Ruby 开发,采用 C/S 架构,扩展性强,基于 SSL,远程命令执行相对较弱SaltStack —基于 Python 开发,采用 ...

随机推荐

  1. Codeforces Round #428 A. Arya and Bran【模拟】

    A. Arya and Bran time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  2. Web Api 返回图片流给前端

    public class TestController : ApiController { public HttpResponseMessage GetImg() { //获取文件的绝对路径 stri ...

  3. EasyUI Datagrid 单元格编辑

    3:对于单元格的编辑 $('#Units').datagrid({ pageNumber: 1, //url: "@ViewBag.Domain/Paper/GetQuestionUnit& ...

  4. linux安装mysql数据库(5.7之前的版本)

    到mysql官网下载mysql编译好的二进制安装包   解压32位安装包: 进入安装包所在目录,执行命令:tar mysql-5.6.17-linux-glibc2.5-i686.tar.gz   复 ...

  5. A Beginner’s Guide to the OUTPUT Clause in SQL Server

    原文 A Beginner’s Guide to the OUTPUT Clause in SQL Server T-SQL supports the OUTPUT clause after the ...

  6. Android开发必须知道SERVICE的10件事

    这些年我在和其他安卓攻城狮交流时经常谈到的一个话题就是Service组件被开发者错误地理解,不管是新手还是老司机.这篇文章就是交流的成果. 这篇文章不会讲解Service的使用方法,这个要去看官方的( ...

  7. RESTful接口签名认证实现机制

    RESTful接口 互联网发展至今,催生出了很多丰富多彩的应用,极大地调动了人们对这些应用的使用热情.但同时也为互联网应用带来了严峻的考验.具体体现在以下几个方面: 1.     部署方式的改变:当用 ...

  8. 新人补钙系列教程之:体验ApplicationDomain 应用程序域

    要说应用程序域,就不得不说安全沙箱 安全沙箱在帮助文档的解释是: 客户端计算机可以从很多来源(如外部 Web 站点或本地文件系统)中获取单个 SWF 文件.当 SWF 文件及其它资源(例如共享对象.位 ...

  9. leetcode题解:Valid Palindrome(判断回文)

    题目: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ig ...

  10. ElasticSearch测试数据

    curl命令数据 curl -XPUT http://127.0.0.1:9200/us/user/1 -d "{\"email\":\"john@smith. ...