sphinx 快速使用
- 建立配置文件 例可以参照之前的模板新建一个配置文件 sphinx/etc目录
#MySQL数据源配置,详情请查看:http://www.coreseek.cn/products-install/mysql/
#请先将var/test/documents.sql导入数据库,并配置好以下的MySQL用户密码数据库 #源定义
source mysql
{
type = mysql sql_host = localhost
sql_user = root
sql_pass =
sql_db = test
sql_port = 3306
sql_query_pre = SET NAMES utf8 sql_query = SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content FROM documents
#sql_query第一列id需为整数
#title、content作为字符串/文本字段,被全文索引
sql_attr_uint = group_id #从SQL读取到的值必须为整数
sql_attr_timestamp = date_added #从SQL读取到的值必须为整数,作为时间属性 sql_query_info_pre = SET NAMES utf8 #命令行查询时,设置正确的字符集
sql_query_info = SELECT * FROM documents WHERE id=$id #命令行查询时,从数据库读取原始数据信息
} #index定义
index mysql
{
source = mysql #对应的source名称
path = C:\wamp\apps\sphinx\var #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...
docinfo = extern
mlock = 0
morphology = none
min_word_len = 1
html_strip = 0 #中文分词配置,详情请查看:http://www.coreseek.cn/products-install/coreseek_mmseg/
#charset_dictpath = /usr/local/mmseg3/etc/ #BSD、Linux环境下设置,/符号结尾
charset_dictpath = C:\wamp\apps\sphinx\etc #Windows环境下设置,/符号结尾,最好给出绝对路径,例如:C:/usr/local/coreseek/etc/...
charset_type = zh_cn.utf-8
} #全局index定义
indexer
{
mem_limit = 128M
} #searchd服务定义
searchd
{
listen = 9312
read_timeout = 5
max_children = 30
max_matches = 1000
seamless_rotate = 0
preopen_indexes = 0
unlink_old = 1
pid_file = C:\wamp\apps\sphinx\var\log\searchd_mysql.pid #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...
log = C:\wamp\apps\sphinx\var\log\searchd_mysql.log #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...
query_log = C:\wamp\apps\sphinx\var\log\query_mysql.log #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...
binlog_path = #关闭binlog日志
} 把
searchd服务安装成一个Windows服务:c:\wamp\apps\sphinx\bin>searchd --install --config c:\wamp\apps\sphinx\etc\sphinx_mysql.conf
Coreseek Fulltext 4.0 [ Sphinx 1.11-dev (r2540)]
Copyright (c) 2007-2011,
Beijing Choice Software Technologies Inc (http://www.coreseek.com)
Installing service...
Service 'searchd' installed succesfully.
这样 searchd 服务应该出现在“控制面板->系统管理->服务”的列表中了,但还没有被启动,因为在启动它之前,我们还需要做些配置并用indexer 建立索引 . 这些可以参考 快速入门教程.
3.建立索引
c:\wamp\apps\sphinx\bin>indexer --all --config C:\wamp\apps\sphinx\etc\sphinx.conf
indexing index 'mysql'...
collected 3 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 3 docs, 7545 bytes
total 0.026 sec, 287198 bytes/sec, 114.19 docs/sec
total 2 reads, 0.000 sec, 4.2 kb/call avg, 0.0 msec/call avg
total 9 writes, 0.000 sec, 2.2 kb/call avg, 0.0 msec/call avg
indexer 直接打入命令,可以查看,帮助选项
--config <file> read configuration from specified file
(default is csft.conf)
--all reindex all configured indexes
--quiet be quiet, only print errors
--verbose verbose indexing issues report
--noprogress do not display progress
(automatically on if output is not to a tty)
--buildstops <output.txt> <N>
build top N stopwords and write them to given file
--buildfreqs store words frequencies to output.txt
(used with --buildstops only)
--merge <dst-index> <src-index>
merge 'src-index' into 'dst-index'
'dst-index' will receive merge result
'src-index' will not be modified
--merge-dst-range <attr> <min> <max>
filter 'dst-index' on merge, keep only those documents
where 'attr' is between 'min' and 'max' (inclusive)
--merge-klists
--merge-killlists merge src and dst kill-lists (default is to
apply src kill-list to dst index)
--dump-rows <FILE> dump indexed rows into FILE Examples:
4.进行索引
c:\wamp\apps\sphinx\bin>search.exe -c c:\wamp\apps\sphinx\etc\sphinx.conf twitter
指定配置文件,搜索twitter
5.集成到Php
<?php
/*
* test sphinx
*/
include_once('sphinxapi.php'); $sp = new SphinxClient(); $sp ->SetServer('127.0.0.1',9312); //connect server
$sp ->SetConnectTimeout(5); //connection timeout
$sp ->SetLimits(0,10); //($min,$max) $keywords = $_POST['kw']?trim($_POST['kw']):''; //search keywords $res = $sp ->Query($keywords,'*'); // *:all index name can use specific index
print_r($res);
返回结果如下,其中Matches数组是搜索到匹配的结果,其中key是搜索的的结果主键。
提取出key,使用in ,在连接数据库既可以取出匹配的结果。
Array
(
[error] =>
[warning] =>
[status] => 0
[fields] => Array
(
[0] => title
[1] => content
) [attrs] => Array
(
[group_id] => 1
[date_added] => 2
) [matches] => Array
(
[2] => Array
(
[weight] => 2
[attrs] => Array
(
[group_id] => 3
[date_added] => 1270135548
) ) [1] => Array
(
[weight] => 1
[attrs] => Array
(
[group_id] => 2
[date_added] => 1270131607
) ) ) [total] => 2
[total_found] => 2
[time] => 0.001
[words] => Array
(
[twitter] => Array
(
[docs] => 2
[hits] => 5
) ) )
sphinx 快速使用的更多相关文章
- 使用sphinx快速为你python注释生成API文档
sphinx简介sphinx是一种基于Python的文档工具,它可以令人轻松的撰写出清晰且优美的文档,由Georg Brandl在BSD许可证下开发.新版的Python3文档就是由sphinx生成的, ...
- 使用sphinx快速生成Python API 文档
一 简单介绍 不管是开源还是闭源,文档都是很重要的.当然理论上说,最好的文档就是代码本身,但是要让所有人都能读懂你的代码这太难了.所以我们要写文档.大部分情况,我们不希望维护一份代码再加上一份文档, ...
- 我为NET狂~群福利:逆天书库
我为NET狂-官方群① 238575862 爱学习,爱研究,福利不断,技能直彪~~ 最近更新:2016-08-30,欢迎补充 暂缺PDF: │ SQL Server 2012 Analysis Ser ...
- 【整理】Linux下中文检索引擎coreseek4安装,以及PHP使用sphinx的三种方式(sphinxapi,sphinx的php扩展,SphinxSe作为mysql存储引擎)
一,软件准备 coreseek4.1 (包含coreseek测试版和mmseg最新版本,以及测试数据包[内置中文分词与搜索.单字切分.mysql数据源.python数据源.RT实时索引等测 ...
- [搜索引擎]Sphinx的介绍和原理探索
What/Sphinx是什么 定义 Sphinx是一个全文检索引擎. 特性 索引和性能优异 易于集成SQL和XML数据源,并可使用SphinxAPI.SphinxQL或者SphinxSE搜索接口 易于 ...
- mydumper 快速高效备份mysql,按照表生成备份文件,快速恢复
Mydumper是一个针对MySQL和Drizzle的高性能多线程备份和恢复工具.开发人员主要来自MySQL,Facebook,SkySQL公司.目前已经在一些线上使用了Mydumper. Mydum ...
- Sphinx : 高性能SQL全文检索引擎
Sphinx的特点 快速创建索引:3分钟左右即可创建近100万条记录的索引,并且采用了增量索引的方式,重建索引非常迅速. 闪电般的检索速度:尽管是1千万条的大数据量,查询数据的速度也在毫秒级以上,2- ...
- CentOS6.5 安装Sphinx 配置MySQL数据源
前提安装完mysql,并创建测试表和数据 DROP TABLE IF EXISTS `documents`; CREATE TABLE IF NOT EXISTS `documents` ( `i ...
- Sphinx 之 Coreseek、Sphinx-for-chinaese、Sphinx+Scws 评测
Sphinx是一个基于SQL的全文检索引擎:普遍使用于很多网站:但由于中英文的差异,其本身,对中文的支持并不好.主要体现在对一段话断词:英文只需按照空格对其分词即可:但对于博大精深的中文来说,却是件困 ...
随机推荐
- codeforces540E-树状数组求逆序对
1-1e9的数据范围 但有1e5个区间 所以可以考虑把没有涉及到的区间缩成一个点 然后树状数组求逆序对 #include<bits/stdc++.h> #define inf 0x3f3f ...
- Memcache未授权访问漏洞利用及修复
Memcached是一套分布式的高速缓存系统.它以Key-Value(键值对)形式将数据存储在内存中,这些数据通常是应用读取频繁的.正因为内存中数据的读取远远大于硬盘,因此可以用来加速应用的访问.本文 ...
- Windows和Ubuntu使用网线直连搭建局域网
1.Windows下的配置:右键右下角的网络图标(或者右键网络→属性)→更改适配器设置→以太网→右键属性→TCP/IPv4→IP地址(192.168.1.3)→子网掩码(255.255.255.0)→ ...
- 浮点数据与IEE754
在计算机系统(包括单片机)中,浮点数(单精度float和双精度的double)对采用IEE-754标准.该标准为 32 位浮点和 64 位双精度浮点二进制小数定义了二进制标准. IEEE 754 用科 ...
- Spring Boot Security配置教程
1.简介 在本文中,我们将了解Spring Boot对spring Security的支持. 简而言之,我们将专注于默认Security配置以及如何在需要时禁用或自定义它. 2.默认Security设 ...
- Linux关闭/开启防火墙命令
Linux还是比较常用的,于是我研究了一下Linux关闭防火墙命令,在这里拿出来和大家分享一下,希望你能学会Linux关闭防火墙命令 . 1) 永久性生效,重启后不会复原 开启: chkconfig ...
- Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own promise library instead: http://mongoosejs.com/docs/promises.html
操作数据库的时候,老是提示:Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your ow ...
- css3的animation动画
animation 设置对象的动画特效 有6个主要的值 animation-name 动画名称 animation-duration 动画持续时间 animation-timing-fun ...
- IO(字节流、字符流)
第1章 字节流 在前面的学习过程中,我们一直都是在操作文件或者文件夹,并没有给文件中写任何数据.现在我们就要开始给文件中写数据,或者读取文件中的数据. 1.1 字节输出流OutputStream ...
- I/O操做总结(四))
前面已经把java io的主要操作讲完了 这一节我们来说说关于java io的其他内容 Serializable序列化 实例1:对象的序列化 1 2 3 4 5 6 7 8 9 10 11 12 13 ...