30

Jul

Filed in Code, Django |

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
}
  • Fidel Ramos

    This is very useful! Why don’t you make a custom management command, it’d be easy? Something like this:

    ./manage.py sphinxconfmodel Modelname

    And then we could have a full configuration generator, which would work on a list of models and make use Sphinx’s configuration source and index definition inheritance:

    ./manage.py sphinxfullconf Model1 Model2 Model3

  • David

    That’s a great idea. It could even generate configuration for any model with a SphinxSearch attached to it.

  • Doug Napoleone

    Yes please!

    Just add a postsyncdb signal at the top level management, and a settings module config file output option. Then whenever you do a syncdb the config file will be regenerated.

    shouldn’t be too hard…

  • David

    There’s now a generate_sphinx_config command (I think that’s what I called it, haha) which will generate sample configs for any model it can in [appname].

    I’ve also added a generate_config_for_models (see the s) which will assist you in UNION generation for search groups.

blog comments powered by Disqus