目錄
搭建coreseek(sphinx+mmseg3)安装
[第一步] 先安装mmseg3
[第二步] 安装coreseek
下面开始sphinx与mysql的配置
Sphinx扩展安装安装
[第一步] 安装依赖libsphinxclient
[第二步] 安装sphinx的PHP扩展
php调用sphinx示例:
首頁 後端開發 php教程 筹建coreseek(sphinx+mmseg3)详细安装配置+php之sphinx扩展安装+php调用示例

筹建coreseek(sphinx+mmseg3)详细安装配置+php之sphinx扩展安装+php调用示例

Jun 13, 2016 am 11:51 AM
array coreseek gt quot string

搭建coreseek(sphinx+mmseg3)详细安装配置+php之sphinx扩展安装+php调用示例
一个文档包含了安装、增量备份、扩展、api调用示例,省去了查找大量文章的时间。

搭建coreseek(sphinx+mmseg3)安装


[第一步] 先安装mmseg3

cd /var/installwget http://www.coreseek.cn/uploads/csft/4.0/coreseek-4.1-beta.tar.gztar zxvf coreseek-4.1-beta.tar.gzcd coreseek-4.1-betacd mmseg-3.2.14./bootstrap./configure --prefix=/usr/local/mmseg3make && make install遇到的问题:error: cannot find input file: src/Makefile.in或者遇到其他类似error错误时...解决方案:依次执行下面的命令,我运行'aclocal'时又出现了错误,解决方案请看下文描述yum -y install libtoolaclocallibtoolize --forceautomake --add-missingautoconfautoheadermake clean
登入後複製

安装好'libtool'继续从'aclocal'开始执行上面提到的一串命令,执行完后再运行最开始的安装流程即可。

[第二步] 安装coreseek

##安装coreseek$ cd csft-3.2.14 或者 cd csft-4.0.1 或者 cd csft-4.1$ 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##如果提示mysql问题,可以查看MySQL数据源安装说明   http://www.coreseek.cn/product_install/install_on_bsd_linux/#mysql$ make && make install$ cd ..##命令行测试mmseg分词,coreseek搜索(需要预先设置好字符集为zh_CN.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 网络搜索
登入後複製


出现这个 xmlpipe2 support NOT compiled in. To use xmlpipe2, install missing XML libra  错误

执行以下命令:
yum -y install expat expat-devel
登入後複製

依次安装后,从新编译coreseek,然后再生成索引,就可以通过了。

结果如下:

