Skip to content

Commit

Permalink
Change fields for search and fix deepspaceobjects mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephane MEAUDRE committed Mar 25, 2024
1 parent 9344b67 commit 2c70e10
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
"type": "keyword",
"normalizer": "lowercase_normalizer"
}
}
},
Expand Down Expand Up @@ -115,7 +116,8 @@
"fielddata": true,
"fields": {
"keyword": {
"type": "keyword"
"type": "keyword",
"normalizer": "lowercase_normalizer"
}
}
},
Expand All @@ -126,7 +128,8 @@
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
"type": "keyword",
"normalizer": "lowercase_normalizer"
}
}
},
Expand Down
29 changes: 24 additions & 5 deletions api/src/Repository/ElasticsearchRepository/DsoRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,25 +100,46 @@ public function getRandomDso(int $offset, int $limit): array
// GetDsoCatalogs
public function getDsosFiltersBy(array $filters, int $offset, int $limit): array
{

$fieldsFilters = [
'query' => [
'bool' => [
'must' =>
array_map(function(string $field, string $value): array {
return [
'term' => [$field => $value]
];
if ('magnitude' !== $field) {
$field = self::$listAggregates[$field]['field'];
$value = strtolower($value);
return [
'term' => [$field => $value]
];
} else {
$keyRange = array_search($value, array_column(self::$listAggregatesRange[$field]['ranges'], 'key'), true);
$range = self::$listAggregatesRange[$field]['ranges'][$keyRange];
if (array_key_exists('to', $range)) {
$paramRange['lte'] = $range['to'];
}
if (array_key_exists('from', $range)) {
$paramRange['gte'] = $range['from'];
}
$field = self::$listAggregatesRange[$field]['field'];
return [
'range' => [$field => $paramRange]
];
}

}, array_keys($filters), $filters)
]
]
];

$sort = [
'sort' => [
['order' => 'asc']
],
'from' => $offset,
'size' => $limit
];

$aggregates = [
'aggs' =>
array_merge(
Expand All @@ -145,13 +166,11 @@ public function getDsosFiltersBy(array $filters, int $offset, int $limit): array
)
];


$param = [
'index' => $this->getIndex(),
'body' => array_merge($fieldsFilters, $sort, $aggregates),
];


$results = $this->client->search($param);
['total' => $total, 'hits' => $hits] = $results['hits'];
['aggregations' => $aggregations] = $results;
Expand Down
5 changes: 0 additions & 5 deletions api/src/State/DsoStateProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ public function provide(
return in_array($paramKey, $authorizedQueryParams);
}, ARRAY_FILTER_USE_KEY);

if (array_key_exists('constellation', $filters)) {
$filters['constId'] = $filters['constellation'];
unset($filters['constellation']);
}

[
'total' => $total,
'documents' => $documents,
Expand Down

0 comments on commit 2c70e10

Please sign in to comment.