Take the 2-minute tour ×

The django-sphinx documentation shows that django-sphinx layer also supports some basic querying over multiple indexes.


from djangosphinx.models import SphinxSearch

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

It seems SphinxSearch does not contain the function query(). I also tried to include content_type in sphinx.conf sql_query configuration as mentioned in the django-sphinx documentation. Nothing has worked.

Traceback (most recent call last):
AttributeError: 'SphinxSearch' object has no attribute 'query'

Can anybody throw light on how I could get ranked results from multiple indexes in sphinx

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

instead of using SphinxSearch, you want to use SphinxQuerySet

for example, if i wanted to query three indexes, weigh the results using the title, tags, and content fields, and set custom matching (SPH_MATCH_EXTENDED2) and ranking (SPH_RANK_NONE) modes:

from djangosphinx.models import SphinxQuerySet

search = SphinxQuerySet(
    index = "index_1 index_2 index_n",
    weights = {
        'title': 100,
        'tags': 80,
        'content': 20
    mode = 'SPH_MATCH_EXTENDED2',
    rankmode = 'SPH_RANK_NONE')

results = search.query('what is the answer to life, the universe, and everything?')

for result in results:
    print result
share|improve this answer
the answer is 42 ;) –  nabizan Feb 4 '11 at 9:35
add comment

Your Answer


