Если вы хотите начать изучать простые индексы 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 не может работать. Это:
Section “source” для получения данных из mysql. В этом случае мы даже не получаем реальные данные из mysql, а просто используем интерфейс mysql, имеющий данные, определённые прямо в конфигурации (“select 1, ‘cat’ union select 2, ‘dog'”). Он создаст 2 документа в Manticoresearch: один содержащий слово “cat”, другой — слово “dog”, идентификаторы соответственно 1 и 2.
Section “index” для создания индекса на основе вышеуказанного источника, он содержит только ссылку на источник (“source = min”) и путь к индексу (“path = idx”). После построения этого индекса файлы idx.* будут созданы в каталоге, из которого вы запускаете ‘indexer’ из.
Section “searchd” чтобы указать Manticoresearch, какие порты он должен слушать (“listen = 9306:mysql41”, что означает, что для общения с Manticoresearch на этом порту следует использовать SphinxQL), какой журнал использовать (“log = searchd.log”) и где сохранять идентификатор процесса (“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!