simplify esFolderSearch

This commit is contained in:
Jérémy Munsch 2022-07-25 12:11:35 +02:00
parent 50a5aa5604
commit e107cfd337
No known key found for this signature in database
GPG key ID: 18361AF3BFEC0FEC

View file

@ -840,6 +840,14 @@ class MediaController extends Controller
/** @var \App\Models\User */
$user = auth()->user();
if ($isDepot) {
// * Dossier dépôt
$esMust = array_merge($esMust, [[
\array_undot(['match.dossier_id' => $dossier->id])
]]);
return;
}
if (!$dossier) {
if ($request->folder === -1) {
// * Recherche globale .
@ -860,45 +868,42 @@ class MediaController extends Controller
\array_undot(['match.statut' => config('services.statut.public')]),
\array_undot(['match.created_by' => $user->id])
]);
} elseif (!$isDepot) {
// * Dossier classic .
$esMust = array_merge($esMust, [[
return;
} //end if
// * Dossier classic .
$esMust = array_merge($esMust, [[
\array_undot([
'bool.must' => [
\array_undot(['match.sujet_id' => $sujet->codeSujet]),
\array_undot(['match.dossier_id' => $dossier->id]),
]
])
]]);
if (!$user->hasRole(config('roles.const.ADMIN'))) {
$esFilters = array_merge($esFilters, [
\array_undot([
'bool.must' => [
\array_undot(['match.sujet_id' => $sujet->codeSujet]),
\array_undot(['match.dossier_id' => $dossier->id]),
]
'bool.should' => [
\array_undot([
'bool.must_not' => [[
\array_undot([
'term.statut.value' => config('services.statut.brouillon'),
'term.statut.boost' => 1.0
])
]],
'bool.adjust_pure_negative' => true,
'bool.boost' => 1.0
]),
\array_undot([
'term.created_by.value' => $user->id,
'term.created_by.boost' => 1.0
])
],
'bool.adjust_pure_negative' => true,
'bool.boost' => 1.0
])
]]);
if (!$user->hasRole(config('roles.const.ADMIN'))) {
$esFilters = array_merge($esFilters, [
\array_undot([
'bool.should' => [
\array_undot([
'bool.must_not' => [[
\array_undot([
'term.statut.value' => config('services.statut.brouillon'),
'term.statut.boost' => 1.0
])
]],
'bool.adjust_pure_negative' => true,
'bool.boost' => 1.0
]),
\array_undot([
'term.created_by.value' => $user->id,
'term.created_by.boost' => 1.0
])
],
'bool.adjust_pure_negative' => true,
'bool.boost' => 1.0
])
]);
} //end if
} else {
// * Dossier dépôt
$esMust = array_merge($esMust, [[
\array_undot(['match.dossier_id' => $dossier->id])
]]);
]);
} //end if
}