Analyzer + plus de champs

This commit is contained in:
Evarin 2017-06-17 13:59:41 +02:00
parent 542363aefd
commit 2d8c6515c4

View file

@ -1,6 +1,10 @@
from django_elasticsearch_dsl import DocType, Index, fields from django_elasticsearch_dsl import DocType, Index, fields
from elasticsearch_dsl import analyzer, token_filter, tokenizer from elasticsearch_dsl import analyzer, token_filter, tokenizer
from .models import Stage, AvisStage, AvisLieu from .models import Stage, AvisStage, AvisLieu
from .statics import PAYS_OPTIONS
PAYS_DICT = dict(PAYS_OPTIONS)
stage = Index('stages') stage = Index('stages')
stage.settings( stage.settings(
@ -9,9 +13,10 @@ stage.settings(
) )
text_analyzer = analyzer( text_analyzer = analyzer(
'texte', 'default',
tokenizer="standard", tokenizer="standard",
filters=['lowercase', 'standard', 'asciifolding', filter=['lowercase', 'standard', 'asciifolding',
token_filter("frstop", type="stop", stopwords="_french_"),
token_filter("frsnow", type="snowball", language="French")]) token_filter("frsnow", type="snowball", language="French")])
stage.analyzer(text_analyzer) stage.analyzer(text_analyzer)
@ -19,8 +24,12 @@ stage.analyzer(text_analyzer)
class StageDocument(DocType): class StageDocument(DocType):
lieux = fields.ObjectField(properties={ lieux = fields.ObjectField(properties={
'nom': fields.StringField(), 'nom': fields.StringField(),
'ville': fields.StringField(),
'pays': fields.StringField(), 'pays': fields.StringField(),
}) })
auteur = fields.ObjectField(properties={
'nom': fields.StringField(),
})
thematiques = fields.StringField() thematiques = fields.StringField()
matieres = fields.StringField() matieres = fields.StringField()
@ -31,7 +40,9 @@ class StageDocument(DocType):
'encadrants', 'encadrants',
'type_stage', 'type_stage',
'niveau_scol', 'niveau_scol',
'structure' 'structure',
'date_debut',
'date_fin'
] ]
def prepare_thematiques(self, instance): def prepare_thematiques(self, instance):
@ -45,3 +56,17 @@ class StageDocument(DocType):
def prepare_type_stage(self, instance): def prepare_type_stage(self, instance):
return instance.type_stage_fancy 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