Search code examples
phpsphinx

How to properly reindex Sphinx search server?


I have a website that is using Sphinx search server to search through a MySQL database. This is working perfectly but the issue is when new items are added to the database. My question is when is the best time to perform a reindex as well as how to do it correctly. Currently I am doing a "indexer --all --rotate" but this doesn't seem to be working. The only way to update the indexes is to stop sphinx then perform a indexer --all and then restart the service. This is obviously not ideal on a live site. If anyone has any information on how to do this correctly I would really appreciate it.

Thanks


Solution

  • If I understand it correctly, a restart should not be necessary. The -all option tells indexer to update every index. -rotate rotates the index, i.e. create a temporary copy of each index and replace the old ones when finished. According to the Sphinx manual rotating works as follows: "it creates a second index, parallel to the first (in the same place, simply including .new in the filenames). Once complete, indexer notifies searchd via sending the SIGHUP signal, and searchd will attempt to rename the indexes (renaming the existing ones to include .old and renaming the .new to replace them), and then start serving from the newer files. Depending on the setting of seamless_rotate, there may be a slight delay in being able to search the newer indexes."

    There are differences between seamless and "interrupted" rotates. The type can be controlled using the seamless_rotate parameter in the Sphinx config file. Seamless rotates come at the cost of higher peak memory usage during the rotation, but happen without interruption.

    The Sphinx version also matters. In former versions a restart was required to update the index, in the newest version this seems to be no longer necessary.