-
Notifications
You must be signed in to change notification settings - Fork 112
/
search_indexes.py
53 lines (39 loc) · 1.81 KB
/
search_indexes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# -*- coding: utf-8 -*-
"""Django haystack `SearchIndex` module."""
from pages.models import Page
from pages import settings
from haystack.indexes import SearchIndex, CharField, DateTimeField, Indexable
# This is obsolete if you use haystack 2.0, use the HAYSTACK_SIGNAL_PROCESSOR
# setting instead
if settings.PAGE_REAL_TIME_SEARCH:
from haystack.indexes import RealTimeSearchIndex
class RealTimePageIndex(RealTimeSearchIndex, Indexable):
"""Search index for pages content."""
text = CharField(document=True, use_template=True)
title = CharField(model_attr='title')
url = CharField(model_attr='get_absolute_url')
publication_date = DateTimeField(model_attr='publication_date')
def index_queryset(self, using=None):
"""Haystack 2.0 requires this method now"""
return self.get_model().objects.published()
def get_queryset(self):
"""Used when the entire index for model is updated."""
return Page.objects.published()
def get_model(self):
return Page
def should_update(self, instance, **kwargs):
return instance.status == Page.PUBLISHED
else:
class PageIndex(SearchIndex, Indexable):
"""Search index for pages content."""
text = CharField(document=True, use_template=True)
title = CharField(model_attr='title')
url = CharField(model_attr='get_absolute_url')
publication_date = DateTimeField(model_attr='publication_date')
def index_queryset(self, using=None):
"""Used when the entire index for model is updated."""
return Page.objects.published()
def get_model(self):
return Page
def should_update(self, instance, **kwargs):
return instance.status == Page.PUBLISHED