Sphinx某些时候会找不到搜索结果,使用seach命令进行搜索时发现有如下错误:


index 'xxx': search error: failed to open /data/html/index/xxx.sph: No such file or directory


到该目录下发现出现很多名为xxx.new.sph, xxx.new.spa, xxx.new.spm等文件,

而sphinx配置文件中写的索引路径为/data/html/index/xxx。


可以确定是search寻找的是xxx.sph文件,而indexer或searchd将索引文件命名为xxx.new.sph造成无法检索。


这个问题出现的原因和indexer rotate工作方式有关,具体可以参考http://www.sphinxsearch.com/forum/view.html?id=274。

原因引用如下:

It seems thata) the lock files were lost somehow, and
b) you ran indexer without --rotate switch.
Normally, searchd would create .spl lock files on startup (and kill them on shutdown),
and indexer would then refuse to reindex without --rotate switch.
indexers sends SIGHUP to searchd when completed (and it should print that out). searchd
then does the following:
1) waits for all children to exit
2) renames current index files to .old
3) renames .new index files to current
4) tries to load current index files
5) if something failed, it rollbacks current files from .old and new to .new
In your case I would start with double checking directory access rights, users which both
indexer and searchd run under, etc.

解决方式为:

searchd --stop # 先停掉searchd,注意如果采用kill的方式,要保证/var/log/searchd.pid文件的一致性

index --all # 重建所有索引,可以看到xxx.sph文件又回来了

searchd # 启动searchd服务

index --all --rotate # 试试用rotate命令重建索引