bgneal@223: """Haystack search index for the bio application."""
bgneal@223: from haystack.indexes import *
bgneal@223: from haystack import site
bgneal@469: from custom_search.indexes import CondQueuedSearchIndex
bgneal@223: 
bgneal@223: from bio.models import UserProfile
bgneal@471: from bio.signals import profile_content_update
bgneal@223: 
bgneal@223: 
bgneal@467: class UserProfileIndex(CondQueuedSearchIndex):
bgneal@223:     text = CharField(document=True, use_template=True)
bgneal@223:     author = CharField(model_attr='user')
bgneal@223: 
bgneal@533:     def index_queryset(self):
bgneal@223:         return UserProfile.objects.filter(user__is_active=True)
bgneal@223: 
bgneal@277:     def get_updated_field(self):
bgneal@277:         return 'update_date'
bgneal@277: 
bgneal@471:     def _setup_save(self, model):
bgneal@471:         profile_content_update.connect(self.enqueue_save)
bgneal@471: 
bgneal@471:     def _teardown_save(self, model):
bgneal@471:         profile_content_update.disconnect(self.enqueue_save)
bgneal@471: 
bgneal@471:     def enqueue_save(self, sender, **kwargs):
bgneal@471:         return self.enqueue('update', sender)
bgneal@471: 
bgneal@223: 
bgneal@223: site.register(UserProfile, UserProfileIndex)