日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

Sphinx+MySQL5.1x+SphinxSE+mmseg

發(fā)布時間:2025/3/8 数据库 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Sphinx+MySQL5.1x+SphinxSE+mmseg 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.


一.不停止mysql的情況下安裝SphinxSE

1.確定mysql版本,下載對應源碼包

此處下載5.1.69的mysql源碼包

#wget ftp://ftp.ntu.edu.tw/pub/MySQL/Downloads/MySQL-5.1/mysql-5.1.69.tar.gz?

解壓


2.下載sphinx:

#wget http://sphinxsearch.com/downloads/sphinx-0.9.9.tar.gz?

解壓


3.拷貝mysqlse到mysql5.1.69下的storage/sphinx

#cp -r sphinx-0.9.9/mysqlse/ mysql-5.1.69/storage/sphinx


4.編譯

#cd mysql-5.1.69

#sh BUILD/autorun.sh

#./configure

#make


5.mysql插入sphinx引擎

#cd ./mysql-5.1.69

#cd ./storage/sphinx/.libs

#cp ha_sphinx.* /usr/lib64/mysql/plugin


更改所有者

#chown mysql.mysql /usr/lib64/mysql/plugin/*


登錄mysql,插入引擎

#mysql -u root -p -h localhost?

#mysql> INSTALL PLUGIN sphinx SONAME 'ha_sphinx.so';


檢查引擎是否安裝

#mysql> show engines;


如果出現(xiàn)sphinx引擎,則表明已正常安裝


二.安裝Coreseek,使其支持中文索引及檢索

1.安裝autoconf


2.下載coreseek3.2.14.tar.gz,并解壓縮


3.安裝mmseg分詞

#cd coreseek-3.2.14

#./bootstrap

#./configure --prefix=/usr/local/mmseg3

#make

#make install


4.安裝csft

#cd ../csft-3.2.14/

#sh buildconf.sh

#./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


===========================================================

##如果出現(xiàn)錯誤提示:“ERROR: cannot find MySQL include files.......To disable MySQL support, use --without-mysql option.“,可按照如下方法處理:

##請找到頭文件mysql.h所在的目錄,一般是/usr/local/mysql/include,請?zhí)鎿Q為實際的

##請找到庫文件libmysqlclient.a所在的目錄,一般是/usr/local/mysql/lib,請?zhí)鎿Q為實際的

##configure參數(shù)加上:--with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/mysql/lib,執(zhí)行后,重新編譯安裝

============================================================


#make

#make install


三.配置并測試

1.進入coreseek目錄

#cd /usr/local/coreseek/etc

#ls

可以看到三個文件

example.sql ?sphinx.conf.dist ?sphinx-min.conf.dist


#cp sphinx.conf.dist sphinx.conf


2.配置sphinx.conf

source src1

{


? ? ?type ? ? ? ? ? ? ? ? ? = mysql


? ? ?sql_host ? ? ? ? ? ? ? = localhost


? ? ?sql_user ? ? ? ? ? ? ? = root


? ? ?sql_pass ? ? ? ? ? ? ? = 123456


? ? ?sql_db ? ? ? ? ? ? ? ? = test


? ? ?sql_port ? ? ? ? ? ? ? = 3306 ? # optional, default is 3306


? ? ?sql_sock ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?= /var/lib/mysql/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


}



3.創(chuàng)建test數(shù)據(jù)庫,并建立表documents,sql語句如下


DROP TABLE IF EXISTS test.documents;


CREATE TABLE test.documents

(

? ? ? ? id ? ? ? ? ? ? ? ? ? ? ?INTEGER PRIMARY KEY NOT NULL AUTO_INCREMENT,

? ? ? ? group_id ? ? ? ?INTEGER NOT NULL,

? ? ? ? group_id2 ? ? ? INTEGER NOT NULL,

? ? ? ? date_added ? ? ?DATETIME NOT NULL,

? ? ? ? title ? ? ? ? ? VARCHAR(255) NOT NULL,

? ? ? ? content ? ? ? ? TEXT NOT NULL

);


