David Cramer's Blog

Configuration Generation for django-sphinx

I pushed an update to the django-sphinx repository tonight which includes a sample configuration generation tool.

It allows you to generate a source and index config for a Model based on it's field type. For example:

from nibbits.maps.models import Map
import djangosphinx

output = djangosphinx.generate_config_for_model(Map)
print output

This will give you something like:

source base
{
    type                = 'mysql'
    strip_html          = 0
    index_html_attrs    =
    sql_host            = localhost
    sql_user            = nibbits
    sql_pass            = 
    sql_db              = nibbits
    sql_port            =
    log                 = /var/log/sphinx/searchd.log

    sql_query_pre       =
    sql_query_post      =
    sql_query           = \
    SELECT id, name, game_id, author, description, tileset, map,
    map_filename, visible, checksum, screenshot, date_added \
    FROM maps
    sql_query_info      = SELECT * FROM `maps` WHERE `id` = $id

    # ForeignKey's and BooleanField's
    sql_group_column    = game_id
    sql_group_column    = tileset
    sql_group_column    = visible

    # DateField's and DateTimeField's
    sql_date_column     = date_added
}

index maps
{
    source          = maps
    patg            = maps
    docinfo         = extern
    morphology      = none
    stopwords       =
    min_word_len    = 2
    charset_type    = sbcs
    min_prefix_len  = 0
    min_infix_len   = 0
}