diff 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
line wrap: on
line diff
--- a/gpp/forums/search_indexes.py	Thu Apr 07 23:52:18 2011 +0000
+++ b/gpp/forums/search_indexes.py	Sat Apr 09 19:20:12 2011 +0000
@@ -3,7 +3,19 @@
 from haystack import site
 from queued_search.indexes import QueuedSearchIndex
 
-from forums.models import Forum, Post
+from forums.models import Forum, Topic, Post
+
+
+class TopicIndex(QueuedSearchIndex):
+    text = CharField(document=True, use_template=True)
+    author = CharField(model_attr='user')
+    pub_date = DateTimeField(model_attr='creation_date')
+
+    def get_queryset(self):
+        return Topic.objects.filter(forum__in=Forum.objects.public_forum_ids())
+
+    def get_updated_field(self):
+        return 'update_date'
 
 
 class PostIndex(QueuedSearchIndex):
@@ -13,10 +25,11 @@
 
     def get_queryset(self):
         return Post.objects.filter(
-                topic__forum__in=Forum.objects.public_forums())
+                topic__forum__in=Forum.objects.public_forum_ids())
 
     def get_updated_field(self):
         return 'update_date'
 
 
+site.register(Topic, TopicIndex)
 site.register(Post, PostIndex)