如果你想开始学习 Manticore Search 的普通索引或查看某些功能如何运作,以下是最简单的 Manticoresearch 配置可能会有所帮助:
source min {
type = mysql
sql_host = localhost
sql_user = root
sql_pass =
sql_db = test
sql_query = select 1, 'cat' union select 2, 'dog'
}
index idx_min {
path = idx
source = min
}
searchd {
listen = 9306:mysql41
log = searchd.log
pid_file = manticoresearch.pid
binlog_path =
}
它几乎什么都没有,但只包含 Manticoresearch 无法正常运行所必需的要素。这些是:
"source" 部分用于从 mysql 获取数据。在这种情况下,我们甚至不从 mysql 获取真实数据,而是仅使用 mysql 接口,数据直接在配置中定义("select 1, ‘cat’ union select 2, ‘dog'")。它将在 Manticoresearch 中创建 2 个文档:一个包含单词 "cat",另一个包含单词 "dog",它们的 ID 分别为 1 和 2。
"index" 部分用于根据上述 source 创建索引,它仅包含对 source 的引用("source = min")和索引路径("path = idx")。一旦你构建这个索引,文件 idx.* 将在你启动 'indexer' 的目录中创建。
"searchd" 部分用于告诉 Manticoresearch 它应该监听哪些端口("listen = 9306:mysql41" 表示应使用 SphinxQL 通过此端口与 Manticoresearch 通信),应使用什么日志("log = searchd.log")以及应保存其进程 ID 的位置("pid_file = manticoresearch.pid")。
以下是使用此配置的示例:
索引:
[snikolaev@dev01 ~]$ indexer -c min.conf --all
Manticore 2.6.1 9a706b4@180119 dev
Copyright (c) 2001-2016, Andrew Aksyonoff
Copyright (c) 2008-2016, Sphinx Technologies Inc (http://sphinxsearch.com)
Copyright (c) 2017-2018, Manticore Software LTD (http://manticoresearch.com)
using config file 'min.conf'...
indexing index 'idx_min'...
WARNING: Attribute count is 0: switching to none docinfo
collected 2 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 2 docs, 6 bytes
total 0.045 sec, 131 bytes/sec, 43.75 docs/sec
total 3 reads, 0.000 sec, 10.6 kb/call avg, 0.0 msec/call avg
total 9 writes, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg
启动 'searchd' 并使用 mysql 客户端获取结果:
[snikolaev@dev01 ~]$ searchd -c min.conf
Manticore 2.6.2 df9dc57@180213 dev
Copyright (c) 2001-2016, Andrew Aksyonoff
Copyright (c) 2008-2016, Sphinx Technologies Inc (http://sphinxsearch.com)
Copyright (c) 2017-2018, Manticore Software LTD (http://manticoresearch.com)
using config file 'min.conf'...
listening on all interfaces, port=9306
precaching index 'idx_min'
precached 1 indexes in 0.001 sec
[snikolaev@dev01 ~]$ mysql -P9306 -h0
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 2.6.2 df9dc57@180213 dev
Copyright (c) 2009-2017 Percona LLC and/or its affiliates
Copyright (c) 2000, 2017, 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> select * from idx_min where match('dog');
+------+
| id |
+------+
| 2 |
+------+
1 row in set (0.00 sec)
mysql> select * from idx_min where match('cat');
+------+
| id |
+------+
| 1 |
+------+
1 row in set (0.00 sec)
当 searchd 正在运行时,如果你想重建索引,可以在不停止 searchd 的情况下运行 indexer --rotate:
[snikolaev@dev01 ~]$ indexer -c min.conf --all --rotate
Manticore 2.6.1 9a706b4@180119 dev
Copyright (c) 2001-2016, Andrew Aksyonoff
Copyright (c) 2008-2016, Sphinx Technologies Inc (http://sphinxsearch.com)
Copyright (c) 2017-2018, Manticore Software LTD (http://manticoresearch.com)
using config file 'min.conf'...
indexing index 'idx_min'...
WARNING: Attribute count is 0: switching to none docinfo
collected 2 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 2 docs, 6 bytes
total 0.003 sec, 1547 bytes/sec, 515.86 docs/sec
total 3 reads, 0.000 sec, 10.6 kb/call avg, 0.0 msec/call avg
total 9 writes, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg
rotating indices: successfully sent SIGHUP to searchd (pid=27004).
如最后一行所示,indexer 向 searchd 发送信号,使其旋转索引。
尽情享受使用 Manticore Search 的乐趣!