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. left join on 和where条件的放置(转)

    http://blog.csdn.net/muxiaoshan/article/details/7617533

  2. 如何使用在Windows 下AspNetCore Api 和 consul

    在Windows 下如何使用 AspNetCore Api 和 consul https://blog.csdn.net/sD7O95O/article/details/80750803 一.概念:什 ...

  3. Ubuntu18.10设置静态IP、DNS、卸载无用软件

    设置静态IP root@xueji:~# vim /etc/network/interfaces # interfaces() ) and ifdown() auto lo iface lo inet ...

  4. 第十五章 提升用户体验 之 设计实现MVC controllers 和 actions

    1. 概述 controllers 和 actions 是 ASP.NET MVC4中非常重要的组成部分. controller管理用户和程序间的交互,使用action作为完成任务的方式. 如果是包含 ...

  5. 洛谷 P1821 [USACO07FEB]银牛派对Silver Cow Party

    银牛派对 正向建图+反向建图, 两边跑dijkstra,然后将结果相加即可. 反向建图以及双向建图的做法是学习图论的必备思想. #include <iostream> #include & ...

  6. Linux下常用的数据恢复工具

    一.数据删除 命令:rm -rf,将任何数据直接从硬盘删除,且没有任何提示 建议做法: 把命令参数放到后面:rm -rfi 将删除的东西通过mv命令移动到系统下的/temp目录下,然后写个脚 本定期执 ...

  7. java 通过文件后缀名查找文件

    最近开发项目的时候需要过滤出一些指定的文件,所以有了以下的一些代码: /** **该类主要是过滤得到指定后缀名的文件 **/ public class DataFileFilter implement ...

  8. Android GreenDao操作外部DB数据库文件

    1.背景 所谓外部数据库文件此处指的就是一个在外部单独创建的db文件,假设有这么一个场景,我们项目中有一些本地数据,不需要接口去获取的(不需要进行网络操作),写死的数据,比如全国各个省各个市的一些基本 ...

  9. RK3288开发过程中遇到的问题点和解决方法之Kernel

    修改背光改变区间 kernel\drivers\video\backlight\pwm_bl.c static int pwm_backlight_update_status(struct backl ...

  10. Autoit3脚本编写举例

    以任务管理器为例 1.首先打开任务管理器 2.点击结束任务操作 第一步打开任务管理器 run("C:\WINDOWS\system32\taskmgr.exe"); 第二步点击结束 ...