how to obtain two different search results from single query in django haystack with solr

StackOverflow https://stackoverflow.com/questions/3663920

  •  01-10-2019
  •  | 
  •  

Question

I have one search box where users can search for either the movie name or actor. On the search results page I want to show the top hits for both the actor and for the movie name in separate tables. How is this done with Django Haystack over SOLR?

Thanks!

Was it helpful?

Solution

Don't know about haystack, but from a Solr point of view you'll have to run one query for actors and another query for movies.

OTHER TIPS

This post is old but I stumbled over it because I wanted to do the same thing. Like Mauricio Scheffler said you have to make two queries. In haystack you can specify witch model is queried:

query1 = SearchQuerySet().filter(content="something").models(Actor)
query2 = SearchQuerySet().filter(content="something").models(Movies)

If both values are in one table or the tables are related. You can place the results you want in the template.

{{ movies.object.actor }}
{{ movies.object.name }}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top