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的全文检索引擎:普遍使用于很多网站:但由于中英文的差异,其本身,对中文的支持并不好.主要体现在对一段话断词:英文只需按照空格对其分词即可:但对于博大精深的中文来说,却是件困 ...
随机推荐
- python3 安装虚拟镜像
virtualenvwrapper--提供了一系列命令使得和虚拟环境工作变得愉快很多,他把你所需要的虚拟环境都放在一个地方. 1.先安装virtualenv:pip install virtualen ...
- 递归遍历树形json
前置知识: 1.首先 js里面“万物皆对象” 2.递归:自己调用自己(递归的优缺点:https://www.cnblogs.com/tchjs/p/4428153.html https://www. ...
- python进阶04 装饰器、描述器、常用内置装饰器
python进阶04 装饰器.描述器.常用内置装饰器 一.装饰器 作用:能够给现有的函数增加功能 如何给一个现有的函数增加执行计数的功能 首先用类来添加新功能 def fun(): #首先我们定义一个 ...
- Linux —— awk命令
- 作用: 强大的文本分析工具,对于文本分析来说绝对是一把利器 - 语法: awk '{pattern + action}' {filenames} pattern需要查找的内容 action 查找到 ...
- NET Core:部署项目到Ubuntu Server
NET Core:部署项目到Ubuntu Server 概述 基于上一篇成功安装Ubuntu Server 16.10的基础上,接下来继续我们ASP.NET Core项目的部署之旅! 只是对于这些年整 ...
- react-dnd
http://react-trello-board.web-pal.com/ https://react-dnd.github.io/react-dnd/docs-tutorial.html http ...
- Oracle ERP Interface堵住--Request Running too long time,查找Request执行的Sql
Request Running too long time 堵住了INV Manager 导致INV Interface Pending 很多笔资料 Review 发现Request 实际执行SQL ...
- springMVC框架的理解加深,个人的一些想法
一 写spring-boot整合的时候,有种想看源码的冲动!呸,是钻牛角尖的毛病犯了... @RequestMapping("/index") public String inde ...
- 老生常谈Java虚拟机垃圾回收机制(必看篇)
二.垃圾收集 垃圾收集主要是针对堆和方法区进行. 程序计数器.虚拟机栈和本地方法栈这三个区域属于线程私有的,只存在于线程的生命周期内,线程结束之后也会消失,因此不需要对这三个区域进行垃圾回收. 判断一 ...
- 【复习笔记】CSS基础
外观 color:rgba(255,255,255,1),a表示alpha,透明度值0~1 font-family:字体1,字体2,字体3;确保某字体不存在时自动选择下一个,最好使用字体的英文名称保证 ...