Search code examples
djangosearch-enginedjango-haystack

Filtering in haystack does not work


I have a model which has a field status definde as:

class Model(models.Model):
    ...
    status = models.CharField(_('entry status'), default=ENTRY_DRAFT, max_length=2, choices=ENTRY_CHOICES)

Right now I use haystack with simple engine set. My search index is below:

class EntryIndex(SearchIndex):
    text = CharField(document=True, use_template=True)
    author = CharField(model_attr='owner')
    date_published = DateTimeField(model_attr='date_published')
    status = CharField(model_attr='status')

    def index_queryset(self):
        """Used when the entire index for model is updated."""
        return Entry.objects.all().distinct()

site.register(Entry, EntryIndex)

The problem is that when I try to filter my entries using entries.filter(status=ENTRY_DRAFT) I receive all objects not only matching to filtering. Entries is SearchQuerySet passed to other function. What is wrong?


Solution

  • The problem occurred only when I used dummy search engine. The solution was to change search engine to other.