1
from haystack import indexes
2
from pybb.models import Topic, Post
5
class TopicIndex(indexes.SearchIndex, indexes.Indexable):
7
"""Create a search index. Changes made here need to be reindexed. Defined
8
fields are stored in the index, so when displaying the result the data is
9
read from the index and do not hit the database.
11
Except the 'text' field all defined fields will be in the index.
13
'text' indicates the template where the concatenated data
14
is gathered and the search runs over.
16
'date' is the field which is used for sorting
20
text = indexes.CharField(document=True, use_template=True)
21
date = indexes.DateTimeField(model_attr='created')
22
name = indexes.CharField(model_attr='name')
23
# Following fields get stored in the index but are not be used for indexing
24
# This avoids hitting the database when the results are rendered
25
user = indexes.CharField(model_attr='user', indexed=False)
26
topic_link = indexes.CharField(model_attr='get_absolute_url', indexed=False)
31
def index_queryset(self, using=None):
32
"""Do not index hidden topics."""
33
return self.get_model().objects.exclude(posts__hidden=True)
35
def get_updated_field(self):
39
class PostIndex(indexes.SearchIndex, indexes.Indexable):
41
text = indexes.CharField(document=True, use_template=True)
42
date = indexes.DateTimeField(model_attr='created')
43
body_text = indexes.CharField(model_attr='body_text')
44
# Following fields get stored in the index but are not be used for indexing
45
# This avoids hitting the database when the results are rendered
46
user = indexes.CharField(model_attr='user', indexed='false')
47
post_link = indexes.CharField(
48
model_attr='get_absolute_url', indexed='false')
53
def index_queryset(self, using=None):
54
"""Do not index hidden posts."""
55
return self.get_model().objects.exclude(hidden=True)
57
def get_updated_field(self):