From 2d8c6515c4f5a6b5fda4b41351e7ccef21df6cc4 Mon Sep 17 00:00:00 2001 From: Evarin Date: Sat, 17 Jun 2017 13:59:41 +0200 Subject: [PATCH] Analyzer + plus de champs --- avisstage/documents.py | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/avisstage/documents.py b/avisstage/documents.py index 6886073..3995b3c 100644 --- a/avisstage/documents.py +++ b/avisstage/documents.py @@ -1,6 +1,10 @@ from django_elasticsearch_dsl import DocType, Index, fields from elasticsearch_dsl import analyzer, token_filter, tokenizer + from .models import Stage, AvisStage, AvisLieu +from .statics import PAYS_OPTIONS + +PAYS_DICT = dict(PAYS_OPTIONS) stage = Index('stages') stage.settings( @@ -9,9 +13,10 @@ stage.settings( ) text_analyzer = analyzer( - 'texte', + 'default', tokenizer="standard", - filters=['lowercase', 'standard', 'asciifolding', + filter=['lowercase', 'standard', 'asciifolding', + token_filter("frstop", type="stop", stopwords="_french_"), token_filter("frsnow", type="snowball", language="French")]) stage.analyzer(text_analyzer) @@ -19,8 +24,12 @@ stage.analyzer(text_analyzer) class StageDocument(DocType): lieux = fields.ObjectField(properties={ 'nom': fields.StringField(), + 'ville': fields.StringField(), 'pays': fields.StringField(), }) + auteur = fields.ObjectField(properties={ + 'nom': fields.StringField(), + }) thematiques = fields.StringField() matieres = fields.StringField() @@ -31,7 +40,9 @@ class StageDocument(DocType): 'encadrants', 'type_stage', 'niveau_scol', - 'structure' + 'structure', + 'date_debut', + 'date_fin' ] def prepare_thematiques(self, instance): @@ -45,3 +56,17 @@ class StageDocument(DocType): def prepare_type_stage(self, instance): return instance.type_stage_fancy + + def prepare_date_fin(self, instance): + return instance.date_fin.year + + def prepare_date_debut(self, instance): + return instance.date_debut.year + + # Hook pour l'affichage des noms de pays + def prepare(self, instance): + data = super(StageDocument, self).prepare(instance) + + for lieu in data['lieux']: + lieu['pays'] = PAYS_DICT[lieu['pays']] + return data