djangofull-text-searchsphinxdjango-sphinx

Django / Sphinx: How to query on multiple models?


I want to be able to query different models at once and get the aggregate result of the full text search. i.e. books and authors as a single list, sorted by relevance for example.

As I understand, in the documentation it mentions that it is possible but there is a huge limitation:

... The django-sphinx layer also supports some basic querying over multiple 
indexes ... 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) ...

Does this mean that the models should have exactly the same fields or would it be sufficient if only the fields in the index are common? It would still be a huge limitation. And why should the models contain a content_type attribute when it can be obtained from the class itself?

What if the same index name is given for indexes of different models? Would it be possible to search over that index and have results from different models?

Also in the documentation it says it is required to configure sphinx as follows for searching on multiple models:

model_classes = (ModelOne, ModelTwoWhichResemblesModelOne)
output = generate_config_for_models(model_classes)

Does anybody have any experience on this?


Solution

  • The models have to be commom just in the index (you can add fake colums). They have to contain the content_type so when you get the results you know the model the result belongs to.