配置中的脚本

你知道 Sphinx 和 Manticore Search 配置允许你通过使用 shebang 语法 进行脚本编写吗?以下是它在某些情况下如何有用的示例:

想象一下,你有 3 个结构完全相同的表,你希望将它们索引到 3 个索引中,每个表对应一个索引。你可以仅仅做一个 php 脚本来完成这项工作,并将其用作 Manticore Search 配置,而不是分别描述每个源/索引:

#!/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
}

现在你可以像正常的 Manticore Search 配置一样使用这个文件:

[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'...

安装Manticore Search

安装Manticore Search