REPLACE INTO test.documents ( id, group_id, group_id2, date_added, title, content ) VALUES

? ? ? ? ( 1, 1, 5, NOW(), 'test one', 'this is my test document number one. also checking search within phrases.' ),

? ? ? ? ( 2, 1, 6, NOW(), 'test two', 'this is my test document number two' ),

? ? ? ? ( 3, 2, 7, NOW(), 'another doc', 'this is another group' ),

? ? ? ? ( 4, 2, 8, NOW(), 'doc number four', 'this is to test groups' );


DROP TABLE IF EXISTS test.tags;


CREATE TABLE test.tags

(

? ? ? ? docid INTEGER NOT NULL,

? ? ? ? tagid INTEGER NOT NULL,

? ? ? ? UNIQUE(docid,tagid)

);


INSERT INTO test.tags VALUES

? ? ? ? (1,1), (1,3), (1,5), (1,7),

? ? ? ? (2,6), (2,4), (2,2),

? ? ? ? (3,15),

? ? ? ? (4,7), (4,40);



4.生成索引

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

其中參數(shù)--all表示生成所有索引


當然也可以是索引的名字例如:#/usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/sphinx.conf test1

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


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


#/usr/local/coreseek/bin/search -c /usr/local/coreseek/etc/sphinx.conf number

?

#/usr/local/coreseek/bin/search -c /usr/local/coreseek/etc/sphinx.conf number --filter group_id 2


限定group_id 為2 返回一條記錄


我們插入幾條數(shù)據(jù)來測試中文

set names utf8 ?之前一定要設置字符集


INSERT INTO `test`.`documents` (


`id` ,


`group_id` ,


`group_id2` ,


`date_added` ,


`title` ,


`content`


)


VALUES (


NULL , '2', '3', '2011-02-01 00:37:12', '研究生的故事', '研究生自主創(chuàng)業(yè)'


), (


NULL , '1', '1', '2011-01-28 00:38:22', '研究', '為了創(chuàng)業(yè)而研究生命科學'


);


插入數(shù)據(jù)后需要重新索引

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


進行測試

#/usr/local/coreseek/bin/search -c /usr/local/coreseek/etc/sphinx.conf 研究生創(chuàng)業(yè)




四.實際使用

1.作為守護進程啟動

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


2.建立一個sphinx引擎的表

CREATE TABLE t1


(


? ? id ? ? ? ? ?INTEGER UNSIGNED NOT NULL,


? ? weight ? ? ?INTEGER NOT NULL,


? ? query ? ? ? VARCHAR(3072) NOT NULL,


? ? group_id ? ?INTEGER,


? ? INDEX(query)


) ENGINE=SPHINX CONNECTION="sphinx://localhost:9312/test1";


搜索表前三列的類型必須是INTEGER,INTEGER和VARCHAR,這三列分別對應文檔ID,匹配權值和搜索查詢。查詢列必須被索引,其他列必須無索引。列的名字會被忽略,所以可以任意命名,參數(shù)CONNECTION來指定用這個表搜索時的默認搜索主機、端口號和索引,語法格式:CONNECTION="sphinx://HOST:PORT/INDEXNAME"。


執(zhí)行SQL語句 select d.id,d.title,d.content from t1 join documents as d on t1.id = d.id and t1.query = '研究生創(chuàng)業(yè)';


即可查詢結果


3.在不停止searchd的情況下主索引

插入數(shù)據(jù)后創(chuàng)建主索引

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


對于實際應用,應該是主索引+增量索引





轉(zhuǎn)載于:https://www.cnblogs.com/itfenqing/p/4429417.html

總結

以上是生活随笔為你收集整理的Sphinx+MySQL5.1x+SphinxSE+mmseg的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。