From bb62779555f19edd3add3456d7c33c433a20ee4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20W=C3=B3js?= Date: Thu, 28 Sep 2023 11:49:38 +0200 Subject: [PATCH 1/2] IBX-6649: Added support for spell checking --- src/lib/QueryType/SearchQueryType.php | 5 +++++ src/lib/View/SearchViewBuilder.php | 1 + 2 files changed, 6 insertions(+) diff --git a/src/lib/QueryType/SearchQueryType.php b/src/lib/QueryType/SearchQueryType.php index 7bca8cc..0a205f6 100644 --- a/src/lib/QueryType/SearchQueryType.php +++ b/src/lib/QueryType/SearchQueryType.php @@ -15,6 +15,7 @@ use Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\SectionTermAggregation; use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; use Ibexa\Contracts\Core\Repository\Values\Content\Query\SortClause\ContentId; +use Ibexa\Contracts\Core\Repository\Values\Content\Query\Spellcheck; use Ibexa\Contracts\Core\Repository\Values\User\User; use Ibexa\Contracts\Search\SortingDefinition\SortingDefinitionRegistryInterface; use Ibexa\Core\QueryType\OptionsResolverBasedQueryType; @@ -42,6 +43,10 @@ protected function doGetQuery(array $parameters): Query $query = new Query(); if (null !== $searchData->getQuery()) { $query->query = new Criterion\FullText($searchData->getQuery()); + + if ($this->searchService->supports(SearchService::CAPABILITY_SPELLCHECK)) { + $query->spellcheck = new Spellcheck($searchData->getQuery()); + } } $criteria = $this->buildCriteria($searchData); diff --git a/src/lib/View/SearchViewBuilder.php b/src/lib/View/SearchViewBuilder.php index 702b918..de7b984 100644 --- a/src/lib/View/SearchViewBuilder.php +++ b/src/lib/View/SearchViewBuilder.php @@ -82,6 +82,7 @@ public function buildView(array $parameters): SearchView 'results' => $this->pagerSearchContentToDataMapper->map($pagerfanta), 'pager' => $pagerfanta, 'aggregations' => $adapter->getAggregations(), + 'spellcheck' => $adapter->getSpellcheck(), ]); } From 126ffceb4e91d75cb139eb6b6a511b4013340ba0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20W=C3=B3js?= Date: Tue, 5 Dec 2023 13:44:45 +0100 Subject: [PATCH 2/2] Applied core review suggestions --- src/lib/View/SearchViewBuilder.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/View/SearchViewBuilder.php b/src/lib/View/SearchViewBuilder.php index de7b984..79a22f6 100644 --- a/src/lib/View/SearchViewBuilder.php +++ b/src/lib/View/SearchViewBuilder.php @@ -78,8 +78,10 @@ public function buildView(array $parameters): SearchView $pagerfanta->setMaxPerPage($data->getLimit()); $pagerfanta->setCurrentPage(min($data->getPage(), $pagerfanta->getNbPages())); + $results = $this->pagerSearchContentToDataMapper->map($pagerfanta); + $view->addParameters([ - 'results' => $this->pagerSearchContentToDataMapper->map($pagerfanta), + 'results' => $results, 'pager' => $pagerfanta, 'aggregations' => $adapter->getAggregations(), 'spellcheck' => $adapter->getSpellcheck(),