X-Git-Url: https://git.mdrn.pl/prawokultury.git/blobdiff_plain/fb2d5b78a90d3042f7eb5e8e419fcbe6e62fd00d..8debbb6ca3804057fe0458a6c2ac579bc9e91162:/migdal/search_indexes.py?ds=sidebyside diff --git a/migdal/search_indexes.py b/migdal/search_indexes.py index 333899f..63acc1c 100644 --- a/migdal/search_indexes.py +++ b/migdal/search_indexes.py @@ -2,11 +2,10 @@ from django.conf import settings import datetime from haystack import indexes from migdal.models import Entry +from migdal.helpers import add_translatable_index -from copy import copy - -class EntryIndex(indexes.SearchIndex, indexes.Indexable): +class EntryIndex(indexes.RealTimeSearchIndex, indexes.Indexable): date = indexes.DateTimeField(indexed=True, model_attr="date") author = indexes.CharField(model_attr="author") @@ -18,24 +17,10 @@ class EntryIndex(indexes.SearchIndex, indexes.Indexable): return self.get_model().objects.filter(date__lte=datetime.datetime.now()) -def add_translatable(index_class, fields, languages=None): - """Adds some translatable fields to a search index, and a getter.""" - if languages is None: - languages = settings.LANGUAGES - for name, field in fields.items(): - for lang_code, lang_name in languages: - new_field = copy(field) - fname = "%s_%s" % (name, lang_code) - new_field.index_fieldname = fname - new_field.model_attr = fname - setattr(index_class, fname, new_field) - index_class.fields[fname] = new_field - - -add_translatable(EntryIndex, { - 'title': indexes.CharField(indexed=True, document=False), - 'lead': indexes.CharField(indexed=True, document=False), - 'body': indexes.CharField(indexed=True, document=False) +add_translatable_index(EntryIndex, { + 'title': indexes.CharField(), + 'lead': indexes.CharField(), + 'body': indexes.CharField() })