changeset 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 (2011-04-09)
parents 6144023ebea8
children d4d167876c25
files gpp/forums/models.py gpp/forums/search_indexes.py gpp/templates/search/indexes/forums/post_text.txt gpp/templates/search/indexes/forums/topic_text.txt gpp/templates/search/search.html
diffstat 5 files changed, 33 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/gpp/forums/models.py	Thu Apr 07 23:52:18 2011 +0000
+++ b/gpp/forums/models.py	Sat Apr 09 19:20:12 2011 +0000
@@ -259,6 +259,12 @@
         except Post.DoesNotExist:
             self.last_post = None
 
+    def search_title(self):
+        return u"%s by %s" % (self.name, self.user.username)
+
+    def search_summary(self):
+        return u''
+
 
 class Post(models.Model):
     """
--- 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)
--- a/gpp/templates/search/indexes/forums/post_text.txt	Thu Apr 07 23:52:18 2011 +0000
+++ b/gpp/templates/search/indexes/forums/post_text.txt	Sat Apr 09 19:20:12 2011 +0000
@@ -1,4 +1,3 @@
-{{ object.topic.name }}
 {{ object.user.username }}
 {{ object.user.get_full_name }}
 {{ object.body }}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gpp/templates/search/indexes/forums/topic_text.txt	Sat Apr 09 19:20:12 2011 +0000
@@ -0,0 +1,3 @@
+{{ object.name }}
+{{ object.user.username }}
+{{ object.user.get_full_name }}
--- a/gpp/templates/search/search.html	Thu Apr 07 23:52:18 2011 +0000
+++ b/gpp/templates/search/search.html	Sat Apr 09 19:20:12 2011 +0000
@@ -35,22 +35,25 @@
 <legend>Search in:</legend>
 <table>
    <tr>
-      <td><input id="chk-forums" type="checkbox" name="models" value="forums.post" checked="checked" />
-         <label for="chk-forums" class="pointer">Forum Posts</label></td>
+      <td><input id="chk-forums-topics" type="checkbox" name="models" value="forums.topic" checked="checked" />
+         <label for="chk-forums-topics" class="pointer">Forum Topics</label></td>
+
+      <td><input id="chk-forums-post" type="checkbox" name="models" value="forums.post" checked="checked" />
+         <label for="chk-forums-post" class="pointer">Forum Posts</label></td>
       <td><input id="chk-news" type="checkbox" name="models" value="news.story" checked="checked" />
          <label for="chk-news" class="pointer">News Stories</label></td>
+   </tr>
+   <tr>
       <td><input id="chk-profiles" type="checkbox" name="models" value="bio.userprofile" checked="checked" />
          <label for="chk-profiles" class="pointer">User Profiles</label></td>
-   </tr>
-   <tr>
       <td><input id="chk-links" type="checkbox" name="models" value="weblinks.link" checked="checked" />
          <label for="chk-links" class="pointer">Links</label></td>
       <td><input id="chk-dls" type="checkbox" name="models" value="downloads.download" checked="checked" />
          <label for="chk-dls" class="pointer">Downloads</label></td>
+   </tr>
+   <tr>
       <td><input id="chk-podcasts" type="checkbox" name="models" value="podcast.item" checked="checked" />
          <label for="chk-podcasts" class="pointer">Podcasts</label></td>
-   </tr>
-   <tr>
       <td colspan="2"><input id="chk-ygroup" type="checkbox" name="models" value="ygroup.post" checked="checked" />
          <label for="chk-ygroup" class="pointer">Yahoo Group Archives</label></td>
    </tr>