问题
views.py (relevant part)
srch = request.GET.get('search', "")
sqs = SearchQuerySet().filter(has_title=True)
clean_query = sqs.query.clean(srch)
results = sqs.raw_search(clean_query)
search_indexes.py
from haystack.indexes import *
from haystack import site
from myproject.myapp.models import Person
class PersonIndex(SearchIndex):
text = CharField(document=True, use_template=True)
name = CharField(model_attr='name')
has_title = BooleanField(model_attr='has_title')
site.register(Person, PersonIndex)
models.py
class Person(models.Model):
name = models.CharField(max_length=50)
has_title = models.BooleanField()
def __unicode__(self):
return u'%s' % self.name
When searching, I get my results out of the complete model instead of only those entries were has_title
is True
. I also ran python manage.py rebuild_index
after applying the filter. Why does the filter not work?
I am using Whoosh 2.4.1
, Django-haystack 1.2.7
and Django 1.4
.
If someone could just confirm that they can successfully use SearchQuerySet().filter
with Whoosh 2.4
and Django-haystack 1.2.7
this would already be a big help.
回答1:
It seems that raw_search(clean_query)
just returns every item in sqs
again (don't know why), using filter(content=clean_query)
instead gets the expected result.
srch = request.GET.get('search', "")
sqs = SearchQuerySet().filter(has_title=True)
clean_query = sqs.query.clean(srch)
result = sqs.filter(content=clean_query)
来源:https://stackoverflow.com/questions/14216207/haystacks-searchqueryset-filter-not-doing-anything-whoosh-2-4-1-django-hays