在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. NEUQOJ 1999: 三角形or四边形?【搜索联通块/模拟】

    http://newoj.acmclub.cn/problems/1999 1999: 三角形or四边形? 描述 题目描述: JiangYu很无聊,所以他拿钉子在板子上戳出了一个由.#组成的10*10 ...

  2. [xsy2724]Tree

    题意:给一棵树,找出$k$个点$A_{1\cdots k}$以最小化$\begin{align*}\sum\limits_{i=1}^{k-1}dis_{A_i,A_{i+1}}\end{align* ...

  3. 线程流量控制工具之Semaphore

    简介 Semaphore(信号量)是用来控制同时访问特定资源的线程数量,它通过协调各个线程,以保证合理的使用公共资源.很多年以来,我都觉得从字面上很难理解Semaphore所表达的含义,只能把它比作是 ...

  4. pr_debug、dev_dbg等动态调试三

    内核版本:Linux-3.14 作者:彭东林 邮箱:pengdonglin137@163.com 如果没有使用CONFIG_DYNAMIC_DEBUG,那么就需要定义DEBUG,那么此时pr_debu ...

  5. Facebook KeyHash生成方法

    1. 去https://code.google.com/p/openssl-for-windows/downloads/list下载OpenSSL工具 2.  在C盘根目录下新建一个openssl的文 ...

  6. Linux下安装Eclipse的PHP插件(PHPEclipse)

    下载: Eclipse: http://www.eclipse.org/downloads/       (本人用的Ubuntu,直接在SoftWare Center中下载的) (选择适合你系统的相应 ...

  7. python virtualenv virtualenvwrapper

    python中的virtualenv模块能够将项目环境分隔开,而不是使用全局的环境,非常实用. 首先pip install virtualenv 如何创建一个环境virtualenv testvir ...

  8. 获取本机IP,用户代理

    1.获取本机IP:http://httpbin.org/ip 2.获取用户代理 https://httpbin.org/user-agent https://httpbin.org/ httpbin( ...

  9. postman(一)批量执行接口测试用例

    postman(一)批量执行接口测试用例 学习了:https://blog.csdn.net/github_36032947/article/details/78611405 还可以把collecti ...

  10. Android源代码下载

    清华大学AOSP镜像: https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/