ubuntu下编译安装sphinx

1、下载
sphinx-2.0.6-release.tar.gz
2、安装

sudo apt-get install build-essential libmysqlclient-dev;
tar -xvf sphinx-2.0.6-release.tar.gz;
cd sphinx-2.0.6-release;
./configure;
make;
sudo make install;

3、创建数据库demo

CREATE DATABASE `indexer`;
USE indexer;
DROP TABLE IF EXISTS documents;
CREATE TABLE 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 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' );

4、创建/usr/local/etc/sphinx.conf

#
# Minimal Sphinx configuration sample (clean, simple, functional)
#
 
source src1
{
	type			= mysql
 
	sql_host		= 192.168.1.88
	sql_user		= root
	sql_pass		= 123456
	sql_db			= indexer
	sql_port		= 3306	# optional, default is 3306
 
	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			= /var/data/test1
	docinfo			= extern
	charset_type		= sbcs
}
 
 
index testrt
{
	type			= rt
	rt_mem_limit		= 32M
 
	path			= /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			= /var/log/searchd.log
	query_log		= /var/log/query.log
	read_timeout		= 5
	max_children		= 30
	pid_file		= /var/log/searchd.pid
	max_matches		= 1000
	seamless_rotate		= 1
	preopen_indexes		= 1
	unlink_old		= 1
	workers			= threads # for RT to work
	binlog_path		= /var/data
}

6、创建索引

sudo mkdir /var/data;
sudo indexer --all;

7、启动查询服务器

sudo searchd;

8、用python的api测试查询

cd sphinx-2.0.6-release/api;
python test.py test

原创文章,转载请注明: 转载自海波无痕

本文链接地址: ubuntu下编译安装sphinx

文章的脚注信息由WordPress的wp-posturl插件自动生成

此条目发表在server分类目录,贴了, , 标签。将固定链接加入收藏夹。

发表评论

电子邮件地址不会被公开。 必填项已用*标注

评论链接可以 移除 nofollow.