annotate gpp/forums/search_indexes.py @ 414:b1f939b1fb01

Fixing #204; added the ability to search on forum topics.
author Brian Neal <bgneal@gmail.com>
date Sat, 09 Apr 2011 19:20:12 +0000
parents 79240675b903
children b910cc1460c8
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@392 4 from queued_search.indexes import QueuedSearchIndex
bgneal@222 5
bgneal@414 6 from forums.models import Forum, Topic, Post
bgneal@414 7
bgneal@414 8
bgneal@414 9 class TopicIndex(QueuedSearchIndex):
bgneal@414 10 text = CharField(document=True, use_template=True)
bgneal@414 11 author = CharField(model_attr='user')
bgneal@414 12 pub_date = DateTimeField(model_attr='creation_date')
bgneal@414 13
bgneal@414 14 def get_queryset(self):
bgneal@414 15 return Topic.objects.filter(forum__in=Forum.objects.public_forum_ids())
bgneal@414 16
bgneal@414 17 def get_updated_field(self):
bgneal@414 18 return 'update_date'
bgneal@222 19
bgneal@222 20
bgneal@392 21 class PostIndex(QueuedSearchIndex):
bgneal@222 22 text = CharField(document=True, use_template=True)
bgneal@222 23 author = CharField(model_attr='user')
bgneal@222 24 pub_date = DateTimeField(model_attr='creation_date')
bgneal@222 25
bgneal@222 26 def get_queryset(self):
bgneal@222 27 return Post.objects.filter(
bgneal@414 28 topic__forum__in=Forum.objects.public_forum_ids())
bgneal@222 29
bgneal@277 30 def get_updated_field(self):
bgneal@277 31 return 'update_date'
bgneal@277 32
bgneal@222 33
bgneal@414 34 site.register(Topic, TopicIndex)
bgneal@222 35 site.register(Post, PostIndex)