comparison gpp/bio/search_indexes.py @ 471:d83296cac940

For #227: only enqueue user profiles if the user has changed the content we have in the search index.
author Brian Neal <bgneal@gmail.com>
date Wed, 17 Aug 2011 02:02:20 +0000
parents 3b30286adba5
children 387d46abcb95
comparison
equal deleted inserted replaced
470:d9b6c4ec1977 471:d83296cac940
2 from haystack.indexes import * 2 from haystack.indexes import *
3 from haystack import site 3 from haystack import site
4 from custom_search.indexes import CondQueuedSearchIndex 4 from custom_search.indexes import CondQueuedSearchIndex
5 5
6 from bio.models import UserProfile 6 from bio.models import UserProfile
7 from bio.signals import profile_content_update
7 8
8 9
9 class UserProfileIndex(CondQueuedSearchIndex): 10 class UserProfileIndex(CondQueuedSearchIndex):
10 text = CharField(document=True, use_template=True) 11 text = CharField(document=True, use_template=True)
11 author = CharField(model_attr='user') 12 author = CharField(model_attr='user')
14 return UserProfile.objects.filter(user__is_active=True) 15 return UserProfile.objects.filter(user__is_active=True)
15 16
16 def get_updated_field(self): 17 def get_updated_field(self):
17 return 'update_date' 18 return 'update_date'
18 19
20 def _setup_save(self, model):
21 profile_content_update.connect(self.enqueue_save)
22
23 def _teardown_save(self, model):
24 profile_content_update.disconnect(self.enqueue_save)
25
26 def enqueue_save(self, sender, **kwargs):
27 return self.enqueue('update', sender)
28
19 def can_index(self, instance): 29 def can_index(self, instance):
20 return instance.user.is_active 30 return instance.user.is_active
21 31
22 32
23 site.register(UserProfile, UserProfileIndex) 33 site.register(UserProfile, UserProfileIndex)