Mercurial > public > sg101
comparison gpp/forums/search_indexes.py @ 469:3b30286adba5
Smarter search index updating for forums. This work is for #227.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 17 Aug 2011 01:02:08 +0000 |
parents | b910cc1460c8 |
children | d9b6c4ec1977 |
comparison
equal
deleted
inserted
replaced
468:ad4b63fbc584 | 469:3b30286adba5 |
---|---|
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 custom_search import CondQueuedSearchIndex | 4 from custom_search.indexes import CondQueuedSearchIndex |
5 | 5 |
6 from forums.models import Forum, Topic, Post | 6 from forums.models import Forum, Topic, Post |
7 from forums.signals import topic_content_update, post_content_update | |
7 | 8 |
8 | 9 |
9 class TopicIndex(CondQueuedSearchIndex): | 10 class TopicIndex(CondQueuedSearchIndex): |
10 text = CharField(document=True, use_template=True) | 11 text = CharField(document=True, use_template=True) |
11 author = CharField(model_attr='user') | 12 author = CharField(model_attr='user') |
14 def get_queryset(self): | 15 def get_queryset(self): |
15 return Topic.objects.filter(forum__in=Forum.objects.public_forum_ids()) | 16 return Topic.objects.filter(forum__in=Forum.objects.public_forum_ids()) |
16 | 17 |
17 def get_updated_field(self): | 18 def get_updated_field(self): |
18 return 'update_date' | 19 return 'update_date' |
20 | |
21 def _setup_save(self, model): | |
22 topic_content_update.connect(self.enqueue_save) | |
23 | |
24 def _teardown_save(self, model): | |
25 topic_content_update.disconnect(self.enqueue_save) | |
19 | 26 |
20 def can_index(self, instance): | 27 def can_index(self, instance): |
21 return instance.forum.id in Forum.objects.public_forum_ids() | 28 return instance.forum.id in Forum.objects.public_forum_ids() |
22 | 29 |
23 | 30 |
31 topic__forum__in=Forum.objects.public_forum_ids()) | 38 topic__forum__in=Forum.objects.public_forum_ids()) |
32 | 39 |
33 def get_updated_field(self): | 40 def get_updated_field(self): |
34 return 'update_date' | 41 return 'update_date' |
35 | 42 |
43 def _setup_save(self, model): | |
44 post_content_update.connect(self.enqueue_save) | |
45 | |
46 def _teardown_save(self, model): | |
47 post_content_update.disconnect(self.enqueue_save) | |
48 | |
36 def can_index(self, instance): | 49 def can_index(self, instance): |
37 return instance.topic.forum.id in Forum.objects.public_forum_ids() | 50 return instance.topic.forum.id in Forum.objects.public_forum_ids() |
38 | 51 |
39 | 52 |
40 site.register(Topic, TopicIndex) | 53 site.register(Topic, TopicIndex) |