Did you know that Sphinx and Manticore Search configs allow you to do scripting by using shebang syntax? Here is an example of how useful it can be in some cases:
Imagine you have 3 tables with identical structure that you would like to index into 3 indexes one per table. You can just make a php script which will do it and use it as a Manticore Search config instead of describing each source/index separately:
#!/usr/bin/php
<?php
$source= "source [TABLE]_src {
type = mysql
sql_host = localhost
sql_user = user
sql_pass = password
sql_db = db
sql_port = 3306
sql_query = SELECT [TABLE].id, title, body FROM [TABLE] WHERE [TABLE].id >=\$startand[TABLE].ID <=\$end
sql_query_range = SELECT MIN(id), MAX(id) FROM [TABLE]
sql_range_step = 1000
}
";
$index= "index [TABLE]_idx {
source = [TABLE]_src
path = /path/to/indexes/idx_[TABLE]
}
";
$tables= array('Cats', 'Dogs', 'Mouses');
foreach($tables as $table) {
echo str_replace('[TABLE]', $table, $source)."\n";
echo str_replace('[TABLE]', $table, $index)."\n";
}
?>
searchd {
listen = localhost:9306:mysql41
pid_file = /path/to/pid_file.pid
}
Now you can use this file just like a normal Manticore Search config:
[snikolaev@dev01 ~]$ searchd -c manticore.conf
Manticore 2.6.4 4510fa4@180501 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 'manticore.conf'...