(jlive)[isfdb]>INSTALL SONAME 'ha_sphinx';
Query OK, 0 rows affected (0.01 sec)
(jlive)[isfdb]>SHOW storage engines;
+--------------------+---------+--------------------------------------------------------------------------------------------------+--------------+------+------------+
| Engine
+--------------------+---------+--------------------------------------------------------------------------------------------------+--------------+------+------------+
|
MRG_MyISAM
|
CSV
| Aria
| MyISAM
|
SPHINX
| MEMORY
| InnoDB
|
SEQUENCE
|
PERFORMANCE_SCHEMA | YES
| TokuDB
|
CONNECT
+--------------------+---------+--------------------------------------------------------------------------------------------------+--------------+------+------------+
11 rows in set (0.15 sec)
(jlive)[isfdb]>SHOW STATUS LIKE 'sphinx_%';
+--------------------+-------+
|
Variable_name
+--------------------+-------+
|
Sphinx_error
|
Sphinx_time
|
Sphinx_total
|
Sphinx_total_found |
|
Sphinx_word_count
|
Sphinx_words
+--------------------+-------+
6 rows in set (0.00 sec)
(jlive)[isfdb]>SHOW ENGINE SPHINX STATUS;
Empty set (0.15 sec)
安装Sphinx daemon
http://sphinxsearch.com/downloads/release/
wget
rpm -ivh sphinx-2.2.10-1.rhel7.x86_64.rpm
service searchd start
root@jlive:lnmp#rpm
-ivh sphinx-2.2.10-1.rhel7.x86_64.rpm
准备中...
正在升级/安装...
[/usr/lib/tmpfiles.d/searchd.conf:1] Unknown user 'sphinx'.
Sphinx installed!
Now create a full-text index, start the search daemon, and you're all set.
To manage indexes:
To rebuild all disk indexes:
To start/stop search daemon:
To query search daemon using MySQL client:
See the manual at /usr/share/doc/sphinx-2.2.10 for details.
For commercial support please contact Sphinx Technologies Inc at
http://sphinxsearch.com/contacts.html
root@jlive:lnmp#service
searchd start
Starting
searchd (via systemctl):
配置Sphinx
1.创建sphinx管理用户
CREATE USER 'sphinx'@localhost IDENTIFIED BY 'sphinxsecretpassword';
GRANT SELECT on test.* to 'sphinx'@localhost;
2.修改配置文件
cp /etc/sphinx/sphinx.conf{,.default}
source src1
{
}
... ...
root@jlive:lnmp#netstat -tunlp|grep searchd
tcp
tcp
提示: mariadb和sphinx可以在不同的主机上
使用searching
1.先创建示例表
USE test;
CREATE TABLE documents (
);
INSERT INTO documents VALUES
(1,UNIX_TIMESTAMP(date),'bash','Bash is an sh-compatible command
language interpreter that executes commands read from the standard
input or from a file.
(2,UNIX_TIMESTAMP(date),'sed',"Sed
(2,UNIX_TIMESTAMP(date),'awk',"Gawk
2.生成sphinx索引
root@jlive:~#/etc/init.d/searchd restart
Restarting searchd
(via systemctl):
root@jlive:~#indexer --rotate --all
Sphinx 2.2.10-id64-release (2c212e0)
Copyright (c) 2001-2015, Andrew Aksyonoff
Copyright (c) 2008-2015, Sphinx Technologies Inc (http://sphinxsearch.com)
using config file '/etc/sphinx/sphinx.conf'...
indexing index 'test1'...
collected 0 docs, 0.0 MB
total 0 docs, 0 bytes
total 0.005 sec, 0 bytes/sec, 0.00 docs/sec
skipping non-plain index 'testrt'...
total 1 reads, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg
total 7 writes, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg
rotating indices: successfully sent SIGHUP to searchd (pid=14641).
root@jlive:api#ls /var/lib/sphinx/
binlog.001
binlog.lock
binlog.meta
3.sphinx本地查询
search -q nosql
提示:sphinx-2.2.10没有search这个命令,有待进一步确认
4.SphinxSE接口查询
USE test;
CREATE TABLE documents_search (
SELECT *
FROM documents_search WHERE query='sphinx';
SELECT * FROM documents_search WHERE query='nosql';
停掉mariadb后直接连sphinx
service mysql stop
jlive@MacBook-Pro:~ $mysql -ujlive -p -h 192.168.130.254 -P 9306
Enter
password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome
to the MySQL monitor.
Your MySQL connection id is 1
Server version: 2.2.10-id64-release (2c212e0)
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.
(jlive)[isfdb]>SELECT * FROM test1 WHERE MATCH('bash');
Empty set (0.00 sec)
Sphinx API
http://sphinxsearch.com/docs/current.html#sphinxql-reference
http://sphinxsearch.com/blog/2013/07/23/from-api-to- sphinxql-and-back-again/
root@jlive:~#ls /usr/share/sphinx/api/
java/
lgpl-3.0.txt
libsphinxclient/
sphinxapi.pyc
ruby/