1. 建立配置文件 例可以参照之前的模板新建一个配置文件 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日志
    }
  2. 把 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 快速使用的更多相关文章

  1. 使用sphinx快速为你python注释生成API文档

    sphinx简介sphinx是一种基于Python的文档工具,它可以令人轻松的撰写出清晰且优美的文档,由Georg Brandl在BSD许可证下开发.新版的Python3文档就是由sphinx生成的, ...

  2. 使用sphinx快速生成Python API 文档

    一  简单介绍 不管是开源还是闭源,文档都是很重要的.当然理论上说,最好的文档就是代码本身,但是要让所有人都能读懂你的代码这太难了.所以我们要写文档.大部分情况,我们不希望维护一份代码再加上一份文档, ...

  3. 我为NET狂~群福利:逆天书库

    我为NET狂-官方群① 238575862 爱学习,爱研究,福利不断,技能直彪~~ 最近更新:2016-08-30,欢迎补充 暂缺PDF: │ SQL Server 2012 Analysis Ser ...

  4. 【整理】Linux下中文检索引擎coreseek4安装,以及PHP使用sphinx的三种方式(sphinxapi,sphinx的php扩展,SphinxSe作为mysql存储引擎)

          一,软件准备 coreseek4.1 (包含coreseek测试版和mmseg最新版本,以及测试数据包[内置中文分词与搜索.单字切分.mysql数据源.python数据源.RT实时索引等测 ...

  5. [搜索引擎]Sphinx的介绍和原理探索

    What/Sphinx是什么 定义 Sphinx是一个全文检索引擎. 特性 索引和性能优异 易于集成SQL和XML数据源,并可使用SphinxAPI.SphinxQL或者SphinxSE搜索接口 易于 ...

  6. mydumper 快速高效备份mysql,按照表生成备份文件,快速恢复

    Mydumper是一个针对MySQL和Drizzle的高性能多线程备份和恢复工具.开发人员主要来自MySQL,Facebook,SkySQL公司.目前已经在一些线上使用了Mydumper. Mydum ...

  7. Sphinx : 高性能SQL全文检索引擎

    Sphinx的特点 快速创建索引:3分钟左右即可创建近100万条记录的索引,并且采用了增量索引的方式,重建索引非常迅速. 闪电般的检索速度:尽管是1千万条的大数据量,查询数据的速度也在毫秒级以上,2- ...

  8. CentOS6.5 安装Sphinx 配置MySQL数据源

      前提安装完mysql,并创建测试表和数据 DROP TABLE IF EXISTS `documents`; CREATE TABLE IF NOT EXISTS `documents` ( `i ...

  9. Sphinx 之 Coreseek、Sphinx-for-chinaese、Sphinx+Scws 评测

    Sphinx是一个基于SQL的全文检索引擎:普遍使用于很多网站:但由于中英文的差异,其本身,对中文的支持并不好.主要体现在对一段话断词:英文只需按照空格对其分词即可:但对于博大精深的中文来说,却是件困 ...

随机推荐

  1. 洛谷P2971 牛的政治Cow Politics

    题目描述 Farmer John's cows are living on \(N (2 \leq N \leq 200,000)\)different pastures conveniently n ...

  2. 页面出现滚动条时,body里面的内容不能自动居中?

    弹窗后允许页面滚动 这种方式通常使用 position: absolute; ,可以看看我做的这个 Demo.主要用来应对弹窗内容很大很多的情况,超过了屏幕的宽高需要产生滚动条来方便浏览者查看.有一些 ...

  3. 微信小程序实战

    为了积攒粉丝,公司决定做一个一分钱姓名测算的小程序引导大家关注公众号. 实现的需求就是  1 首页 用户编辑姓名和性别进行提交 2 测算结果页 实现分享和支付功能 3 测算历史页面 看到用户曾经测算记 ...

  4. Xshell连接不上虚拟机&连接提示SSH服务器拒绝了密码,请再试一次

    问题1:Xshell连接不上虚拟机 #启动ssh服务 /etc/init.d/ssh start #查看SSH服务22端口是否开启 netstat -antulp | grep ssh 问题2:XSh ...

  5. hibernate Restrictions用法 HibernateTemplate Hibernate结合spring

    常用方法 http://www.jb51.net/article/41541.htm ........................................... 博客分类: Hiberna ...

  6. ExceptionHandlerMiddleware中间件如何呈现“定制化错误页面”

    ExceptionHandlerMiddleware中间件如何呈现“定制化错误页面” DeveloperExceptionPageMiddleware中间件利用呈现出来的错误页面实现抛出异常和当前请求 ...

  7. 讲明白combineByKey()算子,不是谈源码

    简单介绍 combineByKey()是最通用的对key-value型rdd进行聚集操作的聚集函数(aggregation function).类似于aggregate(),combineByKey( ...

  8. 树莓派连接启动SSH

    树莓派的官方更新消息发布:http://downloads.raspberrypi.org/raspbian/release_notes.txt SSH禁用的启用方法: 2016年11月25日: * ...

  9. SpringBoot 2.x (15):Actuator监控

    Actuator监控:SpringBoot自带的,对生成环境进行监控的系统 使用:既然是监控,那就不能监控一个空项目 这里我使用SpringBoot整合MyBatis的Demo: https://ww ...

  10. Java基础(Scanner、Random、流程控制语句)

    第3天 Java基础语法 今日内容介绍 u 引用数据数据类型(Scanner.Random) u 流程控制语句(if.for.while.dowhile.break.continue) 第1章 引用数 ...