Mercurial > public > sg101
comparison forums/search_indexes.py @ 581:ee87ea74d46b
For Django 1.4, rearranged project structure for new manage.py.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 05 May 2012 17:10:48 -0500 |
parents | gpp/forums/search_indexes.py@387d46abcb95 |
children | ad53d929281a |
comparison
equal
deleted
inserted
replaced
580:c525f3e0b5d0 | 581:ee87ea74d46b |
---|---|
1 """Haystack search index for the weblinks application.""" | |
2 from haystack.indexes import * | |
3 from haystack import site | |
4 from custom_search.indexes import CondQueuedSearchIndex | |
5 | |
6 from forums.models import Forum, Topic, Post | |
7 from forums.signals import topic_content_update, post_content_update | |
8 | |
9 | |
10 class TopicIndex(CondQueuedSearchIndex): | |
11 text = CharField(document=True, use_template=True) | |
12 author = CharField(model_attr='user') | |
13 pub_date = DateTimeField(model_attr='creation_date') | |
14 | |
15 def index_queryset(self): | |
16 return Topic.objects.filter(forum__in=Forum.objects.public_forum_ids()) | |
17 | |
18 def get_updated_field(self): | |
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) | |
26 | |
27 def enqueue_save(self, sender, **kwargs): | |
28 return self.enqueue('update', sender) | |
29 | |
30 def can_index(self, instance): | |
31 return instance.forum.id in Forum.objects.public_forum_ids() | |
32 | |
33 | |
34 class PostIndex(CondQueuedSearchIndex): | |
35 text = CharField(document=True, use_template=True) | |
36 author = CharField(model_attr='user') | |
37 pub_date = DateTimeField(model_attr='creation_date') | |
38 | |
39 def index_queryset(self): | |
40 return Post.objects.filter( | |
41 topic__forum__in=Forum.objects.public_forum_ids()) | |
42 | |
43 def get_updated_field(self): | |
44 return 'update_date' | |
45 | |
46 def _setup_save(self, model): | |
47 post_content_update.connect(self.enqueue_save) | |
48 | |
49 def _teardown_save(self, model): | |
50 post_content_update.disconnect(self.enqueue_save) | |
51 | |
52 def enqueue_save(self, sender, **kwargs): | |
53 return self.enqueue('update', sender) | |
54 | |
55 def can_index(self, instance): | |
56 return instance.topic.forum.id in Forum.objects.public_forum_ids() | |
57 | |
58 | |
59 site.register(Topic, TopicIndex) | |
60 site.register(Post, PostIndex) |