Lamp環境下安裝及使用coreseek

首先在你的linux上先下載一個coreseek的一個linux的安裝包 
博主給大家奉獻的下載地址:


打開linux首先安裝如下依賴包;(如果有的話只需要更新)

yum -y install m4 autoconf automake libtool

yum -y install gcc gcc-c++ wget

yum -y install mysql-devel
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

mmseg3是一箇中文分詞插件

執行如下命令:

tar xzvf coreseek-3.2.14.tar.gz                 //解壓命令

cd coreseek-3.2.14                              //進入目錄

cd mmseg-3.2.14/                                //進入中文分詞插件

./bootstrap                                 

./configure --prefix=/usr/local/mmseg3          //檢測配置

make   && make install                          //編譯 &&  編譯安裝


cd ../csft-3.2.14/                              //進入配置目錄

sh buildconf.sh                                 //執行腳本


./configure --prefix=/usr/local/coreseek --without-python --without-unixodbc --with-mmseg --with-mmseg-includes=/usr/local/mmseg3/include/mmseg/ --with-mmseg-libs=/usr/local/mmseg3/lib/ --with-mysql --host=arm                       
                                                 //檢測配置
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

安裝過程需要修改一個配置文件

vi src/sphinxexpr.cpp

//然後將所有的
    T val = ExprEval ( this->m_pArg, tMatch ).....
//修改爲
    T val = this->ExprEval ( this->m_pArg, tMatch )
//(建議大家將此文件拿到本地進行修改)
make
make install
cd /usr/local/coreseek/etc          //進入coreseek安裝完成的路徑

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

輸入ls會看到3個文件 
example.sql sphinx.conf.dist sphinx-min.conf.dist 
其中example.sql是示例sql腳本我們將其導入到數據庫中的test數據庫中作爲測試數據(會創建兩張表 documents和tags)

vi sphinx.conf

輸入以下內容:
source src1
{
    type                    = mysql
    sql_host                = 192.168.214.128
    sql_user                = root
    sql_pass                = root
    sql_db                  = test
    sql_port                = 3306  # optional, default is 3306
    sql_sock                = /tmp/mysql.sock
    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 test1
{
    source                  = src1
    path                    = /usr/local/coreseek/var/data/test1
    docinfo                 = extern
    charset_type            = zh_cn.utf-8
    mlock                   = 0
    morphology              = none
    min_word_len            = 1
    html_strip              = 0
    charset_dictpath        = /usr/local/mmseg3/etc/
    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
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52

說明: 
代碼段source src1{***} 代表數據源裏面主要包含了數據庫的配置信息,src1表示數據源名字,可以隨便寫。 
代碼段index test1{***} 代表爲哪個數據源創建索引,與source 是成對出現的,其中的source參數的值必須是某一個數據源的名字。 
其他參數可以查看手冊,這裏不再贅述。

生成索引

//其中參數--all表示生成所有索引
/usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/sphinx.conf --all
  • 1
  • 2

當然也可以是索引的名字例如

/usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/sphinx.conf test1
  • 1

執行後可以在/usr/local/coreseek/var/data目錄中看到多出一些文件,是以索引名爲文件名的不同的擴展名的文件

在不啓動sphinx的情況下即可測試命令:

/usr/local/coreseek/bin/search -c /usr/local/coreseek/etc/sphinx.conf number 
//(這是開啓sphinx的命令行搜索就是說 number是你要查詢的數據名稱)
  • 1
  • 2
/usr/local/coreseek/bin/searchd -c /usr/local/coreseek/etc/sphinx.conf
//(searchd是開啓sphinx的搜索服務功能)
  • 1
  • 2

Php操作linux上的sphinx

在站點域名目錄下創建一個文件列如test.php 
在test.php文件中寫入如下內容 
(注意與test同級需要將本身的sphinxapi類加載進來)

<?php
    header("content-type:text/html;charset=utf8");
    include'./sphinxapi.php';
    $sphinx= new SphinxClient();
    $sphinx->SetServer('你linux上的ip地址',9312);
    $res=$sphinx->Query("搜索字段","*");  //這裏的*代表匹配所有定義好的規則
    print_r($res);
?>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章