Skip to content

Commit 9da2507

Browse files
committed
1284: Use elastic search score for result sorting
1 parent c3def0e commit 9da2507

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/Service/ElasticSearch/ElasticSearchIndex.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,17 @@ private function getTotalHits(array $data): int
268268
*/
269269
private function getSort(string $indexName): array
270270
{
271+
// Translates a string or int into the corresponding Enum case, if any.
272+
// If there is no matching case defined, it will return null.
271273
$indexName = IndexNames::tryFrom($indexName);
272274

273275
return match ($indexName) {
274276
IndexNames::Events => [
275-
'title.keyword' => [
276-
'order' => 'asc',
277+
'_score',
278+
[
279+
'title.keyword' => [
280+
'order' => 'asc',
281+
],
277282
],
278283
],
279284
IndexNames::DailyOccurrences, IndexNames::Occurrences => [
@@ -282,17 +287,17 @@ private function getSort(string $indexName): array
282287
'format' => 'strict_date_optional_time_nanos',
283288
],
284289
],
285-
IndexNames::Locations, IndexNames::Organizations => [
286-
'name.keyword' => [
287-
'order' => 'asc',
288-
],
289-
],
290-
IndexNames::Tags, IndexNames::Vocabularies => [
291-
'name' => [
292-
'order' => 'asc',
290+
IndexNames::Tags, IndexNames::Vocabularies,IndexNames::Locations, IndexNames::Organizations => [
291+
'_score',
292+
[
293+
'name.keyword' => [
294+
'order' => 'asc',
295+
],
293296
],
294297
],
295-
default => []
298+
default => [
299+
'_score',
300+
]
296301
};
297302
}
298303
}

0 commit comments

Comments
 (0)