# HG changeset patch # User Brian Neal # Date 1302376812 0 # Node ID b1f939b1fb01b21b5233fc0634c3d05794717a6f # Parent 6144023ebea8440a03de104b8bb95c0e84029358 Fixing #204; added the ability to search on forum topics. diff -r 6144023ebea8 -r b1f939b1fb01 gpp/forums/models.py --- 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): """ diff -r 6144023ebea8 -r b1f939b1fb01 gpp/forums/search_indexes.py --- 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) diff -r 6144023ebea8 -r b1f939b1fb01 gpp/templates/search/indexes/forums/post_text.txt --- 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 }} diff -r 6144023ebea8 -r b1f939b1fb01 gpp/templates/search/indexes/forums/topic_text.txt --- /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 }} diff -r 6144023ebea8 -r b1f939b1fb01 gpp/templates/search/search.html --- 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 @@ Search in: - + + + + + - - + + - -
- + +