From 54d6da42684dba9d6a91f0dc372b058f0d87b88b Mon Sep 17 00:00:00 2001 From: Oleksandr Zhyian Date: Thu, 19 Dec 2024 12:25:55 +0200 Subject: [PATCH 1/2] feat: restrict search to pre-selected degree programs --- composer.lock | 70 ++++++++----------- .../Component/ComponentModule.php | 3 + .../Component/DegreeProgramsSearch.php | 1 + .../Component/PreAppliedFilters.php | 47 +++++++++++++ templates/search/filter/hidden-item.php | 24 +++++++ .../search/filter/pre-applied-filters.php | 27 +++++++ templates/search/search.php | 10 +++ 7 files changed, 142 insertions(+), 40 deletions(-) create mode 100644 src/Infrastructure/Component/PreAppliedFilters.php create mode 100644 templates/search/filter/hidden-item.php create mode 100644 templates/search/filter/pre-applied-filters.php diff --git a/composer.lock b/composer.lock index ea17375..8a8817c 100644 --- a/composer.lock +++ b/composer.lock @@ -8,16 +8,16 @@ "packages": [ { "name": "inpsyde/assets", - "version": "2.8.3", + "version": "2.9.0", "source": { "type": "git", "url": "https://github.com/inpsyde/assets.git", - "reference": "f198d7d8b726132851413a6a9b4918e02c077a4b" + "reference": "2b2d2ac359383e24284388bf54a6ff4f122d3c67" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/inpsyde/assets/zipball/f198d7d8b726132851413a6a9b4918e02c077a4b", - "reference": "f198d7d8b726132851413a6a9b4918e02c077a4b", + "url": "https://api.github.com/repos/inpsyde/assets/zipball/2b2d2ac359383e24284388bf54a6ff4f122d3c67", + "reference": "2b2d2ac359383e24284388bf54a6ff4f122d3c67", "shasum": "" }, "require": { @@ -29,9 +29,9 @@ "require-dev": { "brain/monkey": "^2.5.0", "inpsyde/php-coding-standards": "^1", - "johnpbloch/wordpress-core": ">=6.0", + "johnpbloch/wordpress-core": ">=6.2", "mikey179/vfsstream": "^1.6.8", - "php-stubs/wordpress-stubs": ">=6.0@stable", + "php-stubs/wordpress-stubs": ">=6.2@stable", "phpunit/phpunit": "^8.5.14 || ^9.0", "vimeo/psalm": "@stable" }, @@ -69,37 +69,37 @@ "description": "Package to manage assets in WordPress.", "support": { "issues": "https://github.com/inpsyde/assets/issues", - "source": "https://github.com/inpsyde/assets/tree/2.8.3" + "source": "https://github.com/inpsyde/assets/tree/2.9.0" }, - "time": "2022-12-16T13:23:02+00:00" + "time": "2024-11-28T11:55:20+00:00" }, { "name": "inpsyde/modularity", - "version": "1.8.0", + "version": "1.11.0", "source": { "type": "git", "url": "https://github.com/inpsyde/modularity.git", - "reference": "c6855a6d9c4ce6f090d031e820f176bddf2a0b1c" + "reference": "c79bb3682f55e1a2ece67f36e70d04fa2ab8c65d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/inpsyde/modularity/zipball/c6855a6d9c4ce6f090d031e820f176bddf2a0b1c", - "reference": "c6855a6d9c4ce6f090d031e820f176bddf2a0b1c", + "url": "https://api.github.com/repos/inpsyde/modularity/zipball/c79bb3682f55e1a2ece67f36e70d04fa2ab8c65d", + "reference": "c79bb3682f55e1a2ece67f36e70d04fa2ab8c65d", "shasum": "" }, "require": { "ext-json": "*", - "php": ">=7.2", + "php": ">=7.4 <8.4", "psr/container": "^1.1.0 || ^2" }, "require-dev": { "brain/monkey": "^2.6.1", - "inpsyde/php-coding-standards": "^1", - "johnpbloch/wordpress-core": ">=5.8", - "mikey179/vfsstream": "^v1.6.10", - "php-stubs/wordpress-stubs": ">=5.8@stable", - "phpunit/phpunit": "^8.5.21 || ^9.6.7", - "vimeo/psalm": "^4.13.1" + "inpsyde/php-coding-standards": "^2@dev", + "inpsyde/wp-stubs-versions": "dev-latest", + "mikey179/vfsstream": "^v1.6.11", + "phpunit/phpunit": "^9.6.19", + "roots/wordpress-no-content": "@dev", + "vimeo/psalm": "^5.24.0" }, "type": "library", "extra": { @@ -118,41 +118,31 @@ ], "authors": [ { - "name": "Inpsyde GmbH", - "email": "hello@inpsyde.com", - "homepage": "https://inpsyde.com/", + "name": "Syde GmbH", + "email": "hello@syde.com", + "homepage": "https://syde.com/", "role": "Company" - }, - { - "name": "Christian Leucht", - "email": "c.leucht@inpsyde.com", - "role": "Developer" - }, - { - "name": "Giuseppe Mazzapica", - "email": "g.mazzapica@inpsyde.com", - "role": "Developer" } ], "description": "Modular PSR-11 implementation for WordPress plugins, themes or libraries.", "support": { "issues": "https://github.com/inpsyde/modularity/issues", - "source": "https://github.com/inpsyde/modularity/tree/1.8.0" + "source": "https://github.com/inpsyde/modularity/tree/1.11.0" }, - "time": "2024-05-14T06:07:35+00:00" + "time": "2024-11-28T09:34:00+00:00" }, { "name": "inpsyde/wp-context", - "version": "1.5.0", + "version": "1.5.1", "source": { "type": "git", "url": "https://github.com/inpsyde/wp-context.git", - "reference": "1f61ccb539e287e2688dfdf86dea0448c18fc8c6" + "reference": "1350ada72517f5d374bff9409b4ea5a02377ec1a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/inpsyde/wp-context/zipball/1f61ccb539e287e2688dfdf86dea0448c18fc8c6", - "reference": "1f61ccb539e287e2688dfdf86dea0448c18fc8c6", + "url": "https://api.github.com/repos/inpsyde/wp-context/zipball/1350ada72517f5d374bff9409b4ea5a02377ec1a", + "reference": "1350ada72517f5d374bff9409b4ea5a02377ec1a", "shasum": "" }, "require": { @@ -197,9 +187,9 @@ "description": "A single-class utility to check the running context in WordPress sites.", "support": { "issues": "https://github.com/inpsyde/wp-context/issues", - "source": "https://github.com/inpsyde/wp-context/tree/1.5.0" + "source": "https://github.com/inpsyde/wp-context/tree/1.5.1" }, - "time": "2023-01-09T06:27:09+00:00" + "time": "2024-10-16T10:44:18+00:00" }, { "name": "psr/container", diff --git a/src/Infrastructure/Component/ComponentModule.php b/src/Infrastructure/Component/ComponentModule.php index 699690b..9ce0691 100644 --- a/src/Infrastructure/Component/ComponentModule.php +++ b/src/Infrastructure/Component/ComponentModule.php @@ -104,6 +104,9 @@ public function services(): array AdvancedFilters::class => static fn(ContainerInterface $container) => new AdvancedFilters( $container->get(Renderer::class), ), + PreAppliedFilters::class => static fn(ContainerInterface $container) => new PreAppliedFilters( + $container->get(Renderer::class), + ), ]; } } diff --git a/src/Infrastructure/Component/DegreeProgramsSearch.php b/src/Infrastructure/Component/DegreeProgramsSearch.php index edeb23b..06c4265 100644 --- a/src/Infrastructure/Component/DegreeProgramsSearch.php +++ b/src/Infrastructure/Component/DegreeProgramsSearch.php @@ -100,6 +100,7 @@ public function render(array $attributes = self::DEFAULT_ATTRIBUTES): string 'hiddenElements' => $this->excludeDegreeProgramElements->hideElements( $attributes['hidden_elements'] ), + 'preAppliedFilters' => $attributes['pre_applied_filters'], ], ); remove_filter('locale', [$localeHelper, 'filterLocale']); diff --git a/src/Infrastructure/Component/PreAppliedFilters.php b/src/Infrastructure/Component/PreAppliedFilters.php new file mode 100644 index 0000000..4b3e366 --- /dev/null +++ b/src/Infrastructure/Component/PreAppliedFilters.php @@ -0,0 +1,47 @@ +>, + * } + */ +class PreAppliedFilters implements RenderableComponent +{ + private const DEFAULT_ATTRIBUTES = [ + 'preAppliedFilters' => [], + ]; + + public function __construct( + private Renderer $renderer, + ) { + } + + public function render(array $attributes = self::DEFAULT_ATTRIBUTES): string + { + /** @var PreAppliedFilters $attributes */ + $attributes = wp_parse_args($attributes, self::DEFAULT_ATTRIBUTES); + $preAppliedFilters = []; + + foreach ($attributes['preAppliedFilters'] as $name => $values) { + foreach ($values as $value) { + $preAppliedFilters[] = [ + 'name' => $name, + 'value' => (string) $value, + ]; + } + } + + return $this->renderer->render( + 'search/filter/pre-applied-filters', + [ + 'preAppliedFilters' => $preAppliedFilters, + ] + ); + } +} diff --git a/templates/search/filter/hidden-item.php b/templates/search/filter/hidden-item.php new file mode 100644 index 0000000..7023da6 --- /dev/null +++ b/templates/search/filter/hidden-item.php @@ -0,0 +1,24 @@ + $name, + 'value' => $value, +] = $data; + +?> + + diff --git a/templates/search/filter/pre-applied-filters.php b/templates/search/filter/pre-applied-filters.php new file mode 100644 index 0000000..26d77af --- /dev/null +++ b/templates/search/filter/pre-applied-filters.php @@ -0,0 +1,27 @@ + $preAppliedFilters, +] = $data; + +?> + + + + render( + 'search/filter/hidden-item', + $filter + ) ?> + $activeFilters, 'advancedFilters' => $advancedFilters, 'hiddenElements' => $hiddenElements, + 'preAppliedFilters' => $preAppliedFilters, ] = $data; ?> @@ -57,6 +59,14 @@ class="c-degree-programs-search" action="" method="get" > + $preAppliedFilters, + ], + ) + ) ?> Date: Thu, 19 Dec 2024 12:50:14 +0200 Subject: [PATCH 2/2] feat: include keywords in searchable content --- CHANGELOG.md | 4 ++++ src/Infrastructure/Search/SearchableContentUpdater.php | 1 + 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5540ea9..8fa2756 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Keywords are indexed for searching. + ## [2.1.0] - 2024-09-06 ### Added diff --git a/src/Infrastructure/Search/SearchableContentUpdater.php b/src/Infrastructure/Search/SearchableContentUpdater.php index fc64069..5f4a247 100644 --- a/src/Infrastructure/Search/SearchableContentUpdater.php +++ b/src/Infrastructure/Search/SearchableContentUpdater.php @@ -84,6 +84,7 @@ private function buildSearchableContent( $rawView->title()->asString($languageCode), $rawView->subtitle()->asString($languageCode), $rawView->content()->about()->description()->asString($languageCode), + ...array_values($rawView->keywords()->asArrayOfStrings($languageCode)->getArrayCopy()), ]; return implode(' ', $parts);