Created
April 25, 2011 17:16
-
-
Save toastdriven/940847 to your computer and use it in GitHub Desktop.
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
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