Sphinx的配置文件的语法是不支持include语法的,
那如果多个索引都配置在sphinx.conf主配置文件中,
那文件会变得非常的大,
于是想看怎样让sphinx的配置文件可以支持include包含多个子配置文件?
有个老外在他的博客中提供了用php脚本实现include子配置文件的方法,
其博文地址:
http://mwillis.co.uk/sphinx/sphinx-tip-multiple-config-files/
于是摘抄其中的php代码下来,
经测试,是可行的。
可以在sphinx的配置文件sphinx.conf所在的目录下创建一个conf.d目录,
然后把多个索引的配置文件分别以.conf做后缀命名存放其中,
然后在sphinx.conf配置中加上如下php代码即可:
1 |
<?php |
2 |
$files =
scandir(dirname( __FILE__ )
. "/conf.d/" ); |
3 |
foreach ( $files as $key => $file )
{ |
4 |
if ( $file != "." && $file != ".." &&
preg_match( '/.conf$/iU' , $file )
) { |
5 |
include (dirname( __FILE__ )
. "/conf.d/$file" ); |
6 |
} |
7 |
} |
8 |
?> |
注意:
因为要让php代码执行,
所以在sphinx.conf文件的第一行加上:
1 |
#!/usr/bin/php |
这也表明了sphinx的配置文件是支持PHP语法的,所以如果我们需要动态加载某些索引的时候可以采用PHP来实现。