在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. cl编译C文件的环境变量修改

    添 加环境 变量INCLUDEC:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt;C:\Program Files (x8 ...

  2. 四. Java继承和多态6. 多态对象的类型转换

    这里所说的对象类型转换,是指存在继承关系的对象,不是任意类型的对象.当对不存在继承关系的对象进行强制类型转换时,java 运行时将抛出 java.lang.ClassCastException 异常. ...

  3. Introduction to the TestFlight SDK

    https://developer.apple.com/testflight/ When you want to test an app on your device, usually you plu ...

  4. Assembly.Load动态加载程序集而不占用文件 z

    方式一:占用文件的加载 Assembly assembly = Assembly.Load(path); 用上面的方法可以动态的加载到dll,但是用这种方法加载到的dll一直到程序运行结束都是占用的d ...

  5. [置顶] kubernetes资源类型--Service

    为了适应快速的业务需求,微服务架构已经逐渐成为主流,微服务架构的应用需要有非常好的服务编排支持.K8S中的核心要素Service便提供了一套简化的服务代理和发现机制,天然适应微服务架构. 实现原理 S ...

  6. codeigniter与swfupload完整解决方案

    转自:http://blog.sina.com.cn/s/blog_6d8dc8eb0100s4bv.html codeigniter(简称ci)有研究了一段时间了,看重的是ci的轻量,便捷,最近公司 ...

  7. vsftp 服务配置篇

    在CentOS或者RedHat Linux上有自带的ftp软件叫做vsftpd (very serure ftp) 搭建vsftpd 服务 yum 安装需要用两个包:vsftpd 和 db4-util ...

  8. 批处理学习:for语句详解

    大纲 一 前言 二 for语句的基本用法 三 for /f (delims.tokens.skip.eol.userbackq.变量延迟) 四 for /r (递归遍历) 五 for /d (遍历目录 ...

  9. log4j教程 7、日志记录级别

    org.apache.log4j.Level类提供以下级别,但也可以通过Level类的子类自定义级别. Level 描述 ALL 各级包括自定义级别 DEBUG 指定细粒度信息事件是最有用的应用程序调 ...

  10. cocos2d-x ios游戏开发初认识(六) 渲染的优化

    做程序开发肯定要考虑到内存的优化,毕竟iphone本身的内存就不是非常大.这一节主要说这个cocos2d开发对内存的优化,详细表如今,既能够对同样的精灵(图片)仅仅渲染一次,也能够对不能的精灵仅仅渲染 ...