Skip to content

Instantly share code, notes, and snippets.

@catalanojuan
Created June 30, 2012 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save catalanojuan/605788cd7a73837f7b1f to your computer and use it in GitHub Desktop.
Save catalanojuan/605788cd7a73837f7b1f to your computer and use it in GitHub Desktop.
Index
# -*- coding: UTF-8 -*-
from haystack import indexes
from ewebapp.apps.articles.models import Article, Category
from ewebapp.apps.utils.strings import remove_accents
class ArticleIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
title = indexes.CharField(model_attr='title')
keywords = indexes.MultiValueField()
suggestions = indexes.FacetCharField()
def get_model(self):
return Article
def prepare(self, obj):
prepared_data = super(ArticleIndex, self).prepare(obj)
prepared_data['suggestions'] = prepared_data['text']
return prepared_data
def prepare_text(self, obj):
if not obj.body:
return u''
return remove_accents(obj.body.lower())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment