Skip to content

Instantly share code, notes, and snippets.

@toastdriven
Created April 25, 2011 17:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toastdriven/940847 to your computer and use it in GitHub Desktop.
Save toastdriven/940847 to your computer and use it in GitHub Desktop.
import datetime
from haystack import indexes
from haystack import site
from myapp.models import Note
class NoteIndex(indexes.SearchIndex):
text = indexes.CharField(document=True, use_template=True)
author = indexes.CharField(model_attr='user')
pub_date = indexes.DateTimeField(model_attr='pub_date')
# We add this for autocomplete.
content_auto = indexes.EdgeNgramField()
def get_queryset(self):
"""Used when the entire index for model is updated."""
return Note.objects.filter(pub_date__lte=datetime.datetime.now())
def prepare(self, obj):
data = super(NoteIndex, self).prepare(obj)
data['content_auto'] = data['text']
return data
site.register(Note, NoteIndex)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment