bgneal@222: """Haystack search index for the weblinks application.""" bgneal@222: from haystack.indexes import * bgneal@222: from haystack import site bgneal@469: from custom_search.indexes import CondQueuedSearchIndex bgneal@222: bgneal@414: from forums.models import Forum, Topic, Post bgneal@469: from forums.signals import topic_content_update, post_content_update bgneal@414: bgneal@414: bgneal@467: class TopicIndex(CondQueuedSearchIndex): bgneal@414: text = CharField(document=True, use_template=True) bgneal@414: author = CharField(model_attr='user') bgneal@414: pub_date = DateTimeField(model_attr='creation_date') bgneal@414: bgneal@414: def get_queryset(self): bgneal@414: return Topic.objects.filter(forum__in=Forum.objects.public_forum_ids()) bgneal@414: bgneal@414: def get_updated_field(self): bgneal@414: return 'update_date' bgneal@222: bgneal@469: def _setup_save(self, model): bgneal@469: topic_content_update.connect(self.enqueue_save) bgneal@469: bgneal@469: def _teardown_save(self, model): bgneal@469: topic_content_update.disconnect(self.enqueue_save) bgneal@469: bgneal@467: def can_index(self, instance): bgneal@467: return instance.forum.id in Forum.objects.public_forum_ids() bgneal@222: bgneal@467: bgneal@467: class PostIndex(CondQueuedSearchIndex): bgneal@222: text = CharField(document=True, use_template=True) bgneal@222: author = CharField(model_attr='user') bgneal@222: pub_date = DateTimeField(model_attr='creation_date') bgneal@222: bgneal@222: def get_queryset(self): bgneal@222: return Post.objects.filter( bgneal@414: topic__forum__in=Forum.objects.public_forum_ids()) bgneal@222: bgneal@277: def get_updated_field(self): bgneal@277: return 'update_date' bgneal@277: bgneal@469: def _setup_save(self, model): bgneal@469: post_content_update.connect(self.enqueue_save) bgneal@469: bgneal@469: def _teardown_save(self, model): bgneal@469: post_content_update.disconnect(self.enqueue_save) bgneal@469: bgneal@467: def can_index(self, instance): bgneal@467: return instance.topic.forum.id in Forum.objects.public_forum_ids() bgneal@467: bgneal@222: bgneal@414: site.register(Topic, TopicIndex) bgneal@222: site.register(Post, PostIndex)