最小配置以玩转 Manticore Search

如果您想开始学习 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 = 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).

正如您在最后一行所看到的,索引器向 searchd 发送了信号,以使其旋转索引。

享受玩转 Manticore Search!

安装Manticore Search

安装Manticore Search