secret
Created

Index

  • Download Gist
search_index.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
# -*- 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())

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.