SphinxとCoreseekのインストール構成


今回使用するLinuxリリース版はCentOS 6.5,coreseekバージョン4.1
SphinxはSQLベースの全文検索エンジンで、MySQL、PostgreSQLと組み合わせて全文検索を行うことができ、データベース自体よりも専門的な検索機能を提供することができ、アプリケーションが専門的な全文検索を実現しやすい.Sphinxは特に、PHP、Python、Perl、Rubyなどのスクリプト言語の検索APIインタフェースを設計し、MySQLにもストレージエンジンプラグインを設計しています.
Sphinxの主な特性は次のとおりです.
高速インデックス(新しいCPUでは、10 MB/秒近く);高速検索(2-4 Gのテキスト量の平均クエリー速度は0.1秒未満).高可用性(単一CPUで最大100 GBのテキスト、100 Mドキュメントをサポート可能);良好な相関順位を提供し、分散検索をサポートする.ドキュメントのサマリー生成を提供します.MySQL内部のプラグインストレージエンジンからブール、フレーズ、類義語クエリーをサポートする検索を提供します.各ドキュメントの複数の全文検索ドメイン(デフォルトは最大32個)をサポートします.各ドキュメントのマルチプロパティをサポートします.断詞を支持する.シングルバイト符号化とUTF-8符号化をサポートする.
coreseekはsphinxオープンソースに基づく検索エンジンで、ユーザーに無料の中国語全文検索システムを提供し、coreseekは中国語の分詞を持つsphinxと呼ばれ、sphinxとは異なりcoreseekが中国語の分司を持つ辞書を追加した.
そこで今回はcoreseek 4を直接インストール.1バージョンは、Sphinxソースコードが内蔵されているためです.
一、Coreseek取付
1、mmsegを取り付ける
[root@test3 ~]# tar xf coreseek-4.1-beta.tar.gz -C /usr/src
[root@test3 ~]# cd /usr/src/coreseek-4.1-beta
[root@test3 coreseek-4.1-beta]# ls
csft-4.1  mmseg-3.2.14  README.txt  testpack        
#   csft-4.1 sphinx  ,mmseg        

[root@test3 coreseek-4.1-beta]# cd mmseg-3.2.14
[root@test3 mmseg-3.2.14]# ./bootstrap         #        
[root@test3 mmseg-3.2.14]# ./configure --prefix=/usr/local/mmseg3
[root@test3 mmseg-3.2.14]# make && make install

2、Coreseek(Sphinx)の取り付け
[root@test3 mmseg-3.2.14]# cd ../csft-4.1/
[root@test3 coreseek-4.1-beta]# ./buildconf.sh  #          
[root@test3 coreseek-4.1-beta]# ./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
[root@test3 coreseek-4.1-beta]# make && make install

二、Coreseekの配置
[root@test3 csft-4.1]# cd /usr/local/coreseek/
[root@test3 coreseek]# ls
bin  etc  share  var
[root@test3 coreseek]# cd etc/ && ll
-rw-r--r--. 1 root root   903 Jul 28 10:08 example.sql           #      
-rw-r--r--. 1 root root 31081 Jul 28 09:25 sphinx.conf.dist      #       
-rw-r--r--. 1 root root  1163 Jun 12 00:40 sphinx-min.conf.dist  #        

#  mysql     test   , example.sql  
[root@test3 etc]# mysql -uroot -ppasswd -e 'create database test2;'
[root@test3 etc]# mysql -uroot -ppasswd  
  


、 Coreseek,

[root@test3 etc]# /usr/local/coreseek/bin/searchd  -c csft.conf    #     
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 'sphinx-min.conf.dist'...
WARNING: compat_sphinxql_magics=1 is deprecated; please update your application and config
 listening on all interfaces, port=9312
listening on all interfaces, port=9306
 precaching index 'test1'
precaching index 'testrt'                                   
precached 2 indexes in 0.001 sec
[root@test3 etc]# ss -tnl | grep -e 9306 -e 9312                   #      
LISTEN     0      5                         *:9306                     *:*     
LISTEN     0      5                         *:9312                     *:*    

#   
[root@test3 etc]# /usr/local/coreseek/bin/indexer --all --rotate   #     
[root@test3 etc]# /usr/local/coreseek/bin/search test              #   test   
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 '/usr/local/coreseek/etc/csft.conf'...
index 'test1': query 'test ': returned 3 matches of 3 total in 0.000 sec

displaying matches:
1. document=1, weight=2421, group_id=1, date_added=Thu Jul 28 13:39:05 2016
	id=1
	group_id=1
	group_id2=5
	date_added=2016-07-28 13:39:05
	title=test one
	content=this is my test document number one. also checking search within phrases.
