ThinkPHP CoreSeek 中文搜索 安装教程

来源:GK导航    date:2022-9-6    标签:,     admin

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

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

[title]下载编译文件:[/title]

tar xvfz coreseek-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/coreseek  --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.coreseek.cn/product_install/install_on_bsd_linux/#mysql" data-mce-href="http://www.coreseek.cn/product_install/install_on_bsd_linux/#mysql">查看MySQL数据源安装说明</a>  $ make && make install  $ cd ..

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

#  # 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 utf8          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  }

[title]开启searchd服务:[/title]

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

[title]ThinkPHP部分:[/title]

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

[title]拷贝PHP类文件:[/title]

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

ThinkPHP/Library/Vendor/Sphinx.class.php

[title]前端Controller 使用方法:[/title]

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']; //结果集

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

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

/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

腾讯云限时秒杀【点击购买】

搬瓦工,CN2高速线路,1GB带宽,电信联通优化KVM,延迟低,速度快,建站稳定,搬瓦工BandwagonHost VPS优惠码BWH26FXH3HIQ,支持<支付宝> 【点击购买】!

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

阿里云香港、新加坡VPS/1核/1G/25G SSD/1T流量/30M带宽/年付¥288【点击购买】

ThinkPHP CoreSeek 中文搜索 安装教程

`微信`扫码 加好友