left arrowBack
Mindaugas Zukas

Mindaugas Zukas

October 15, 2010 ・ Sphinx

Indexer for real-time indexes

We’ve implemented a script which should help when you need to migrate from plain indexes to real-time (RT) indexes or simply make first-time RT indexing.

This script’s function is to fill and update RT Sphinx indexes. It does the similar work as sphinx indexer did for regular ones. Thus its config file (sources.ini) has almost the same syntax and content as the source section of sphinx.conf.

The script can:

  • Populate index with data;

  • Append new data to the index;

  • Update existing index records;

  • Make pre and post SQL queries.

To install:


  • Edit sources.ini for that. It already has one demo section, use it as an example;

  • You can make several sections, each for one data source for each RT index.

To append new data without rewriting existing records you should use id counter for data source. For this you should make such steps:

  • Make a table for counters;

  • Add $start and $end to sql_query config parameter;

  • Modify sql_query_range to select min and max counter id from the counter table;

  • Modify sql_query_post_index for counter table updating.

You can find more details on using counters at

Having finished the script configuration you can run it as simple as:

php indexer.php Good luck, and let us know if you have any troubles with this script!

  • Sphinx
  • Basics