2. document=2, weight=2421, group_id=1, date_added=Thu Jul 28 13:39:05 2016
	id=2
	group_id=1
	group_id2=6
	date_added=2016-07-28 13:39:05
	title=test two
	content=this is my test document number two
3. document=4, weight=1442, group_id=2, date_added=Thu Jul 28 13:39:05 2016
	id=4
	group_id=2
	group_id2=8
	date_added=2016-07-28 13:39:05
	title=doc number four
	content=this is to test groups

words:
1. 'test': 3 documents, 5 hits

index 'testrt': search error: failed to open /usr/local/coreseek/var/data/testrt.sph: No such file or directory.

、 ファイルを し、マルチテーブル を する
[root@test3 etc]# vim csft.conf
#
# Minimal Sphinx configuration sample (clean, simple, functional)
#

source host
{
	type			= mysql

	sql_host		= localhost
	sql_user		= root 
	sql_pass		= passwd
	sql_db			= test
	sql_port		= 3306	# optional, default is 3306
}

source src1:host
{
	sql_query		= \
		SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content \
		FROM documents
	sql_joined_field  = tags from query; SELECT id, name FROM tags ORDER BY id ASC

	sql_attr_uint		= group_id
	sql_attr_timestamp	= date_added

	sql_query_info		= SELECT * FROM documents WHERE id=$id
}

source src2:host
{
	sql_query  = SELECT id,name,docid,tagid FROM tags ORDER BY tagid ASC

	sql_attr_uint		= id


	sql_query_info		= SELECT * FROM tags WHERE id=$id
}

index test1
{
	source			= src1
	path			= /usr/local/coreseek/var/data/test1
	docinfo			= extern
	charset_dictpath	= /usr/local/mmseg3/etc/
	charset_type      	= zh_cn.utf-8
}

index test2
{
	source			= src2
	path			= /usr/local/coreseek/var/data/test2
	docinfo			= extern
	charset_dictpath	= /usr/local/mmseg3/etc/
	charset_type      	= zh_cn.utf-8
}

index testrt
{
	type			= rt
	rt_mem_limit		= 32M

	path			= /usr/local/coreseek/var/data/testrt
	charset_type		= utf-8

	rt_field		= title
	rt_field		= content
	rt_attr_uint		= gid
}


indexer
{
	mem_limit		= 32M
}


searchd
{
	listen			= 9312
	listen			= 9306:mysql41
	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		= 1
	unlink_old		= 1
	workers			= threads # for RT to work
}

データベース
mysql> select * from tags;
+----+------------------+
| id | content          |
+----+------------------+
|  1 | test one time    |
|  2 | test two times   |
|  3 | test three times |
|  4 | test four times  |
+----+------------------+
4 rows in set (0.00 sec)

mysql> select * from documents;
+----+----------+-----------+---------------------+-----------------+-----------------------+
| id | group_id | group_id2 | date_added          | title           | content               |
+----+----------+-----------+---------------------+-----------------+-----------------------+
|  1 |        1 |         5 | 2016-07-28 13:57:00 | test one        |         |
|  2 |        1 |         6 | 2016-07-28 13:57:00 | test two        |         |
|  3 |        2 |         7 | 2016-07-28 13:57:00 | another doc     |             |
|  4 |        2 |         8 | 2016-07-28 13:57:00 | doc number four |                 |
+----+----------+-----------+---------------------+-----------------+-----------------------+
4 rows in set (0.00 sec)

クエリ
[root@test3 etc]# /usr/local/coreseek/bin/search test
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 '/usr/local/coreseek/etc/csft.conf'...
index 'test1': query 'test ': returned 4 matches of 4 total in 0.000 sec

displaying matches:
1. document=1, weight=2230, group_id=1, date_added=Thu Jul 28 13:57:00 2016
	id=1
	group_id=1
	group_id2=5
	date_added=2016-07-28 13:57:00
	title=test one
	content=       
2. document=2, weight=2230, group_id=1, date_added=Thu Jul 28 13:57:00 2016
	id=2
	group_id=1
	group_id2=6
	date_added=2016-07-28 13:57:00
	title=test two
	content=       
3. document=3, weight=1304, group_id=2, date_added=Thu Jul 28 13:57:00 2016
	id=3
	group_id=2
	group_id2=7
	date_added=2016-07-28 13:57:00
	title=another doc
	content=     
4. document=4, weight=1304, group_id=2, date_added=Thu Jul 28 13:57:00 2016
	id=4
	group_id=2
	group_id2=8
	date_added=2016-07-28 13:57:00
	title=doc number four
	content=   

words:
1. 'test': 4 documents, 6 hits

index 'testrt': search error: failed to open /usr/local/coreseek/var/data/testrt.sph: No such file or directory.