zoukankan      html  css  js  c++  java
  • Sphinx与coreseek

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

    分类 编程技术

    Sphinx是一款基于SQL的高性能全文检索引擎,Sphinx的性能在众多全文检索引擎中也是数一数二的,利用Sphinx,我们可以完成比数据库本身更专业的搜索功能,而且可以有很多针对性的性能优化。

    Sphinx的特点

    • 快速创建索引:3分钟左右即可创建近100万条记录的索引,并且采用了增量索引的方式,重建索引非常迅速。
    • 闪电般的检索速度:尽管是1千万条的大数据量,查询数据的速度也在毫秒级以上,2-4G的文本量中平均查询速度不到0.1秒。
    • 为很多脚本语言设计了检索API,如PHP,Python,Perl,Ruby等,因此你可以在大部分编程应用中很方便地调用Sphinx的相关接口。
    • 为MySQL设计了一个存储引擎插件,因此如果你在MySQL上使用Sphinx,那简直就方便到家了。
    • 支持分布式搜索,可以横向扩展系统性能。

    PHP+MySQL+Sphinx 搜索引擎架构图

    MySQL中安装Sphinx

    Sphinx在MySQL上安装有两种方式:

    • 第一种方式是采用API调用,我们可以使用PHP,Python,Perl,Ruby等编程语言的API函数进行查询,这种方式不必重新编译MySQL,模块间改动比较少,相对灵活。
    • 第二种需要重新编译MySQL,将Sphinx以插件的方式编译到MySQL中去,这种方式对程序改动比较少,仅仅需要改动SQL语句即可,但前提是你的MySQL版本必须在5.1以上。

    下面是第一种安装方式:

    #下载最新稳定版

    wget http://www.sphinxsearch.com/downloads/sphinx-0.9.9.tar.gz

    tar xzvf sphinx-0.9.9.tar.gz

    cd sphinx-0.9.9

    ./configure --prefix=/usr/local/sphinx/   --with-mysql  --enable-id64

    make

    make install

    Sphinx中文分词插件Coreseek安装

    注:coreseek的安装教程来自这里,下面是详细过程:

    安装升级autoconf

    因为coreseek需要autoconf 2.64以上版本,因此需要升级autoconf,不然会报错。从http://download.chinaunix.net/download.php?id=29328&ResourceID=648下载autoconf-2.64.tar.bz2,安装方法如下:

    tar -jxvf autoconf-2.64.tar.bz2

    cd autoconf-2.64

    ./configure

    make

    make install

    下载coreseek

    新版本的coreseek将词典和sphinx源程序放在了一个包中,因此只需要下载coreseek包就可以了。

    wget http://www.wapm.cn/uploads/csft/3.2/coreseek-3.2.14.tar.gz

    安装mmseg(coreseek所使用的词典)

    tar xzvf coreseek-3.2.14.tar.gz

    cd mmseg-3.2.14

    ./bootstrap    #输出的warning信息可以忽略,如果出现error则需要解决

    ./configure --prefix=/usr/local/mmseg3

    make && make install

    cd ..

    安装coreseek(sphinx)

    cd csft-3.2.14

    sh buildconf.sh    #输出的warning信息可以忽略,如果出现error则需要解决

    ./configure --prefix=/usr/local/coreseek  --without-unixodbc --with-mmseg --with-mmseg-includes=/usr/local/mmseg3/include/mmseg/ --with-mmseg-libs=/usr/local/mmseg3/lib/ --with-mysql

    make && make install

    cd ..

    测试mmseg分词和coreseek搜索

    备注:需要预先设置好字符集为zh_CN.UTF-8,确保正确显示中文,我的系统字符集为en_US.UTF-8也是可以的。

    cd testpack

    cat var/test/test.xml  #此时应该正确显示中文

    /usr/local/mmseg3/bin/mmseg -d /usr/local/mmseg3/etc var/test/test.xml

    /usr/local/coreseek/bin/indexer -c etc/csft.conf --all

    /usr/local/coreseek/bin/search -c etc/csft.conf 网络搜索

    此时正确的应该返回

    words:

    1. '网络': 1 documents, 1 hits

    2. '搜索': 2 documents, 5 hits

    Spinx配置:

    制作一个配置文件

    cd /usr/local/sphinx/etc/

    cp sphinx.conf.dist sphinx.conf

    然后编辑配置文件

    Coreseek配置:

    cd /usr/local/coreseek/

    cp sphinx.conf.dist csft.conf

    然后编辑

    Vim  csft.conf

       

    Shhinx模块的安装:

    模块版本: sphinx-1.3.3.tgz

    tar xf sphinx-1.3.3.tgz

    cd sphinx-1.3.3/
    /usr/local/php/bin/phpize

    ./configure --with-php-config=/usr/local/php/bin/php-config --with-sphinx

    Make && make install

    然后会生成一个sphinx.so文件将这个文件放到

    Vim /usr/local/php/etc/php.ini

    如果不想安装sphinx模块的话,则可以复制出来sphinx类来实例化直接使用

    /coreseek-3.2.14/csft-3.2.14/api/ sphinxapi.php

    /usr/local/coreseek/bin/searchd

    如查报这些错不用管:

    WARNING: stopwords: failed to get file size for 'G:datastopwords.txt'

    WARNING: index 'test1': failed to stat G:datawordforms.txt: No such file or directory

    WARNING: stopwords: failed to get file size for 'G:datastopwords.txt'

    WARNING: index 'test1stemmed': failed to stat G:datawordforms.txt: No such file or directory

    WARNING: multiple addresses found for 'localhost', using the first one (ip=127.0.0.1)

    实时查询的配置

    1. 主数据数据  | 增量数据
    2. 主索引      | 增量索引
  • 相关阅读:
    Java中RuntimeException和Exception
    RuntimeException和Exception的区别
    Spring事务异常回滚
    iOS 卖票中多线程分析;
    凝视转换(部分)
    HDU 5386 Cover(模拟)
    iOS开发之软键盘使用小技巧
    【每日算法】高速幂
    CKEditor高级编辑器
    iOS开发 剖析网易新闻标签栏视图切换(addChildViewController属性介绍)
  • 原文地址:https://www.cnblogs.com/leigepython/p/8595877.html
Copyright © 2011-2022 走看看