2017-05-22 23:36:14 +02:00
|
|
|
from django_elasticsearch_dsl import DocType, Index, fields
|
2017-06-16 00:17:25 +02:00
|
|
|
from elasticsearch_dsl import analyzer, token_filter, tokenizer
|
2017-05-22 23:36:14 +02:00
|
|
|
from .models import Stage, AvisStage, AvisLieu
|
|
|
|
|
|
|
|
stage = Index('stages')
|
|
|
|
stage.settings(
|
|
|
|
number_of_shards=1,
|
|
|
|
number_of_replicas=0
|
|
|
|
)
|
2017-06-16 00:17:25 +02:00
|
|
|
|
|
|
|
text_analyzer = analyzer(
|
|
|
|
'texte',
|
|
|
|
tokenizer="standard",
|
|
|
|
filters=['lowercase', 'standard', 'asciifolding',
|
|
|
|
token_filter("frsnow", type="snowball", language="French")])
|
|
|
|
stage.analyzer(text_analyzer)
|
2017-05-22 23:36:14 +02:00
|
|
|
|
|
|
|
@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):
|
2017-06-16 00:17:25 +02:00
|
|
|
return ", ".join(instance.thematiques.all().values_list("name", flat=True))
|
2017-05-22 23:36:14 +02:00
|
|
|
|
|
|
|
def prepare_matieres(self, instance):
|
2017-06-16 00:17:25 +02:00
|
|
|
return ", ".join(instance.matieres.all().values_list("nom", flat=True))
|
2017-05-22 23:36:14 +02:00
|
|
|
|
|
|
|
def prepare_niveau_scol(self, instance):
|
|
|
|
return instance.get_niveau_scol_display()
|
|
|
|
|
|
|
|
def prepare_type_stage(self, instance):
|
|
|
|
return instance.type_stage_fancy
|