Mercurial > public > sg101
comparison gpp/custom_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 | |
children |
comparison
equal
deleted
inserted
replaced
468:ad4b63fbc584 | 469:3b30286adba5 |
---|---|
1 """ | |
2 This module contains custom search indexes to tailor the Haystack search | |
3 application to our needs. | |
4 | |
5 """ | |
6 from queued_search.indexes import QueuedSearchIndex | |
7 | |
8 | |
9 class CondQueuedSearchIndex(QueuedSearchIndex): | |
10 """ | |
11 This customized version of QueuedSearchIndex conditionally enqueues items | |
12 to be indexed by calling the can_index() method. | |
13 | |
14 """ | |
15 def can_index(self, instance): | |
16 """ | |
17 The default is to index all instances. Override this method to | |
18 customize the behavior. This will be called on all update operations. | |
19 | |
20 """ | |
21 return True | |
22 | |
23 def enqueue(self, action, instance): | |
24 """ | |
25 This method enqueues the instance only if the can_index() method | |
26 returns True. | |
27 | |
28 """ | |
29 if (action == 'update' and self.can_index(instance) or | |
30 action == 'delete'): | |
31 super(CondQueuedSearchIndex, self).enqueue(action, instance) |