Better search

This commit is contained in:
Robin Champenois 2021-06-28 23:25:16 +02:00
parent 46eacc94da
commit c40a91fb67

View file

@ -82,7 +82,6 @@ def cherche(**kwargs):
'type_stage', 'type_stage',
'niveau_scol', 'niveau_scol',
'structure', 'structure',
'date_*',
"lieux.*^2", "lieux.*^2",
"auteur.nom^2", "auteur.nom^2",
"thematiques^2", "thematiques^2",
@ -146,22 +145,30 @@ def cherche(**kwargs):
if field_relevant('type_lieu'): if field_relevant('type_lieu'):
filtres &= Q(lieux__type_lieu=kwargs["type_lieu"]) filtres &= Q(lieux__type_lieu=kwargs["type_lieu"])
# Tri
# Application tri = "pertinence"
resultat = Stage.objects
if USE_ELASTICSEARCH and use_dsl:
resultat = dsl.to_queryset(True)
#print(filtres)
resultat = resultat.filter(filtres).distinct()
tri = 'pertinence'
if not use_dsl:
kwargs['tri'] = '-date_maj'
if field_relevant('tri') and kwargs['tri'] in ['-date_maj']: if field_relevant('tri') and kwargs['tri'] in ['-date_maj']:
tri = kwargs['tri'] tri = kwargs['tri']
resultat = resultat.order_by(tri)
if not use_dsl:
tri = "-date_maj"
# Application
resultat = Stage.objects.filter(filtres).distinct()
if USE_ELASTICSEARCH and use_dsl:
dls_res = [s.meta.id for s in dsl.scan()[:50]]
resultat = resultat.filter(id__in=dsl_res)
if tri == "pertinence":
resultat = resultat.order_by(
Case(
*[When(pk=pk, then=pos) for pos, pk in enumerate(pks)]
)
)
else:
resultat = resultat.order_by(tri)
return resultat, tri return resultat, tri