# coding: utf-8

from __future__ import unicode_literals
from django.conf import settings
from django.utils import translation
from haystack.indexes import SearchIndex, Indexable, CharField, \
    EdgeNgramField, DateField
from .models import Oeuvre, Source, Individu, Lieu, Evenement, Partie, \
    Profession


class CommonSearchIndex(SearchIndex):
    text = CharField(document=True, use_template=True)
    suggestions = CharField()

    def prepare(self, obj):
        translation.activate(settings.LANGUAGE_CODE)
        prepared_data = super(CommonSearchIndex, self).prepare(obj)
        prepared_data['suggestions'] = prepared_data['text']
        return prepared_data    


class PolymorphicCommonSearchIndex(CommonSearchIndex):
    def index_queryset(self):
        return super(PolymorphicCommonSearchIndex,
                     self).index_queryset().non_polymorphic()


class OeuvreIndex(CommonSearchIndex, Indexable):
    content_auto = EdgeNgramField(model_attr='titre_html')

    def get_model(self):
        return Oeuvre

    def prepare(self, obj):
        prepared_data = super(OeuvreIndex, self).prepare(obj)
        prepared_data['boost'] = 1.0 / (obj.level + 1)
        return prepared_data


class SourceIndex(CommonSearchIndex, Indexable):
    date = DateField(model_attr='date')

    def get_model(self):
        return Source


class IndividuIndex(CommonSearchIndex, Indexable):
    content_auto = EdgeNgramField(model_attr='html')

    def get_model(self):
        return Individu


class LieuIndex(PolymorphicCommonSearchIndex, Indexable):
    content_auto = EdgeNgramField(model_attr='html')

    def get_model(self):
        return Lieu


class EvenementIndex(CommonSearchIndex, Indexable):
    def get_model(self):
        return Evenement


class PartieIndex(PolymorphicCommonSearchIndex, Indexable):
    content_auto = EdgeNgramField(model_attr='html')

    def get_model(self):
        return Partie


class ProfessionIndex(CommonSearchIndex, Indexable):
    content_auto = EdgeNgramField(model_attr='html')

    def get_model(self):
        return Profession

@@ -753,24 +753,41 @@
 ueryset(self
+, *args, **kwargs
 ):%0A        r
@@ -870,16 +870,31 @@
 ueryset(
+*args, **kwargs
 ).non_po

Corrige les arguments de index_queryset.