bgneal@469: """
bgneal@469: This module contains custom search indexes to tailor the Haystack search
bgneal@469: application to our needs.
bgneal@469: 
bgneal@469: """
bgneal@469: from queued_search.indexes import QueuedSearchIndex
bgneal@469: 
bgneal@469: 
bgneal@469: class CondQueuedSearchIndex(QueuedSearchIndex):
bgneal@469:     """
bgneal@469:     This customized version of QueuedSearchIndex conditionally enqueues items
bgneal@469:     to be indexed by calling the can_index() method.
bgneal@469: 
bgneal@469:     """
bgneal@469:     def can_index(self, instance):
bgneal@469:         """
bgneal@469:         The default is to index all instances. Override this method to
bgneal@469:         customize the behavior. This will be called on all update operations.
bgneal@469: 
bgneal@469:         """
bgneal@469:         return True
bgneal@469: 
bgneal@469:     def enqueue(self, action, instance):
bgneal@469:         """
bgneal@469:         This method enqueues the instance only if the can_index() method
bgneal@469:         returns True.
bgneal@469: 
bgneal@469:         """
bgneal@469:         if (action == 'update' and self.can_index(instance) or
bgneal@469:                 action == 'delete'):
bgneal@469:             super(CondQueuedSearchIndex, self).enqueue(action, instance)