ThinkPHP CoreSeek 中文搜索 安装教程

由于之前我们使用的原生sphinx不支持中文搜索,所以我们这里重新安装coreseek 搜索中文,下面给出实例:

下载地址:http://vdisk.weibo.com/wap/s/z-JIj1kq4Z81

下载编译文件:

tar xvfz -3.2.14.tar.gz
##安装mmseg
$ cd mmseg-3.2.14
$ chmod +x bootstrap
$ ./bootstrap    #输出的warning信息可以忽略,如果出现error则需要解决
$ chmod +x configure
$ ./configure --prefix=/usr/local/mmseg3
$ make && make install
$ cd ..

##安装coreseek
$ cd csft-3.2.14 
$ sh buildconf.sh    #输出的warning信息可以忽略,如果出现error则需要解决
$ chmod +x configure
$ ./configure --prefix=/usr/local/  --without-unixodbc --with-mmseg --with-mmseg-includes=/usr/local/mmseg3/include/mmseg/ --with-mmseg-libs=/usr/local/mmseg3/lib/ --with-mysql    ##如果提示mysql问题,可以<a href="http://www..cn/product_install/install_on_bsd_/#mysql" data-mce-href="http://www..cn/product_install/install_on_bsd_linux/#mysql">查看MySQL数据源安装说明</a>
$ make && make install
$ cd ..

建立配置文件( /usr/local/coreseek/etc/.conf ):

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

source btlet
{
        type                                    = mysql
        sql_host                                = localhost
        sql_user                                = btlet
        sql_pass                                = laoji.org
        sql_db                                  = btlet
        sql_port                                = 3306  # optional, default is 3306

        sql_query                               = \
                SELECT id,name,infohash,files,status,hits, UNIX_TIMESTAMP(update_time) AS update_time FROM laoji_infohash

        sql_attr_timestamp      = update_time
        sql_query_pre           = SET NAMES 
        sql_query_info          = SELECT * FROM laoji_infohash WHERE id=$id
}


index infohash
{
        source                                  = btlet
        path                                    = /usr/local/coreseek/var/data/infohash
        docinfo                                 = extern
        charset_dictpath                        = /usr/local/mmseg3/etc/
        charset_type                            = zh_cn.utf-8
        ngram_len                               = 0
}


indexer
{
        mem_limit                               = 32M
}


searchd
{
        port                            = 9312
        log                             = /usr/local/coreseek/var/log/searchd.log
        query_log                       = /usr/local/coreseek/var/log/query.log
        read_timeout                    = 5
        max_children                    = 30
        pid_file                        = /usr/local/coreseek/var/log/searchd.pid
        max_matches                     = 1000
        seamless_rotate                 = 1
        preopen_indexes                 = 0
        unlink_old                      = 1
}

开启searchd服务:

/usr/local/coreseek/bin/searchd -c /usr/local/coreseek/etc/sphinx.conf

ThinkPHP部分:

以下部分在btlet.com项目中已完成,无需操作。

拷贝PHP类文件:

将下载的文件包中的 api/sphinxapi.php 重命名到:

ThinkPHP/Library/Vendor/Sphinx.class.php

前端Controller 使用方法:

import('Vendor.Sphinxapi');
$sphinx = new \SphinxClient();
$sphinx->setServer("localhost", 9312);
$sphinx->setMatchMode(SPH_MATCH_EXTENDED); //匹配模式 ANY为关键词自动拆词,ALL为不拆词匹配(完全匹配)
$sphinx->SetFilter ('status',1);
$sphinx->SetSortMode ( SPH_SORT_ATTR_DESC, "update_time" );
$sphinx->SetArrayResult ( true ); //返回的结果集为数组
$sphinx->SetLimits($off,$listRows);//传递当前页面所需的数据条数的参数
$result = $sphinx->query( $s ,"*"); //星号为所有索引源
$total=$result['total']; //查到的结果条数
$time=$result['time']; //耗时
$lists=$result['matches']; //结果集

coreseek生成索引、合并建主索引和增量索引、重建整个索引:

(重建主索引和增量索引)

/usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/sphinx.conf  --rotate

(重建整个索引)

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

搬瓦工年付$28CN2高速线路,512M内存/500G流量/1G带宽,电信联通优化,延迟低,速度快,建站稳定,搬瓦工BandwagonHost VPS优惠BWH26FXH3HIQ点击购买】!

Vultr月付$3.5日本节点,512M内存/500G流量/1G带宽,电信联通优化,延迟低,速度快【点击购买】!

点赞

发表评论

电子邮件地址不会被公开。 必填项已用*标注

Scroll Up