windows+sphinx+php 安装+配置+使用

本文将讲述:sphinx在windows下的安装配置;sphinx与PHP的实时索引使用;sphinx服务加入windows服务。

参考手册:http://www.coreseek.cn/docs/coreseek_4.1-sphinx_2.0.1-beta.html

一、sphinx在windows下的安装配置

1.下载地址:

http://sphinxsearch.com/downloads/    尽量下高一点的版本,我用的Sphinx 2.0.6-release,

下载后解压到,f:/sphinx(根据你的情况安装).

将sphinx.conf.in拷贝重名到/bin/sphinx.conf

新建:f:/sphinx/data 文件夹

新建:f:/sphinx/log 文件夹

2.修改配置文件(详细配置见http://blog.csdn.net/design321/article/details/8895608)

#
# Minimal Sphinx configuration sample (clean, simple, functional)
#

source src1
{

#数据库信息
    type        = mysql

    sql_host    = localhost  
    sql_user    = root
    sql_pass    = 123456
    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_attr_uint    = group_id
    sql_attr_timestamp = date_added

    sql_query_info    = SELECT * FROM documents WHERE id=$id
}


index test2
{
    source        = src1
    path        = f:/sphinx/data/test1   //新建的data目录
    docinfo        = extern
    charset_type    = utf-8
    min_prefix_len  = 0
    min_infix_len   = 0
    min_word_len    = 1
    ngram_len    = 1
    ngram_chars        = U+3000..U+2FA1F

    charset_table = 0..9, A..Z->a..z, _, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F
}


indexer
{
    mem_limit    = 32M
}


searchd
{
    port        = 3312
    log        =f:/sphinx/log/searchd.log              #新建的log目录
    #query_log    = F:/sphinx/log/query.log      #新建的log目录
    read_timeout    = 5
    max_children    = 30
    pid_file    = f:/sphinx/log/searchd.pid        #新建的log目录
    max_matches    = 1000
    preopen_indexes    = 0
    unlink_old    = 1
    seamless_rotate = 0
}
# eof


配置完成


3.导入测试数据到mysql

将example.sql文件在test数据库执行。

注意,导入的数据非utf8格式,需要自已去数据库改一下字条集。


4.建立索引

F:\sphinx\bin>indexer.exe --config f:/sphinx/bin/sphinx.conf --all


Sphinx 2.0.6-release (r3473)
Copyright (c) 2001-2012, Andrew Aksyonoff
Copyright (c) 2008-2012, Sphinx Technologies Inc (http://sphinxsearch.com)

using config file 'f:/sphinx/bin/sphinx.conf'...
indexing index 'test2'...
collected 3 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 3 docs, 138 bytes
total 0.011 sec, 12402 bytes/sec, 269.61 docs/sec
total 2 reads, 0.000 sec, 0.1 kb/call avg, 0.0 msec/call avg
total 9 writes, 0.000 sec, 0.1 kb/call avg, 0.0 msec/call avg


5.查找

F:\sphinx\bin>search.exe test


Sphinx 2.0.6-release (r3473)
Copyright (c) 2001-2012, Andrew Aksyonoff
Copyright (c) 2008-2012, Sphinx Technologies Inc (http://sphinxsearch.com)

using config file './sphinx.conf'...
index 'test2': query 'test ': returned 3 matches of 3 total in 0.000 sec

displaying matches:
1. document=2, weight=2252, group_id=1, date_added=Mon May 06 18:43:15 2013
        id=2
        group_id=1
        group_id2=6
        date_added=2013-05-06 18:43:15
        title=test two
        content=?? this is my test document number two
2. document=3, weight=1319, group_id=2, date_added=Mon May 06 18:43:15 2013
        id=3
        group_id=2
        group_id2=7
        date_added=2013-05-06 18:43:15
        title=another doc
        content=this is another group ?? test
3. document=4, weight=1319, group_id=2, date_added=Mon May 06 18:43:15 2013
        id=4
        group_id=2
        group_id2=8
        date_added=2013-05-06 18:43:15
        title=doc number four
        content=this is to test groups ??

words:
1. 'test': 3 documents, 4 hits


得到以上内容,安装成功。

二、让PHP 能使用sphinx

1.启动sphinx服务

F:\sphinx\bin>searchd.exe


Sphinx 2.0.6-release (r3473)
Copyright (c) 2001-2012, Andrew Aksyonoff
Copyright (c) 2008-2012, Sphinx Technologies Inc (http://sphinxsearch.com)

using config file './sphinx.conf'...
WARNING: compat_sphinxql_magics=1 is deprecated; please update your application
and config
listening on all interfaces, port=3312
precaching index 'test2'
precached 1 indexes in 0.002 sec
binlog: replaying log ./binlog.001

2,将F:\sphinx\api\sphinxapi.php拷贝到apach下的网站目录,以供调用.

3.利用现有索引的简单示例

<?php
require 'sphinxapi.php';
$s = new SphinxClient();
$s->SetServer('127.0.0.1',3312); //服务器名,sphinx端口号
$result = $s->Query('test','test2'); //关键词,索引名(与配置文件里一致,为*时表示全部)
echo '<pre>';
var_dump($result);
echo '<pre>';
?>



4.创建实时索引的示例

  

<?php    
    require 'sphinxapi.php';
        $keyword='中文';    
        $sphinx=new SphinxClient();
        $sphinx->SetServer("localhost",3312);
        $sphinx->SetMatchMode(SPH_MATCH_ANY);
        //$sphinx->setLimits(0,0); //偏移量
        $result=$sphinx->query("$keyword","test2");
        //echo "<pre>";
        //print_r($result);
        //echo "</pre>";
        $ids=join(",",array_keys($result['matches']));
        mysql_connect("localhost","root","123456");
        mysql_select_db("test");
        $sql="select * from documents where id in({$ids})";
        mysql_query("set names utf8");
        $rst=mysql_query($sql);
        $opts=array(
            "before_match"=>"<button style='font-weight:bold;color:#f00'>",
            "after_match"=>"</button>"
        );

        while($row=mysql_fetch_assoc($rst)){
            $rst2=$sphinx->buildExcerpts($row,"main",$keyword,$opts);
echo '<pre>';
            var_dump($row);
echo '';
            /* echo "第{$rst2[0]}篇贴子<br>";
            echo "标题: {$rst2[1]}<br>";
            echo "内容: {$rst2[2]}<br>";
            echo "<hr>"; */
        }

三、将sphinx服务添加到windows服务

F:\sphinx\bin>searchd.exe --install -c f:\sphinx\bin\sphinx.conf --servicename s


phinx
Sphinx 2.0.6-release (r3473)
Copyright (c) 2001-2012, Andrew Aksyonoff
Copyright (c) 2008-2012, Sphinx Technologies Inc (http://sphinxsearch.com)

Installing service...
Service 'sphinx' installed successfully.

F:\sphinx\bin>net start sphinx


sphinx 服务正在启动 .
sphinx 服务已经启动成功。


F:\sphinx\bin>net stop sphinx


sphinx 服务正在停止..

sphinx 服务已成功停止。


F:\sphinx\bin>sc delete sphinx

[SC] DeleteService SUCCESS




end.



  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
在Ubuntu 18.04上安装UHD GNU Radio,您可以按照以下步骤进行操作: 1. 更新软件包列表和系统软件: - sudo apt update - sudo apt upgrade 2. 安装必要的依赖包: - sudo apt install build-essential cmake libboost-all-dev libgmp-dev swig python3-numpy python3-mako python3-sphinx python3-lxml doxygen libfftw3-dev libcomedi-dev libsdl1.2-dev python3-gi-cairo python3-pygccxml python3-pygraphviz python3-qt4 python3-qwt5-qt4 libqt4-opengl-dev python3-click python3-click-plugins python3-zmq python3-scipy python3-gi python3-gi-cairo gir1.2-gtk-3.0 3. 下载UHD源文件并进行编译安装: - 选择一个合适的文件目录,并进入该目录。 - 使用如下命令下载UHD源文件: - git clone --recursive https://gitee.com/chen_nanda/gnuradio.git - 切换到所需的版本: - cd gnuradio - sudo git checkout v3.7.13.4 - sudo git submodule update --init --recursive 4. 编译和安装UHD GNU Radio: - 创建build目录并进入该目录: - sudo mkdir build - cd build - 运行cmake进行配置: - sudo cmake ../ - 运行make进行编译: - sudo make - 运行make test进行测试(可选): - sudo make test - 运行make install进行安装: - sudo make install - 更新动态链接库: - sudo ldconfig 5. 查看GNU Radio版本信息: - gnuradio_config-info --version 6. 启动GNU Radio的GUI: - gnuradio-companion 7. 对USRP进行相关初始设置: - 根据您的具体需求和硬件配置,进行USRP的相关初始化设置。 以上是在Ubuntu 18.04上安装UHD GNU Radio的步骤。请根据您的需求和具体环境进行操作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值