本文只记录了一些安装和部分功能的操作,详细的参数说明和工具使用手册请见官方:
http://www.coreseek.cn/docs/coreseek_4.1-sphinx_2.0.1-beta.html
MySQL安装
http://www.coreseek.cn/docs/coreseek_4.1-sphinx_2.0.1-beta.html
MySQL安装
[
root@59-Mysql-Test ~]# unzip mysql-5.5.46.zip
[
root@59-Mysql-Test ~]# cd mysql-5.5.46
[
root@59-Mysql-Test mysql-5.5.46]# cd cmake/
[
root@59-Mysql-Test cmake]# chmod +x configure.pl
[
root@59-Mysql-Test cmake]# ./configure.pl
[
root@59-Mysql-Test cmake]# make && make install
配置/etc/my.cnf
[
root@59-Mysql-Test cmake]# cd /usr/local/mysql/
[ root@59-Mysql-Test mysql]# cp scripts/mysql_install_db .
[ root@59-Mysql-Test mysql]# ./mysql_install_db
[ root@59-Mysql-Test mysql]# cp scripts/mysql_install_db .
[ root@59-Mysql-Test mysql]# ./mysql_install_db
[
root@59-Mysql-Test mysql]# service mysql start
Starting MySQL.....[ OK ]
[ root@59-Mysql-Test mysql]# /usr/local/mysql/bin/mysqladmin -u root password 'password'
Starting MySQL.....[ OK ]
[ root@59-Mysql-Test mysql]# /usr/local/mysql/bin/mysqladmin -u root password 'password'
[
root@59-Mysql-Test mysql]# /usr/local/mysql/bin/mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.46-log Source distribution
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.46-log Source distribution
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
配置sphinxSE数据库存储引擎
[
root@59-Mysql-Test ~]# tar zxvf coreseek-4.1-beta.tar.gz
[
root@59-Mysql-Test ~]# cd coreseek-4.1-beta
[
root@59-Mysql-Test coreseek-4.1-beta]# cp csft-4.1/mysqlse/ ~/mysql-5.5.46/storage/sphinx -r
[
root@59-Mysql-Test coreseek-4.1-beta]# cd ~/mysql-5.5.46
[ root@59-Mysql-Test mysql-5.5.46]# cmake . -DCMAKE_BUILD_TYPE=Release -DWITH_SPHINX_STORAGE_ENGINE=1
[ root@59-Mysql-Test mysql-5.5.46]# cmake . -DCMAKE_BUILD_TYPE=Release -DWITH_SPHINX_STORAGE_ENGINE=1
[
root@59-Mysql-Test mysql-5.5.46]# make
[
root@59-Mysql-Test mysql-5.5.46]# cp storage/sphinx/ha_sphinx.so /usr/local/mysql/lib/plugin/
[
root@59-Mysql-Test mysql-5.5.46]# chown mysql.mysql /usr/local/mysql/lib/plugin/ha_sphinx.so
mysql> INSTALL PLUGIN sphinx SONAME 'ha_sphinx.so';
Query OK, 0 rows affected (0.19 sec)
mysql> show engines;
+--------------------+---------+------------------------------------------------------------+--------------+------+------------+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+--------------------+---------+------------------------------------------------------------+--------------+------+------------+
| CSV | YES | CSV storage engine | NO | NO | NO |
| PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO |
| MyISAM | YES | MyISAM storage engine | NO | NO | NO |
| InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
|
SPHINX | YES | Sphinx storage engine 2.0.2-dev ($Revision: 2917) | NO | NO | NO |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
+--------------------+---------+------------------------------------------------------------+--------------+------+------------+
7 rows in set (0.00 sec)
安装配置coreseek
[
root@59-Mysql-Test ~]# cd coreseek-4.1-beta
[
root@59-Mysql-Test coreseek-4.1-beta]# cd mmseg-3.2.14/
[
root@59-Mysql-Test mmseg-3.2.14]# ./configure --prefix=/usr/local/mmseg
[
root@59-Mysql-Test mmseg-3.2.14]# make && make install
[
root@59-Mysql-Test mmseg-3.2.14]# cd ../csft-4.1/
[
root@59-Mysql-Test csft-4.1]# sh buildconf.sh
[
root@59-Mysql-Test csft-4.1]# ./configure --prefix=/usr/local/coreseek --without-unixodbc --with-mmseg --with-mmseg-includes=/usr/local/mmseg/include/mmseg/ --with-mmseg-libs=/usr/local/mmseg/lib/ --with-mysql
[
root@59-Mysql-Test csft-4.1]# make && make install
导入测试数据
[
root@59-Mysql-Test ~]# /usr/local/mysql/bin/mysql -u root -p < ~/coreseek-4.1-beta/csft-4.1/example.sql
配置coreseek
[
root@59-Mysql-Test ~]# vi /usr/local/coreseek/etc/csft.conf
source src1
{
type = mysql
sql_host = localhost
sql_user = root
sql_pass = password
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 = iSELECT * 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/mmseg/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
}
构建索引
[
root@59-Mysql-Test ~]# /usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft.conf --all
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'...
indexing index 'test1'...
collected 4 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 4 docs, 193 bytes
total 0.021 sec, 8926 bytes/sec, 184.99 docs/sec
total 3 reads, 0.000 sec, 0.1 kb/call avg, 0.0 msec/call avg
total 9 writes, 0.001 sec, 0.1 kb/call avg, 0.1 msec/call avg
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'...
indexing index 'test1'...
collected 4 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 4 docs, 193 bytes
total 0.021 sec, 8926 bytes/sec, 184.99 docs/sec
total 3 reads, 0.000 sec, 0.1 kb/call avg, 0.0 msec/call avg
total 9 writes, 0.001 sec, 0.1 kb/call avg, 0.1 msec/call avg
测试
[
root@59-Mysql-Test ~]# /usr/local/coreseek/bin/search -c /usr/local/coreseek/etc/csft.conf number
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 'number ': returned 3 matches of 3 total in 0.000 sec
displaying matches:
1. document=1, weight=1442, group_id=1, date_added=Wed Nov 25 11:20:27 2015
id=1
group_id=1
group_id2=5
date_added=2015-11-25 11:20:27
title=test one
content=this is my test document number one. also checking search within phrases.
2. document=2, weight=1442, group_id=1, date_added=Wed Nov 25 11:20:27 2015
id=2
group_id=1
group_id2=6
date_added=2015-11-25 11:20:27
title=test two
content=this is my test document number two
3. document=4, weight=1442, group_id=2, date_added=Wed Nov 25 11:20:27 2015
id=4
group_id=2
group_id2=8
date_added=2015-11-25 11:20:27
title=doc number four
content=this is to test groups
words:
1. 'number': 3 documents, 3 hits
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 'number ': returned 3 matches of 3 total in 0.000 sec
displaying matches:
1. document=1, weight=1442, group_id=1, date_added=Wed Nov 25 11:20:27 2015
id=1
group_id=1
group_id2=5
date_added=2015-11-25 11:20:27
title=test one
content=this is my test document number one. also checking search within phrases.
2. document=2, weight=1442, group_id=1, date_added=Wed Nov 25 11:20:27 2015
id=2
group_id=1
group_id2=6
date_added=2015-11-25 11:20:27
title=test two
content=this is my test document number two
3. document=4, weight=1442, group_id=2, date_added=Wed Nov 25 11:20:27 2015
id=4
group_id=2
group_id2=8
date_added=2015-11-25 11:20:27
title=doc number four
content=this is to test groups
words:
1. 'number': 3 documents, 3 hits
插入中文测试数据
INSERT INTO test.`documents` VALUES
(NULL,3,5,NOW(),'MySQL 学习','学习MySQL的全文索引'),
(NULL,4,6,NOW(),'中国','中华人民共和国'),
(NULL,5,7,NOW(),'今天比较冷','今天零下好几度'),
(NULL,6,8,NOW(),'故乡','故乡在哪里'),
(NULL,7,9,NOW(),'你好','同志们大家好');
创建表t1 作为索引表
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://127.0.0.1:9312/test1";
mysql> SELECT d.id,d.title,d.content FROM t1 JOIN documents AS d ON t1.id = d.id AND t1.query = '故乡';
+----+--------+-----------------+
| id | title | content |
+----+--------+-----------------+
| 8 | 故乡 | 故乡在哪里 |
+----+--------+-----------------+
1 row in set (0.01 sec)
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29320885/viewspace-1846278/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29320885/viewspace-1846278/