What's new? | Help | Directory | Sign in
Google
django-sphinx
A layer for full-text search engine using MySQL and Python
  
  
  
  
    
Join project
Project owners:
  dcramer

This is a layer that functions much like the Django ORM does except it works on top of the Sphinx (http://www.sphinxsearch.com) full-text search engine.

Please Note: You will need to create your own sphinx indexes and install sphinx on your server to use this app.

There will no longer be release packages available. Please use SVN to checkout the latest trunk version, as it should always be stable and current.

svn checkout http://django-sphinx.googlecode.com/svn/trunk/ django-sphinx

2.0.0 Note: You will need to install the sphinxapi.py package into your Python Path if you are using anything other than Sphinx 0.97 (which the API is included for).

The following is some example usage:

class MyModel(models.Model):
    search = SphinxSearch('my_index_name') # optional: defaults to db_table

MyModel.search.query('query')
MyModel.search.query('query').order_by('@weight', '@id', 'my_attribute')
MyModel.search.query('query').filter(my_attribute=5)
MyModel.search.query('query').filter(my_other_attribute=[5, 3,4])
MyModel.search.query('query').exclude(my_attribute=5)[0:10]
MyModel.search.query('query').count()

Some additional methods:

The django-sphinx layer also supports some basic querying over multiple indexes. To use this you first need to understand the rules of a UNION. Your indexes must contain exactly the same fields. These fields must also include a content_type selection which should be the content_type id associated with that table (model).

You can then do something like this:

SphinxSearch('index1 index2 index3').query('hello')

This will return a list of all matches, ordered by weight, from all indexes. This performs one SQL query per index with matches in it, as Django's ORM does not support SQL UNION.