I have a search working fine on my project. But in my models I have a boolean field named is_active
.
I want the search occurs only when is_active is True, but I've been testing this without any satisfatory response.
my search_indexes.py:
from haystack.indexes import *
from haystack.sites import site
from core.models import AnuncioSolucao
class AnuncioSolucaoIndex(RealTimeSearchIndex):
text = CharField(document=True,use_template=True)
site.register(AnuncioSolucao,AnuncioSolucaoIndex)
That way it works, but also bring me all the is_active == False
. Any thoughts?
There's a method called read_queryset on the SearchIndex API. I just had to override this:
class AnuncioSolucaoIndex(RealTimeSearchIndex):
text = CharField(document=True,use_template=True)
def read_queryset(self):
super(AnuncioSolucaoIndex,self).read_queryset()
return AnuncioSolucao.objects.filter(is_active=True)