Skip to content

Commit

Permalink
feat: TM search filter by app/licence (dvsa/olcs-backend#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
wadedvsa authored Apr 17, 2024
1 parent 42ec4db commit f701c59
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
11 changes: 11 additions & 0 deletions app/api/module/Olcs/Db/src/Service/Search/QueryTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
class QueryTemplate extends Query
{
public const FILTER_TYPE_DYNAMIC = 'DYNAMIC';
public const FILTER_TYPE_FIXED = 'FIXED';
public const FILTER_TYPE_BOOLEAN = 'BOOLEAN';

public function __construct(
Expand Down Expand Up @@ -69,6 +70,16 @@ private function applyFilters(array $filters, array $filterTypes): self
}

switch ($filterTypes[$field]) {
case self::FILTER_TYPE_FIXED:
$fields = explode('|', $field);
foreach ($fields as $subField) {
$this->_params['query']['bool']['must']['bool']['must']['bool']['should'][] = [
'terms' => [
$subField => explode('|', $value),
],
];
}
break;
case self::FILTER_TYPE_DYNAMIC:
$this->_params['query']['bool']['filter'][] = [
'term' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,13 @@ public function queryTemplateDataProvider()
'field_1' => 'value1',
'field_2' => 'value2',
'field_3' => '0',
'field_4|field_5' => 'value3|value4',
],
[
'field_1' => 'DYNAMIC',
'field_2' => 'DYNAMIC',
'field_3' => 'BOOLEAN',
'field_4|field_5' => 'FIXED'
],
[],
[
Expand All @@ -241,7 +243,23 @@ public function queryTemplateDataProvider()
'field_1' => 'SMITH'
]
]
]
],
'must' => [
'bool' => [
'should' => [
[
'terms' => [
'field_4' => ['value3', 'value4'],
]
],
[
'terms' => [
'field_5' => ['value3', 'value4'],
]
],
],
],
],
]
],
'filter' => [
Expand Down

0 comments on commit f701c59

Please sign in to comment.