|
@@ 14-33 (lines=20) @@
|
| 11 |
|
|
| 12 |
|
from haystack.indexes import RealTimeSearchIndex |
| 13 |
|
|
| 14 |
|
class RealTimePageIndex(RealTimeSearchIndex, Indexable): |
| 15 |
|
"""Search index for pages content.""" |
| 16 |
|
text = CharField(document=True, use_template=True) |
| 17 |
|
title = CharField(model_attr='title') |
| 18 |
|
url = CharField(model_attr='get_absolute_url') |
| 19 |
|
publication_date = DateTimeField(model_attr='publication_date') |
| 20 |
|
|
| 21 |
|
def index_queryset(self, using=None): |
| 22 |
|
"""Haystack 2.0 requires this method now""" |
| 23 |
|
return self.get_model().objects.published() |
| 24 |
|
|
| 25 |
|
def get_queryset(self): |
| 26 |
|
"""Used when the entire index for model is updated.""" |
| 27 |
|
return Page.objects.published() |
| 28 |
|
|
| 29 |
|
def get_model(self): |
| 30 |
|
return Page |
| 31 |
|
|
| 32 |
|
def should_update(self, instance, **kwargs): |
| 33 |
|
return instance.status == Page.PUBLISHED |
| 34 |
|
|
| 35 |
|
else: |
| 36 |
|
|
|
@@ 37-52 (lines=16) @@
|
| 34 |
|
|
| 35 |
|
else: |
| 36 |
|
|
| 37 |
|
class PageIndex(SearchIndex, Indexable): |
| 38 |
|
"""Search index for pages content.""" |
| 39 |
|
text = CharField(document=True, use_template=True) |
| 40 |
|
title = CharField(model_attr='title') |
| 41 |
|
url = CharField(model_attr='get_absolute_url') |
| 42 |
|
publication_date = DateTimeField(model_attr='publication_date') |
| 43 |
|
|
| 44 |
|
def index_queryset(self, using=None): |
| 45 |
|
"""Used when the entire index for model is updated.""" |
| 46 |
|
return Page.objects.published() |
| 47 |
|
|
| 48 |
|
def get_model(self): |
| 49 |
|
return Page |
| 50 |
|
|
| 51 |
|
def should_update(self, instance, **kwargs): |
| 52 |
|
return instance.status == Page.PUBLISHED |
| 53 |
|
|
| 54 |
|
|