Skip to content

Instantly share code, notes, and snippets.

@ikks
Created February 10, 2012 23:06
Show Gist options
  • Save ikks/1793858 to your computer and use it in GitHub Desktop.
Save ikks/1793858 to your computer and use it in GitHub Desktop.
Haystack search indexes sample
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