Sphinx 在 Linux 下的安裝與基本配置

2021-07-22 11:38:26 字數 2927 閱讀 8169

sphinx 官網:

wget files/sphinx-2.2.10-release.tar.gz

解壓壓縮包

tar zxvf sphinx-2.2.10-release.tar.gz

cd sphinx-2.2.10-release

找到 mysql 的安裝目錄,我的是在 /usr/bin/mysql 執行 /usr/lcoal/sphinx 為 sphinx 的安裝目錄。

sudo ./configure --prefix=/usr/local/sphinx --with-mysql=/usr/local/mysql

make

make install

不出問題的話應該已經安裝成功了

其他引數的配置

--with-mysql-includes=/usr/local/mysql/include/mysql/

--with-mysql-libs=/usr/local/mysql/lib/mysql/

--with-mmseg=/usr/local/mmseg/

--with-mmseg-includes=/usr/local/mmseg/include/mmseg/

--with-mmseg-libs=/usr/local/mmseg/lib/

找到 sphinx 的安裝目錄 /usr/local/sphinx/etc .複製乙份 sphinx.conf.dist 為 test.conf

開啟檔案對照注釋編寫配置檔案。由於都是英文,這裡將經常用到的一些配置做解釋如下:

資料來源配置解析:

source 

; #-----------------------------sql 相關配置--------------------------------------------

# sql某一列的緩衝大小,一般是針對字串來說的

# sql_column_buffers = content=12m, comments=1m

# 索引的 sql 執行前需要執行的操作,比如設定字串為 utf8

sql_query_pre = set names utf8

# 索引的 sql 執行語句

sql_query = select id, name, age from test

# 聯合查詢

# sql_joined_field是增加乙個字段,這個字段是從其他表查詢中查詢出來的。

# 如果是query,則返回id和查詢字段,如果是payload-query,則返回id,查詢欄位和權重

# 查詢需要按照id進行公升序排列

# sql_joined_field = tags from query; select docid, concat('tag',tagid) from tags order by docid asc

# sql_joined_field = wtags from payload-query; select docid, tag, tagweight from tags order by docid asc

#----------------------------欄位屬性的配置(用於過濾和排序)----------------------------------------

# uint無符號整型屬性

sql_attr_uint = id

# 布林值屬性

# sql_attr_bool = is_deleted

# 長整型屬性(有負數用 bigint)

# sql_attr_bigint = my_bigint_id

# 時間戳屬性,經常被用於做排序

sql_attr_timestamp = date_added

# 字串排序屬性。一般我們按照字串排序的話,我們會將這個字串存下來進入到索引中,然後在查詢的時候比較索引中得字元大小進行排序。

# 但是這個時候索引就會很大,於是我們就想到了乙個方法,我們在建立索引的時候,先將字串值從資料庫中取出,暫存,排序。

# 然後給排序後的陣列分配乙個序號,然後在建立索引的時候,就將這個序號存入到索引中去。這樣在查詢的時候也就能完成字串排序的操作。

# 這,就是這個欄位的意義。

# sql_attr_str2ordinal = author_name

# 浮點數屬性

# sql_attr_float = lat_radians

# sql_attr_float = long_radians

# 字串屬性

# sql_attr_string = stitle

# 文件詞彙數記錄屬性。比如下面就是在索引建立的時候增加乙個詞彙數的字段

# sql_attr_str2wordcount = stitle

} # sphinx 的 source 有繼承屬性,也就是說共有的部分可以寫在父級資料來源中,比如資料庫連線配置資訊

source main_0: main

索引配置解析:

index test1

搜尋服務searchd 配置

searchd

生成索引

/usr/local/sphinx/bin/indexer --config /usr/local/sphinx/etc/test.conf --all

開啟 sphinx 程序

/usr/local/sphinx/bin/searchd --config /usr/local/sphinx/etc/sphinx.conf

Sphinx在Windows下的安裝

sphinx在windows下的安裝 僅供小師弟們以後參考 sphinx的中文參考 sphinx是 乙個基於sql的全文檢索引擎,可以結合mysql,postgresql做全文搜尋,它可以提供比資料庫本身更專業的搜尋功能,使得應用程式更容易實現 專業化的全文檢索。sphinx特別為一些指令碼語言設計...

在ubuntu 下安裝sphinx

在ubuntu 下安裝sphinx 安裝包下的doc不準確。這篇文章寫的很好。為保持索引及時更新,在crontab中加入,每小時執行一次索引更新 hourly usr bin indexer rotate config etc sphinxsearch sphinx.conf all 執行 sear...

EDirect在linux和mac下的安裝

edirect是非常有用的工具 其使用要用來perl,mac都預先安裝了perl 安裝的時候最好按下面進行 開啟終端 cd bin bash perl mnet ftp e ftp new net ftp ftp.ncbi.nlm.nih.gov passive 1 ftp login ftp bi...