diff --git a/Classes/Common/QueryParamsBuilder.php b/Classes/Common/QueryParamsBuilder.php index e165cee..1593fb7 100644 --- a/Classes/Common/QueryParamsBuilder.php +++ b/Classes/Common/QueryParamsBuilder.php @@ -12,6 +12,7 @@ class QueryParamsBuilder public static function createElasticParams(array $searchParams): array { $extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('liszt_bibliography'); + $commonConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('liszt_common'); $bibIndex = $extConf['elasticIndexName']; $aggs = []; // TYPOSCRIPT stuff here @@ -128,9 +129,81 @@ public static function createElasticParams(array $searchParams): array ] ]; } + if (isset($searchParams['searchParamsPage']) && $searchParams['searchParamsPage'] !== "") { + $params['from'] = ($searchParams['searchParamsPage'] - 1) * $commonConf['itemsPerPage']; + } return $params; } + public static function createCountParams(array $searchParams): array + { + + $extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('liszt_bibliography'); + $bibIndex = $extConf['elasticIndexName']; + + $params = [ + 'index' => $bibIndex, + 'body' => [ ] + ]; + if (!isset($searchParams['searchText']) || $searchParams['searchText'] == '') { + $params['body']['query'] = [ + 'bool' => [ + 'must' => [[ + 'match_all' => new \stdClass() + ]] + ] + ]; + } else { + // search in field "fulltext" exakt phrase match boost over all words must contain + $params['body']['query'] = [ + 'bool' => [ + 'should' => [ + [ + 'match_phrase' => [ + 'tx_lisztcommon_searchable' => [ + 'query' => $searchParams['searchText'], + 'boost' => 2.0 // boosting for exakt phrases + ] + ] + ], + [ + 'query_string' => [ + 'query' => $searchParams['searchText'], + 'fields' => ['fulltext'], + 'default_operator' => 'AND' + ] + ] + ] + ] + ]; + } + + // Todo: automate the creation of parameters + if (isset($searchParams['f_itemType']) && $searchParams['f_itemType'] !== "") { + $params['body']['query']['bool']['filter'][] = ['term' => ['itemType.keyword' => $searchParams['f_itemType']]]; + } + if (isset($searchParams['f_place']) && $searchParams['f_place'] !== "") { + $params['body']['query']['bool']['filter'][] = ['term' => ['place.keyword' => $searchParams['f_place']]]; + } + if (isset($searchParams['f_date']) && $searchParams['f_date'] !== "") { + $params['body']['query']['bool']['filter'][] = ['term' => ['date.keyword' => $searchParams['f_date']]]; + } + // filter creators name, Todo: its not a filter query because they need 100% match (with spaces from f_creators_name) + // better would be to build the field 'fullName' at build time with PHP? + if (isset($searchParams['f_creators_name']) && $searchParams['f_creators_name'] !== "") { + $params['body']['query']['bool']['must'][] = [ + 'nested' => [ + 'path' => 'creators', + 'query' => [ + 'match' => [ + 'creators.fullName' => $searchParams['f_creators_name'] + ] + ] + ] + ]; + } + return $params; + } } diff --git a/Classes/Services/ElasticSearchService.php b/Classes/Services/ElasticSearchService.php index f881bf7..d6671e1 100644 --- a/Classes/Services/ElasticSearchService.php +++ b/Classes/Services/ElasticSearchService.php @@ -51,4 +51,12 @@ public function search($searchParams): Collection return new Collection($response->asArray()); } + public function count($searchParams): int + { + $this->init(); + $this->params = QueryParamsBuilder::createCountParams($searchParams); + $response = $this->client->count($this->params); + return $response['count']; + } + } diff --git a/Classes/ViewHelpers/SearchParamsViewHelper.php b/Classes/ViewHelpers/SearchParamsViewHelper.php index 81ad0ff..10b7fc2 100644 --- a/Classes/ViewHelpers/SearchParamsViewHelper.php +++ b/Classes/ViewHelpers/SearchParamsViewHelper.php @@ -32,13 +32,15 @@ public static function renderStatic( } // Convert the array to a string formatted as {key: 'value', key2: 'value2'} + /* $formattedParams = []; foreach ($searchParamsArray as $paramKey => $paramValue) { $formattedParams[] = "{$paramKey}: '" . $paramValue . "'"; } + */ // return '{' . implode(', ', $formattedParams) . '}'; - return ['searchParams' => $searchParamsArray]; + return ['searchParams' => $searchParamsArray]; } } diff --git a/Resources/Private/Partials/FilterBlock.html b/Resources/Private/Partials/FilterBlock.html index cdec976..29c4fb8 100644 --- a/Resources/Private/Partials/FilterBlock.html +++ b/Resources/Private/Partials/FilterBlock.html @@ -4,18 +4,20 @@

{key}

f_{key} + {lc:searchParams(action: 'remove', searchParamsArray: searchParams, key: 'searchParamsPage')} + {paramsRemovePage.searchParams}