annotate gpp/forums/search_indexes.py @ 533:387d46abcb95

Updated to Haystack 1.2.6. Got the latest Haystack, xapian backend, and queued_search from PyPi. This is for ticket #215.
author Brian Neal <bgneal@gmail.com>
date Mon, 26 Dec 2011 23:05:29 +0000
parents d9b6c4ec1977
children
rev   line source
bgneal@222 1 """Haystack search index for the weblinks application."""
bgneal@222 2 from haystack.indexes import *
bgneal@222 3 from haystack import site
bgneal@469 4 from custom_search.indexes import CondQueuedSearchIndex
bgneal@222 5
bgneal@414 6 from forums.models import Forum, Topic, Post
bgneal@469 7 from forums.signals import topic_content_update, post_content_update
bgneal@414 8
bgneal@414 9
bgneal@467 10 class TopicIndex(CondQueuedSearchIndex):
bgneal@414 11 text = CharField(document=True, use_template=True)
bgneal@414 12 author = CharField(model_attr='user')
bgneal@414 13 pub_date = DateTimeField(model_attr='creation_date')
bgneal@414 14
bgneal@533 15 def index_queryset(self):
bgneal@414 16 return Topic.objects.filter(forum__in=Forum.objects.public_forum_ids())
bgneal@414 17
bgneal@414 18 def get_updated_field(self):
bgneal@414 19 return 'update_date'
bgneal@222 20
bgneal@469 21 def _setup_save(self, model):
bgneal@469 22 topic_content_update.connect(self.enqueue_save)
bgneal@469 23
bgneal@469 24 def _teardown_save(self, model):
bgneal@469 25 topic_content_update.disconnect(self.enqueue_save)
bgneal@469 26
bgneal@470 27 def enqueue_save(self, sender, **kwargs):
bgneal@470 28 return self.enqueue('update', sender)
bgneal@470 29
bgneal@467 30 def can_index(self, instance):
bgneal@467 31 return instance.forum.id in Forum.objects.public_forum_ids()
bgneal@222 32
bgneal@467 33
bgneal@467 34 class PostIndex(CondQueuedSearchIndex):
bgneal@222 35 text = CharField(document=True, use_template=True)
bgneal@222 36 author = CharField(model_attr='user')
bgneal@222 37 pub_date = DateTimeField(model_attr='creation_date')
bgneal@222 38
bgneal@533 39 def index_queryset(self):
bgneal@222 40 return Post.objects.filter(
bgneal@414 41 topic__forum__in=Forum.objects.public_forum_ids())
bgneal@222 42
bgneal@277 43 def get_updated_field(self):
bgneal@277 44 return 'update_date'
bgneal@277 45
bgneal@469 46 def _setup_save(self, model):
bgneal@469 47 post_content_update.connect(self.enqueue_save)
bgneal@469 48
bgneal@469 49 def _teardown_save(self, model):
bgneal@469 50 post_content_update.disconnect(self.enqueue_save)
bgneal@469 51
bgneal@470 52 def enqueue_save(self, sender, **kwargs):
bgneal@470 53 return self.enqueue('update', sender)
bgneal@470 54
bgneal@467 55 def can_index(self, instance):
bgneal@467 56 return instance.topic.forum.id in Forum.objects.public_forum_ids()
bgneal@467 57
bgneal@222 58
bgneal@414 59 site.register(Topic, TopicIndex)
bgneal@222 60 site.register(Post, PostIndex)