Created
February 10, 2012 23:06
-
-
Save ikks/1793858 to your computer and use it in GitHub Desktop.
Haystack search indexes sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from haystack.indexes import RealTimeSearchIndex | |
from haystack.indexes import CharField | |
from haystack.indexes import RealTimeSearchIndex | |
from haystack.indexes import CharField | |
from haystack.indexes import MultiValueField | |
from haystack import site | |
from apps.informationgathering.models import RR | |
class RRIndex(RealTimeSearchIndex): | |
"""Index preparation, in production, when there is high write traffic | |
we have to make sure we are using QueueSearchIndex and updating the index | |
in a timely way | |
""" | |
text = CharField(document=True, use_template=True) | |
assignednumber = CharField(model_attr='assignednumber') | |
people = MultiValueField() | |
territory = CharField() | |
def prepare_people(self,inst): | |
return [o.indexsearch() for o in inst.relatedpeople.all()] | |
def prepare_territory(self,inst): | |
if inst.territory_for_restitutionrequest_set.count()>0: | |
return inst.territory_for_restitutionrequest_set.all()[0].name | |
return "" | |
site.register(RR,RRIndex) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment