Mercurial > public > sg101
comparison 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 |
comparison
equal
deleted
inserted
replaced
413:6144023ebea8 | 414:b1f939b1fb01 |
---|---|
1 """Haystack search index for the weblinks application.""" | 1 """Haystack search index for the weblinks application.""" |
2 from haystack.indexes import * | 2 from haystack.indexes import * |
3 from haystack import site | 3 from haystack import site |
4 from queued_search.indexes import QueuedSearchIndex | 4 from queued_search.indexes import QueuedSearchIndex |
5 | 5 |
6 from forums.models import Forum, Post | 6 from forums.models import Forum, Topic, Post |
7 | |
8 | |
9 class TopicIndex(QueuedSearchIndex): | |
10 text = CharField(document=True, use_template=True) | |
11 author = CharField(model_attr='user') | |
12 pub_date = DateTimeField(model_attr='creation_date') | |
13 | |
14 def get_queryset(self): | |
15 return Topic.objects.filter(forum__in=Forum.objects.public_forum_ids()) | |
16 | |
17 def get_updated_field(self): | |
18 return 'update_date' | |
7 | 19 |
8 | 20 |
9 class PostIndex(QueuedSearchIndex): | 21 class PostIndex(QueuedSearchIndex): |
10 text = CharField(document=True, use_template=True) | 22 text = CharField(document=True, use_template=True) |
11 author = CharField(model_attr='user') | 23 author = CharField(model_attr='user') |
12 pub_date = DateTimeField(model_attr='creation_date') | 24 pub_date = DateTimeField(model_attr='creation_date') |
13 | 25 |
14 def get_queryset(self): | 26 def get_queryset(self): |
15 return Post.objects.filter( | 27 return Post.objects.filter( |
16 topic__forum__in=Forum.objects.public_forums()) | 28 topic__forum__in=Forum.objects.public_forum_ids()) |
17 | 29 |
18 def get_updated_field(self): | 30 def get_updated_field(self): |
19 return 'update_date' | 31 return 'update_date' |
20 | 32 |
21 | 33 |
34 site.register(Topic, TopicIndex) | |
22 site.register(Post, PostIndex) | 35 site.register(Post, PostIndex) |