解析coreseek for sphinx的使用

yipeiwu_com6年前PHP代码库

1.将下载下来的文件包解压,重新命名为sphinx或者其他。然后放到一个比较合适的位置,一般放到d盘根目录下面。
2.找到D:\sphinx\etc里面的csft_mysql.conf这个文件,打开它,推荐用ue或者editplus。因为记事本打开会没有样式。这是因为在linux下面的文件的缘故。
3.做必要的修改。因为这个修改因表不同和你想要取的内容不同,这里就没有标准的,只能给个实例我的修改是这样的:

复制代码 代码如下:

#源定义
source main
{
 type     = mysql
 sql_host    = 192.168.1.250
 sql_user    = root
 sql_pass    = 123456
 sql_db     = db_youxue
 sql_port    = 3306

 sql_query_pre   = SET NAMES utf8
 sql_query_pre                   = set SESSION query_cache_type = OFF #我加的
 sql_query_pre                   = replace into sph_counter select 1,max(Fid) from t_store   #我加的

 sql_query   = SELECT Fid, Ftitle, Fcontent, Fprovince,Fexamtitle, UNIX_TIMESTAMP(Fcreatetime) AS Fcreatetime FROM t_store where Fid<=(select Fmaxid from sph_counter where Fid = 1)
           #sql_query第一列id需为整数
           #title、content作为字符串/文本字段,被全文索引
 sql_attr_uint   = Fid   #从SQL读取到的值必须为整数
 sql_attr_timestamp  = Fcreatetime      #从SQL读取到的值必须为整数,作为时间属性
 sql_query_info   = SELECT * FROM t_store WHERE Fid=$id  #命令行查询时,从数据库读取原始数据信息
}
#index定义
index main
{
 source   = main             #对应的source名称
 path   = var/data/mysql
 docinfo   = extern
 mlock   = 0
 morphology  = none
 min_word_len  = 1
 html_strip    = 0
 #charset_dictpath = /usr/local/mmseg3/etc/ #BSD、Linux环境下设置,/符号结尾
 charset_dictpath = etc/      #Windows环境下设置,/符号结尾
 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 = var/log/searchd_mysql.pid
 log = var/log/searchd_mysql.log
 query_log = var/log/query_mysql.log
}
source deltaMain: main
{
 sql_query_pre = set names utf8
 sql_query = SELECT Fid, Ftitle, Fcontent, Fprovince,Fexamtitle, UNIX_TIMESTAMP(Fcreatetime) AS Fcreatetime FROM t_store where Fid>(select Fmaxid from sph_counter where Fid=1)
}
index deltaMain: main
{
 source = deltaMain
 path   = var/data/delta
}

这样配置就可以了。
4.在命令行里面找到sphinx的目录。然后输入:
bin\indexer -c etc\csft_mysql.conf
回车,这个是生成新的索引。

5.再输入:
bin\indexer -c etc\csft_mysql.conf --all
回车,如果这里数据大的话会等待些时间。一般10000条20秒吧。反正没有官方说的快。再输入:
bin\searchd -c etc\csft_mysql.conf --console 回车启动searchd服务。这个时候可以在任务管理器的进程中找到这个searchd服务。这样就具备了查询的基本条件了。

6.输入:
bin\searchd -c etc\csft_mysql.conf -a document
回车,意思是搜索包含document的所有匹配项。

相关文章

php实现网页上一页下一页翻页过程详解

php实现网页上一页下一页翻页过程详解

前言 这几天做项目因为数据太多,需要对信息进行上下翻页展示,就自己写了翻页的代码 大致功能就是页面只显示几条信息,按上一页、下一页切换内容,当显示第一页时上一页和首页选项不可选,当页面加...

通过chrome浏览器控制台(Console)进行PHP Debug的方法

通过chrome浏览器控制台(Console)进行PHP Debug的方法

 效果如下图 PHP Console是一款可以帮助用户模拟真实的PHP网站运行环境,帮助用户使用Chrome插件对PHP代码进行调试的Chrome插件,用户在Chrome中安...

php 中文字符入库或显示乱码问题的解决方法

大家以后在编写过程中, 一定要记得定义字符类型。mysql_query("set names 'gbk'") 解决的方法就这么简单。 今天做了一个数据库查询,放出代码。 复制代码 代码如...

为你总结一些php系统类函数

认为整理的还比较详细的,亲们,就快点收藏起来吧! PHP系统类函数 assert函数:检查assertion声明是否错误 extension_loaded函数:检查PHP扩展是否加载 g...

php sprintf()函数让你的sql操作更安全

$bookSQL=sprintf("UPDATE book SET pass=%s WHERE id=%d",   ...