(jlive)[isfdb]>INSTALL SONAME 'ha_sphinx';php
Query OK, 0 rows affected (0.01 sec)html
(jlive)[isfdb]>SHOW storage engines;java
+--------------------+---------+--------------------------------------------------------------------------------------------------+--------------+------+------------+mysql
| Engine
+--------------------+---------+--------------------------------------------------------------------------------------------------+--------------+------+------------+shell
| 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/ sphinxapi.pyo test2.pyo test.pyo