I have the following query
locations = SearchQuerySet().filter_or(content__in=words).models(Location)
but it's returning other models as well, I would only want to see Location instances.
Using Haystack 2.1.0 and whoosh 2.5
Any ideas?
I have the following query
locations = SearchQuerySet().filter_or(content__in=words).models(Location)
but it's returning other models as well, I would only want to see Location instances.
Using Haystack 2.1.0 and whoosh 2.5
Any ideas?
I ran into the same issue with Model filtering being ignored. I was able to get .models() working by downgrading to Haystack 2.0.0 and Whoosh 2.4.1
This is based partly on James Lims answer, but this should work for any versions of Haystack and Whoosh. Unfortunately neither party is really coming to the rescue on this, but the below solution doesn't seem to be too bad.
class MySearchQuerySet(SearchQuerySet):
def models(self,*mods):
# We have to redefine this because Whoosh & Haystack don't play well with model filtering
from haystack.utils import get_model_ct
mods = [get_model_ct(m) for m in mods]
return self.filter(django_ct__in=mods)
Then where ever SearchQuerySet
use MySearchQuerySet
instead:
MySearchQuery().filter(name="foo").models(my_models.bar,my_models.baz)