sphinx 全文搜索 软件 工具 的安装使用

我使用的环境是windows,过程参考了这篇文章:http://www.kaiyuanba.cn/html/1/131/140/7577.htm


1.首先是在官方<http://sphinxsearch.com/>下载了此文件:sphinx-2.0.6-release-win64.zip

2.解压之后在bin同级目录建立log和data目录,然后将根目录的example.sql在mysql的localhost服务器的test数据库上执行。

3.

Install the searchd system as a Windows service:

参考这种方式注册服务:C:\Sphinx\bin> C:\Sphinx\bin\searchd --install --config C:\Sphinx\sphinx.conf.in --servicename SphinxSearch

(这一步来自于解压包里的doc手册)

4.之后将根目录的sphinx.conf.in拷贝到bin目录下并rename为sphinx.conf,并将里面的数据库配置,和index test1和searchd进行相关配置,将其中的@CONFDIR@都替换成你的根目录,例如C:\Sphinx\

5.然后要启动守护进程searchd:


可以看到searchd监听了9312端口,并且里面已经将test1索引预先缓存了,其他的一些缓存失败我暂时没搭理


6.在解压包下面的api目录下的sphinxapi.php拿来,放到www目录下,然后编写:


<?php

require "sphinxapi.php";

$s = new SphinxClient();
$s->SetServer('localhost',9312);
$result = $s->Query('test','test1');
print_r($result);

?>

输出结果为:

Array
(
    [error] => 
    [warning] => 
    [status] => 0
    [fields] => Array
        (
            [0] => title
            [1] => content
        )

    [attrs] => Array
        (
            [group_id] => 1
            [date_added] => 2
        )

    [matches] => Array
        (
            [1] => Array
                (
                    [weight] => 2
                    [attrs] => Array
                        (
                            [group_id] => 1
                            [date_added] => 1359542960
                        )

                )

            [2] => Array
                (
                    [weight] => 2
                    [attrs] => Array
                        (
                            [group_id] => 1
                            [date_added] => 1359542960
                        )

                )

            [4] => Array
                (
                    [weight] => 1
                    [attrs] => Array
                        (
                            [group_id] => 2
                            [date_added] => 1359542960
                        )

                )

        )

    [total] => 3
    [total_found] => 3
    [time] => 0.000
    [words] => Array
        (
            [test] => Array
                (
                    [docs] => 3
                    [hits] => 5
                )

        )

)

结束。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值