experiENS/avisstage/documents.py
2017-06-16 00:17:25 +02:00

47 lines
1.3 KiB
Python

from django_elasticsearch_dsl import DocType, Index, fields
from elasticsearch_dsl import analyzer, token_filter, tokenizer
from .models import Stage, AvisStage, AvisLieu
stage = Index('stages')
stage.settings(
number_of_shards=1,
number_of_replicas=0
)
text_analyzer = analyzer(
'texte',
tokenizer="standard",
filters=['lowercase', 'standard', 'asciifolding',
token_filter("frsnow", type="snowball", language="French")])
stage.analyzer(text_analyzer)
@stage.doc_type
class StageDocument(DocType):
lieux = fields.ObjectField(properties={
'nom': fields.StringField(),
'pays': fields.StringField(),
})
thematiques = fields.StringField()
matieres = fields.StringField()
class Meta:
model = Stage
fields = [
'sujet',
'encadrants',
'type_stage',
'niveau_scol',
'structure'
]
def prepare_thematiques(self, instance):
return ", ".join(instance.thematiques.all().values_list("name", flat=True))
def prepare_matieres(self, instance):
return ", ".join(instance.matieres.all().values_list("nom", flat=True))
def prepare_niveau_scol(self, instance):
return instance.get_niveau_scol_display()
def prepare_type_stage(self, instance):
return instance.type_stage_fancy