Analyzer + plus de champs
This commit is contained in:
parent
542363aefd
commit
2d8c6515c4
1 changed files with 28 additions and 3 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue