From 51eabd480997178f1ab36ae5ba767b2e56c5a76b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20S=C4=85gol?= Date: Fri, 22 Mar 2024 12:21:46 +0100 Subject: [PATCH] [TASK] Allow searching only inside single manual scope This commit follows up on the changes made in the Rendering Guides repository, where a new option for searching within a single manual scope was introduced. These changes implement the same functionality for the search results page: - The search form has been updated to display a list of search scopes (All | Current). - The selected scope is now passed as a filter to the Elasticsearch query to match against manual_slug. - If a scope is selected, facets are hidden on the search results page. - Styles have been updated to the latest version. - Several improvements have been made to the templates. --- config/services.yaml | 16 ++++++---------- src/Controller/SearchController.php | 2 +- src/Dto/SearchDemand.php | 15 +++++++++++++-- src/Twig/AppExtension.php | 6 +++--- templates/partial/aggregations.html.twig | 6 +++--- templates/partial/base/breadcrumbs.html.twig | 2 +- templates/partial/base/page_header.html.twig | 14 +++++++++----- templates/partial/paginator.html.twig | 5 +++-- templates/search/search.html.twig | 18 +++++++++--------- tests/Unit/Dto/SearchDemandTest.php | 19 +++++++++++++++++-- 10 files changed, 65 insertions(+), 38 deletions(-) diff --git a/config/services.yaml b/config/services.yaml index c789170..ad3ba9f 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -16,20 +16,16 @@ parameters: assets: css: header: - - 'https://typo3.azureedge.net/typo3documentation/theme/sphinx_typo3_theme/4.9.0/css/theme.css' - - 'https://typo3.azureedge.net/typo3documentation/theme/sphinx_typo3_theme/4.9.0/css/webfonts.css' - - 'https://typo3.azureedge.net/typo3documentation/theme/sphinx_typo3_theme/4.9.0/css/fontawesome.css' + - 'https://typo3.azureedge.net/typo3documentation/theme/typo3-docs-theme/0.2.32/css/theme.css' footer: js: header: + - 'https://typo3.azureedge.net/typo3infrastructure/universe/dist/webcomponents-loader.js' + - 'https://typo3.azureedge.net/typo3infrastructure/universe/dist/typo3-universe.js' footer: - - 'https://typo3.azureedge.net/typo3documentation/theme/sphinx_typo3_theme/4.9.0/js/jquery.min.js' - - 'https://typo3.azureedge.net/typo3documentation/theme/sphinx_typo3_theme/4.9.0/js/underscore.min.js' - - 'https://typo3.azureedge.net/typo3documentation/theme/sphinx_typo3_theme/4.9.0/js/doctools.min.js' - - 'https://typo3.azureedge.net/typo3documentation/theme/sphinx_typo3_theme/4.9.0/js/popper.min.js' - - 'https://typo3.azureedge.net/typo3documentation/theme/sphinx_typo3_theme/4.9.0/js/bootstrap.min.js' - - 'https://typo3.azureedge.net/typo3documentation/theme/sphinx_typo3_theme/4.9.0/js/autocomplete.min.js' - - 'https://typo3.azureedge.net/typo3documentation/theme/sphinx_typo3_theme/4.9.0/js/theme.min.js' + - 'https://typo3.azureedge.net/typo3documentation/theme/typo3-docs-theme/0.2.32/js/popper.min.js' + - 'https://typo3.azureedge.net/typo3documentation/theme/typo3-docs-theme/0.2.32/js/bootstrap.min.js' + - 'https://typo3.azureedge.net/typo3documentation/theme/typo3-docs-theme/0.2.32/js/theme.min.js' services: # default configuration for services in *this* file diff --git a/src/Controller/SearchController.php b/src/Controller/SearchController.php index 646b04d..95a6492 100644 --- a/src/Controller/SearchController.php +++ b/src/Controller/SearchController.php @@ -17,7 +17,6 @@ public function __construct(private readonly ElasticRepository $elasticRepositor { } - /** * @return Response */ @@ -41,6 +40,7 @@ public function search(Request $request): Response return $this->render('search/search.html.twig', [ 'q' => $searchDemand->getQuery(), + 'searchScope' => $searchDemand->getScope(), 'filters' => $request->get('filters', []), 'results' => $this->elasticRepository->findByQuery($searchDemand), ]); diff --git a/src/Dto/SearchDemand.php b/src/Dto/SearchDemand.php index 64d9f34..4aa8044 100644 --- a/src/Dto/SearchDemand.php +++ b/src/Dto/SearchDemand.php @@ -6,7 +6,7 @@ readonly class SearchDemand { - public function __construct(private string $query, private int $page, private array $filters) + public function __construct(private string $query, private string $scope, private int $page, private array $filters) { } @@ -34,7 +34,13 @@ public static function createFromRequest(Request $request): SearchDemand $page = (int)$request->query->get('page', '1'); $query = $request->query->get('q', ''); - return new self($query, max($page, 1), $filters); + // scope points to given manual version and language + $scope = trim(htmlspecialchars(strip_tags((string)$request->query->get('scope'))), '/'); + if ($scope) { + $filters['manual_slug'] = [$scope]; + } + + return new self($query, $scope, max($page, 1), $filters); } public function getQuery(): string @@ -42,6 +48,11 @@ public function getQuery(): string return $this->query; } + public function getScope(): string + { + return $this->scope; + } + public function getPage(): int { return $this->page; diff --git a/src/Twig/AppExtension.php b/src/Twig/AppExtension.php index 7349bae..fcf0e3b 100644 --- a/src/Twig/AppExtension.php +++ b/src/Twig/AppExtension.php @@ -69,9 +69,9 @@ public function aggregationBucket(string $category, string $index, array $bucket } else { $checked = ''; } - return '
' - . '' - . '