comparison custom_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/custom_search/indexes.py@3b30286adba5
children 858ce870c854
comparison
equal deleted inserted replaced
580:c525f3e0b5d0 581:ee87ea74d46b
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)