Coreseek Fulltext 4.1 [ Sphinx 2.0.2-dev (r2922)]  Copyright (c) 2007-2011,  Beijing Choice Software Technologies Inc (http://www.coreseek.com)   using config file 'etc/csft.conf'...  index 'xml': query '网络搜索 ': returned 1 matches of 1 total in 0.000 sec   displaying matches:  1. document=1, weight=1590, published=Thu Apr  1 07:20:07 2010, author_id=1   words:  1. '网络': 1 documents, 1 hits  2. '搜索': 2 documents, 5 hits  
登入後複製


下面开始sphinx与mysql的配置


创建sphinx统计表,在coreseek_test库中执行。

CREATE TABLE sph_counter(    counter_id INTEGER PRIMARY KEY NOT NULL,    max_doc_id INTEGER NOT NULL);
登入後複製

创建配置sphinx与mysql的配置文件

# vi /usr/local/coreseek/etc/csft_mysql.conf
登入後複製

#MySQL数据源配置,详情请查看:http://www.coreseek.cn/products-install/mysql/#请先将var/test/documents.sql导入数据库,并配置好以下的MySQL用户密码数据库#源定义source main                                                #定义源名称{    type                    = mysql    sql_host                = localhost    sql_user                = root    sql_pass                = 123456    sql_db                  = coreseek_test    sql_port                = 3306    sql_query_pre           = SET NAMES utf8                sql_query_pre           = REPLACE INTO sph_counter SELECT 1,MAX(id) FROM hr_spider_company;                                        # 更新sph_counter    sql_query               = SELECT * FROM hr_spider_company WHERE id( SELECT max_doc_id FROM sph_counter WHERE counter_id=1 )    # 根据sph_counter纪录ID读入数据    sql_query_post_index    = REPLACE INTO sph_counter SELECT 1,MAX(id) FROM hr_spider_company                                        # 更新sph_counter}#index定义index main                                                #注意与定义名称的统一性{    source              = main                                          #对应的source名称    path                = /usr/local/coreseek/var/data/mysql            #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...    docinfo             = extern    mlock               = 0    morphology          = none    min_word_len        = 1    html_strip          = 0    #中文分词配置,详情请查看:http://www.coreseek.cn/products-install/coreseek_mmseg/    charset_dictpath    = /usr/local/mmseg3/etc/                         #BSD、Linux环境下设置,/符号结尾    charset_type        = zh_cn.utf-8}index delta : main                                        #注意与定义名称的统一性{    source              = delta    path                = /usr/local/coreseek/var/data/delta}#全局index定义indexer{    mem_limit            = 128M}#searchd服务定义searchd{    listen              = 9312    read_timeout        = 5    max_children        = 30    max_matches         = 1000    seamless_rotate     = 0    preopen_indexes     = 0    unlink_old          = 1    pid_file            = /usr/local/coreseek/var/log/searchd_mysql.pid   #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...    log                 = /usr/local/coreseek/var/log/searchd_mysql.log   #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...    query_log           = /usr/local/coreseek/var/log/query_mysql.log     #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...    binlog_path         =                                                 #关闭binlog日志}
登入後複製


我的测试表名为hr_spider_company,你只需要根据实际需求更改为自己的表名即可。

调用命令列表:

启动后台服务(必须开启)
# /usr/local/coreseek/bin/searchd -c /usr/local/coreseek/etc/csft_mysql.conf
登入後複製

执行索引(查询、测试前必须执行一次)
/usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft_mysql.conf --all --rotate
登入後複製

执行增量索引
/usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft_mysql.conf delta --rotate
登入後複製

合并索引
/usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft_mysql.conf --merge main delta --rotate --merge-dst-range deleted 0 0
登入後複製

(为了防止多个关键字指向同一个文档加上--merge-dst-range deleted 0 0)

后台服务测试
# /usr/local/coreseek/bin/search -c /usr/local/coreseek/etc/csft_mysql.conf  aaa
登入後複製

关闭后台服务
# /usr/local/coreseek/bin/searchd -c /usr/local/coreseek/etc/csft_mysql.conf --stop
登入後複製

自动化命令:

crontab -e
登入後複製

*/1 * * * * /bin/sh /usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft_mysql.conf delta --rotate*/5 * * * * /bin/sh /usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft_mysql.conf --merge main delta --rotate --merge-dst-range deleted 0 030 1 * * *  /bin/sh /usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft_mysql.conf --all --rotate
登入後複製

以下任务计划的意思是:每隔一分钟执行一遍增量索引,每五分钟执行一遍合并索引,每天1:30执行整体索引。

Sphinx扩展安装安装


Coreseek官方教程中建议php使用直接include一个php文件进行操作,事实上php有独立的sphinx模块可以直接操作coreseek(coreseek就是sphinx!)已经进入了php的官方函数库,而且效率的提升不是一点点!但php模块依赖于libsphinxclient包。

[第一步] 安装依赖libsphinxclient

# cd /var/install/coreseek-4.1-beta/csft-4.1/api/libsphinxclient/# ./configure  --prefix=/usr/local/sphinxclientconfigure: creating ./config.statusconfig.status: creating Makefileconfig.status: error: cannot find input file: Makefile.in   #报错configure失败    //处理configure报错编译过程中报了一个config.status: error: cannot find input file: src/Makefile.in这个的错误,然后运行下列指令再次编译就能通过了:# aclocal# libtoolize --force# automake --add-missing# autoconf# autoheader# make clean//从新configure编译# ./configure# make && make install
登入後複製

[第二步] 安装sphinx的PHP扩展

http://pecl.php.net/package/sphinx# wget http://pecl.php.net/get/sphinx-1.3.0.tgz# tar zxvf sphinx-1.3.0.tgz# cd sphinx-1.3.0# phpize# ./configure --with-php-config=/usr/bin/php-config --with-sphinx=/usr/local/sphinxclient# make && make install# cd /etc/php.d/# cp gd.ini  sphinx.ini# vi sphinx.iniextension=sphinx.so# service php-fpm restart
登入後複製

打开phpinfo看一下是否已经支持了sphinx模块。

php调用sphinx示例:


<?php $s = new SphinxClient;    $s->setServer("127.0.0.1", 9312);    $s->setMatchMode(SPH_MATCH_PHRASE);    $s->setMaxQueryTime(30);    $res = $s->query("宝马",'main'); #[宝马]关键字,[main]数据源source    $err = $s->GetLastError();    var_dump(array_keys($res['matches']));    echo "<br>"."通过获取的ID来读取数据库中的值即可。"."<br>";        echo '<pre class="brush:php;toolbar:false">';    var_dump($res);    var_dump($err);    echo '
登入後複製
';

输出结果:

array(20) {  [0]=>  int(1513)  [1]=>  int(42020)  [2]=>  int(57512)  [3]=>  int(59852)  [4]=>  int(59855)  [5]=>  int(60805)  [6]=>  int(94444)  [7]=>  int(94448)  [8]=>  int(99229)  [9]=>  int(107524)  [10]=>  int(111918)  [11]=>  int(148)  [12]=>  int(178)  [13]=>  int(595)  [14]=>  int(775)  [15]=>  int(860)  [16]=>  int(938)  [17]=>  int(1048)  [18]=>  int(1395)  [19]=>  int(1657)}<br>通过获取的ID来读取数据库中的值即可。<br><pre class="brush:php;toolbar:false">array(10) {  ["error"]=>  string(0) ""  ["warning"]=>  string(0) ""  ["status"]=>  int(0)  ["fields"]=>  array(17) {    [0]=>    string(3) "cid"    [1]=>    string(8) "link_url"    [2]=>    string(12) "company_name"    [3]=>    string(9) "type_name"    [4]=>    string(10) "trade_name"    [5]=>    string(5) "scale"    [6]=>    string(8) "homepage"    [7]=>    string(7) "address"    [8]=>    string(9) "city_name"    [9]=>    string(8) "postcode"    [10]=>    string(7) "contact"    [11]=>    string(9) "telephone"    [12]=>    string(6) "mobile"    [13]=>    string(3) "fax"    [14]=>    string(5) "email"    [15]=>    string(11) "description"    [16]=>    string(11) "update_time"  }  ["attrs"]=>  array(3) {    ["from_id"]=>    string(1) "1"    ["link_id"]=>    string(1) "1"    ["add_time"]=>    string(1) "1"  }  ["matches"]=>  array(20) {    [1513]=>    array(2) {      ["weight"]=>      int(2)      ["attrs"]=>      array(3) {        ["from_id"]=>        string(1) "2"        ["link_id"]=>        string(7) "3171471"        ["add_time"]=>        string(10) "1394853454"      }    }    [42020]=>    array(2) {      ["weight"]=>      int(2)      ["attrs"]=>      array(3) {        ["from_id"]=>        string(1) "2"        ["link_id"]=>        string(7) "2248093"        ["add_time"]=>        string(10) "1394913884"      }    }    [57512]=>    array(2) {      ["weight"]=>      int(2)      ["attrs"]=>      array(3) {        ["from_id"]=>        string(1) "2"        ["link_id"]=>        string(7) "2684470"        ["add_time"]=>        string(10) "1394970833"      }    }    [59852]=>    array(2) {      ["weight"]=>      int(2)      ["attrs"]=>      array(3) {        ["from_id"]=>        string(1) "3"        ["link_id"]=>        string(1) "0"        ["add_time"]=>        string(10) "1394977527"      }    }    [59855]=>    array(2) {      ["weight"]=>      int(2)      ["attrs"]=>      array(3) {        ["from_id"]=>        string(1) "3"        ["link_id"]=>        string(1) "0"        ["add_time"]=>        string(10) "1394977535"      }    }    [60805]=>    array(2) {      ["weight"]=>      int(2)      ["attrs"]=>      array(3) {        ["from_id"]=>        string(1) "3"        ["link_id"]=>        string(1) "0"        ["add_time"]=>        string(10) "1394980072"      }    }    [94444]=>    array(2) {      ["weight"]=>      int(2)      ["attrs"]=>      array(3) {        ["from_id"]=>        string(1) "3"        ["link_id"]=>        string(1) "0"        ["add_time"]=>        string(10) "1395084115"      }    }    [94448]=>    array(2) {      ["weight"]=>      int(2)      ["attrs"]=>      array(3) {        ["from_id"]=>        string(1) "3"        ["link_id"]=>        string(1) "0"        ["add_time"]=>        string(10) "1395084124"      }    }    [99229]=>    array(2) {      ["weight"]=>      int(2)      ["attrs"]=>      array(3) {        ["from_id"]=>        string(1) "2"        ["link_id"]=>        string(7) "1297992"        ["add_time"]=>        string(10) "1395100520"      }    }    [107524]=>    array(2) {      ["weight"]=>      int(2)      ["attrs"]=>      array(3) {        ["from_id"]=>        string(1) "5"        ["link_id"]=>        string(10) "4294967295"        ["add_time"]=>        string(10) "1395122053"      }    }    [111918]=>    array(2) {      ["weight"]=>      int(2)      ["attrs"]=>      array(3) {        ["from_id"]=>        string(1) "5"        ["link_id"]=>        string(10) "4294967295"        ["add_time"]=>        string(10) "1395127953"      }    }    [148]=>    array(2) {      ["weight"]=>      int(1)      ["attrs"]=>      array(3) {        ["from_id"]=>        string(1) "2"        ["link_id"]=>        string(7) "2770294"        ["add_time"]=>        string(10) "1394852562"      }    }    [178]=>    array(2) {      ["weight"]=>      int(1)      ["attrs"]=>      array(3) {        ["from_id"]=>        string(1) "2"        ["link_id"]=>        string(7) "2474558"        ["add_time"]=>        string(10) "1394852579"      }    }    [595]=>    array(2) {      ["weight"]=>      int(1)      ["attrs"]=>      array(3) {        ["from_id"]=>        string(1) "2"        ["link_id"]=>        string(6) "534804"        ["add_time"]=>        string(10) "1394852862"      }    }    [775]=>    array(2) {      ["weight"]=>      int(1)      ["attrs"]=>      array(3) {        ["from_id"]=>        string(1) "2"        ["link_id"]=>        string(7) "3230353"        ["add_time"]=>        string(10) "1394852980"      }    }    [860]=>    array(2) {      ["weight"]=>      int(1)      ["attrs"]=>      array(3) {        ["from_id"]=>        string(1) "2"        ["link_id"]=>        string(7) "2549233"        ["add_time"]=>        string(10) "1394853048"      }    }    [938]=>    array(2) {      ["weight"]=>      int(1)      ["attrs"]=>      array(3) {        ["from_id"]=>        string(1) "2"        ["link_id"]=>        string(7) "3191382"        ["add_time"]=>        string(10) "1394853114"      }    }    [1048]=>    array(2) {      ["weight"]=>      int(1)      ["attrs"]=>      array(3) {        ["from_id"]=>        string(1) "2"        ["link_id"]=>        string(7) "3234645"        ["add_time"]=>        string(10) "1394853174"      }    }    [1395]=>    array(2) {      ["weight"]=>      int(1)      ["attrs"]=>      array(3) {        ["from_id"]=>        string(1) "2"        ["link_id"]=>        string(7) "2661219"        ["add_time"]=>        string(10) "1394853375"      }    }    [1657]=>    array(2) {      ["weight"]=>      int(1)      ["attrs"]=>      array(3) {        ["from_id"]=>        string(1) "2"        ["link_id"]=>        string(7) "2670624"        ["add_time"]=>        string(10) "1394853540"      }    }  }  ["total"]=>  int(543)  ["total_found"]=>  int(543)  ["time"]=>  float(0.109)  ["words"]=>  array(1) {    ["宝马"]=>    array(2) {      ["docs"]=>      int(543)      ["hits"]=>      int(741)    }  }}string(0) ""
登入後複製


本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

華為GT3 Pro和GT4的差異是什麼? 華為GT3 Pro和GT4的差異是什麼? Dec 29, 2023 pm 02:27 PM

許多用戶在選擇智慧型手錶的時候都會選擇的華為的品牌,其中華為GT3pro和GT4都是非常熱門的選擇,不少用戶都很好奇華為GT3pro和GT4有什麼區別,下面就給大家介紹一下二者。華為GT3pro和GT4有什麼差別一、外觀GT4:46mm和41mm,材質是玻璃鏡板+不鏽鋼機身+高分纖維後殼。 GT3pro:46.6mm和42.9mm,材質是藍寶石玻璃鏡+鈦金屬機身/陶瓷機身+陶瓷後殼二、健康GT4:採用最新的華為Truseen5.5+演算法,結果會更加的精準。 GT3pro:多了ECG心電圖和血管及安

使用java的String.valueOf()函數將基本資料型別轉換為字串 使用java的String.valueOf()函數將基本資料型別轉換為字串 Jul 24, 2023 pm 07:55 PM

使用Java的String.valueOf()函數將基本資料型別轉換為字串在Java開發中,當我們需要將基本資料型別轉換為字串時,常見的方法是使用String類別的valueOf()函數。這個函數可以接受基本資料類型的參數,並傳回對應的字串表示。在本文中,我們將探討如何使用String.valueOf()函數進行基本資料型別轉換,並提供一些程式碼範例來

怎麼把char數組轉string 怎麼把char數組轉string Jun 09, 2023 am 10:04 AM

char陣列轉string的方法:可以透過賦值來實現,使用{char a[]=" abc d\0efg ";string s=a;}語法,讓char陣列對string直接賦值,執行程式碼即可完成轉換。

修復:截圖工具在 Windows 11 中不起作用 修復:截圖工具在 Windows 11 中不起作用 Aug 24, 2023 am 09:48 AM

為什麼截圖工具在Windows11上不起作用了解問題的根本原因有助於找到正確的解決方案。以下是截圖工具可能無法正常工作的主要原因:對焦助手已開啟:這可以防止截圖工具開啟。應用程式損壞:如果截圖工具在啟動時崩潰,則可能已損壞。過時的圖形驅動程式:不相容的驅動程式可能會幹擾截圖工具。來自其他應用程式的干擾:其他正在運行的應用程式可能與截圖工具衝突。憑證已過期:升級過程中的錯誤可能會導致此issu簡單的解決方案這些適合大多數用戶,不需要任何特殊的技術知識。 1.更新視窗與Microsoft應用程式商店應用程

使用java的String.replace()函數替換字串中的字元(字串) 使用java的String.replace()函數替換字串中的字元(字串) Jul 25, 2023 pm 05:16 PM

使用Java的String.replace()函數替換字串中的字元(字串)在Java中,字串是不可變的對象,這意味著一旦創建了一個字串對象,就無法修改它的值。但是,你可能會遇到需要替換字串中的某些字元或字串的情況。這時候,我們可以使用Java的String類別中的replace()方法來實作字串的替換。 String類別的replace()方法有兩種重

2w字 詳解 String,yyds 2w字 詳解 String,yyds Aug 24, 2023 pm 03:56 PM

大家好,今天跟大家分享java基礎之String。 String類別的重要性就不必說了,可以說是我們後端開發用的最多的類,所以,很有必要好好聊聊它。

使用java的String.length()函數取得字串的長度 使用java的String.length()函數取得字串的長度 Jul 25, 2023 am 09:09 AM

使用Java的String.length()函數取得字串的長度在Java程式設計中,字串是一種非常常見的資料類型,我們經常需要取得字串的長度,即字串中字元的個數。在Java中,我們可以使用String類別的length()函數來取得字串的長度。下面是一個簡單的範例程式碼:publicclassStringLengthExample{publ

使用C#中的Array.Sort函數對陣列進行排序 使用C#中的Array.Sort函數對陣列進行排序 Nov 18, 2023 am 10:37 AM

標題:C#中使用Array.Sort函數對陣列進行排序的範例正文:在C#中,陣列是一種常用的資料結構,經常需要對陣列進行排序運算。 C#提供了Array類,其中有Sort方法可以方便地對陣列進行排序。本文將示範如何使用C#中的Array.Sort函數對陣列進行排序,並提供具體的程式碼範例。首先,我們要先了解Array.Sort函數的基本用法。 Array.So

See all articles