1
from haystack import indexes
2
from news.models import Post
6
class PostIndex(indexes.SearchIndex, indexes.Indexable):
8
"""Create a search index. Changes made here need to be reindexed.
9
Defined fields are stored in the index, so when displaying the result the
10
data is read from the index and do not hit the database.
12
Except the 'text' field all defined fields will be in the index.
14
'text' indicates the template where the concatenated data
15
is gathered and the search runs over.
17
'date' is the field which is used for sorting
21
text = indexes.CharField(document=True, use_template=True)
22
title = indexes.CharField(model_attr='title')
23
body = indexes.CharField(model_attr='body')
24
date = indexes.DateTimeField(model_attr='publish')
29
def index_queryset(self, using=None):
30
"Don't index news of the future"
31
return self.get_model().objects.filter(publish__lte=datetime.datetime.now())
33
def get_updated_field(self):