X-Git-Url: https://git.mdrn.pl/django-migdal.git/blobdiff_plain/734cd58d3f12c5397b42c1ae122c947500386014..865f2999a89cbe23c75c82d617b9c1ac4c55604e:/migdal/search_indexes.py diff --git a/migdal/search_indexes.py b/migdal/search_indexes.py index 27169f3..fc35cff 100644 --- a/migdal/search_indexes.py +++ b/migdal/search_indexes.py @@ -1,27 +1,34 @@ -import datetime +# -*- coding: utf-8 -*- +# This file is part of PrawoKultury, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# from django.conf import settings from haystack import indexes -from fnpdjango.utils.models.translation import add_translatable_index +from fnpdjango.utils.models.translation import add_translatable_index, localize_field from migdal.models import Entry -class EntryIndex(indexes.RealTimeSearchIndex, indexes.Indexable): +class EntryIndex(indexes.SearchIndex, indexes.Indexable): + text = indexes.CharField( + null=True, + model_attr=localize_field('body', settings.LANGUAGE_CODE), + document=True) date = indexes.DateTimeField(indexed=True, model_attr="date") author = indexes.CharField(model_attr="author") def get_model(self): return Entry - def index_queryset(self): - """Used when the entire index for model is updated.""" - return self.get_model().objects.all() # filter(date__lte=datetime.datetime.now()) - add_translatable_index(EntryIndex, { 'title': indexes.CharField(null=True), 'lead': indexes.CharField(null=True), - 'body': indexes.CharField(null=True) }) - -getattr(EntryIndex, "body_%s" % settings.LANGUAGE_CODE).document = True +add_translatable_index(EntryIndex, { + 'title': indexes.CharField(null=True), + 'lead': indexes.CharField(null=True), + 'body': indexes.CharField(null=True) + }, + (lang for lang in settings.LANGUAGES if lang[0] != settings.LANGUAGE_CODE) +)