# 在配置中使用脚本

你知道Sphinx和Manticore Search配置允许你通过使用[shebang语法](https://en.wikipedia.org/wiki/Shebang_(Unix))来进行脚本编写吗？这里有一个在某些情况下非常有用的例子：

想象你有3个结构相同的表，你希望为每个表建立一个索引。你可以编写一个PHP脚本来完成这个任务，并将其作为Manticore Search配置使用，而不是分别描述每个源/索引：


```ini
#!/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配置一样使用这个文件：


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