Mercurial > public > sg101
comparison forums/search_indexes.py @ 753:ad53d929281a
For issue #62, upgrade Haystack from 1.2.7 to 2.1.0.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Fri, 03 Jan 2014 19:01:18 -0600 |
parents | ee87ea74d46b |
children | cf9918328c64 |
comparison
equal
deleted
inserted
replaced
752:95f4e7f352fd | 753:ad53d929281a |
---|---|
1 """Haystack search index for the weblinks application.""" | 1 """Haystack search index for the weblinks application.""" |
2 from haystack.indexes import * | 2 from haystack import indexes |
3 from haystack import site | |
4 from custom_search.indexes import CondQueuedSearchIndex | |
5 | 3 |
6 from forums.models import Forum, Topic, Post | 4 from forums.models import Forum, Topic, Post |
7 from forums.signals import topic_content_update, post_content_update | |
8 | 5 |
9 | 6 |
10 class TopicIndex(CondQueuedSearchIndex): | 7 class TopicIndex(indexes.SearchIndex, indexes.Indexable): |
11 text = CharField(document=True, use_template=True) | 8 text = indexes.CharField(document=True, use_template=True) |
12 author = CharField(model_attr='user') | 9 author = indexes.CharField(model_attr='user') |
13 pub_date = DateTimeField(model_attr='creation_date') | 10 pub_date = indexes.DateTimeField(model_attr='creation_date') |
14 | 11 |
15 def index_queryset(self): | 12 def get_model(self): |
13 return Topic | |
14 | |
15 def index_queryset(self, using=None): | |
16 return Topic.objects.filter(forum__in=Forum.objects.public_forum_ids()) | 16 return Topic.objects.filter(forum__in=Forum.objects.public_forum_ids()) |
17 | 17 |
18 def get_updated_field(self): | 18 def get_updated_field(self): |
19 return 'update_date' | 19 return 'update_date' |
20 | 20 |
21 def _setup_save(self, model): | |
22 topic_content_update.connect(self.enqueue_save) | |
23 | 21 |
24 def _teardown_save(self, model): | 22 class PostIndex(indexes.SearchIndex, indexes.Indexable): |
25 topic_content_update.disconnect(self.enqueue_save) | 23 text = indexes.CharField(document=True, use_template=True) |
24 author = indexes.CharField(model_attr='user') | |
25 pub_date = indexes.DateTimeField(model_attr='creation_date') | |
26 | 26 |
27 def enqueue_save(self, sender, **kwargs): | 27 def get_model(self): |
28 return self.enqueue('update', sender) | 28 return Post |
29 | 29 |
30 def can_index(self, instance): | 30 def index_queryset(self, using=None): |
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( | 31 return Post.objects.filter( |
41 topic__forum__in=Forum.objects.public_forum_ids()) | 32 topic__forum__in=Forum.objects.public_forum_ids()) |
42 | 33 |
43 def get_updated_field(self): | 34 def get_updated_field(self): |
44 return 'update_date' | 35 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) |