In general, it (possibly) cannot solve your problem using only one request. For example, if you use ElasticSearch as a search backend mechanism and MySQL for django models, MySQL and ElasticSearch will not be able to interact to create a single common query.
However, a workaround should occur if you use a common SQL database for your Django models and your Haystack hosting engine. You will need to create a custom hay mechanism that will analyze the request and filter the available models.
For example, to change the behavior of SimpleSearchBackend, all you have to do is fix the search method:
class CustomSimpleSearchBackend(haystack.backends.SimpleSearchBackend): def search(self, query_string, **kwargs): ... if query_string: for model in models: ... if 'users' in kwargs: qs = qs.filter(users=kwargs['users']) ... class CustomSimpleEngine(haystack.backends.BaseEngine): backend = CustomSimpleSearchBackend query = haystack.backends.simple_backend.SimpleSearchQuery
And in settings.py:
HAYSTACK_CONNECTIONS = { 'default': { 'ENGINE': 'myapp.backends.CustomSimpleEngine', }, }
Depending on the firewall used, the required patch will, of course, be different, but I suspect that it should not be too difficult to implement.
RΓ©gis B.
source share