From 76bb602b46d8c17ab98e68d952205b8572f4adcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hrvoje=20Kne=C5=BEevi=C4=87?= Date: Fri, 11 Oct 2024 13:50:19 +0200 Subject: [PATCH] Add UserEnabled criterion and field mapper for Solr --- .../Content/Query/Criterion/UserEnabled.php | 28 ++++++++++ .../Content/UserEnabledFieldMapper.php | 53 +++++++++++++++++++ .../Content/CriterionVisitor/UserEnabled.php | 24 +++++++++ .../search/solr/criterion_visitors.yaml | 5 ++ .../config/search/solr/field_mappers.yaml | 5 ++ 5 files changed, 115 insertions(+) create mode 100644 lib/API/Values/Content/Query/Criterion/UserEnabled.php create mode 100644 lib/Core/Search/Solr/FieldMapper/Content/UserEnabledFieldMapper.php create mode 100644 lib/Core/Search/Solr/Query/Content/CriterionVisitor/UserEnabled.php diff --git a/lib/API/Values/Content/Query/Criterion/UserEnabled.php b/lib/API/Values/Content/Query/Criterion/UserEnabled.php new file mode 100644 index 00000000..1280b879 --- /dev/null +++ b/lib/API/Values/Content/Query/Criterion/UserEnabled.php @@ -0,0 +1,28 @@ +getUserField($content) !== null; + } + + public function mapFields(SPIContent $content): array + { + $userField = $this->getUserField($content); + if ($userField === null) { + return []; + } + + $fields = []; + + if (isset($userField->value->externalData['enabled'])) { + $fields[] = new Field( + 'ng_user_enabled', + $userField->value->externalData['enabled'], + new FieldType\BooleanField(), + ); + } + + return $fields; + } + + private function getUserField(SPIContent $content): ?SPIContent\Field + { + foreach ($content->fields as $field) { + if ($field->type === 'ezuser') { + return $field; + } + } + + return null; + } +} diff --git a/lib/Core/Search/Solr/Query/Content/CriterionVisitor/UserEnabled.php b/lib/Core/Search/Solr/Query/Content/CriterionVisitor/UserEnabled.php new file mode 100644 index 00000000..5fd648a9 --- /dev/null +++ b/lib/Core/Search/Solr/Query/Content/CriterionVisitor/UserEnabled.php @@ -0,0 +1,24 @@ +value[0]; + + return 'ng_user_enabled_b:' . ($isEnabled ? 'true' : 'false'); + } +} diff --git a/lib/Resources/config/search/solr/criterion_visitors.yaml b/lib/Resources/config/search/solr/criterion_visitors.yaml index 3e015391..d1304944 100644 --- a/lib/Resources/config/search/solr/criterion_visitors.yaml +++ b/lib/Resources/config/search/solr/criterion_visitors.yaml @@ -93,3 +93,8 @@ services: tags: - { name: ibexa.search.solr.query.content.criterion.visitor } - { name: ibexa.search.solr.query.location.criterion.visitor } + + netgen.ibexa_search_extra.solr.query.content.criterion_visitor.user_enabled: + class: Netgen\IbexaSearchExtra\Core\Search\Solr\Query\Content\CriterionVisitor\UserEnabled + tags: + - { name: ibexa.search.solr.query.content.criterion.visitor } diff --git a/lib/Resources/config/search/solr/field_mappers.yaml b/lib/Resources/config/search/solr/field_mappers.yaml index f15c2517..12e36eaa 100644 --- a/lib/Resources/config/search/solr/field_mappers.yaml +++ b/lib/Resources/config/search/solr/field_mappers.yaml @@ -27,3 +27,8 @@ services: class: Netgen\IbexaSearchExtra\Core\Search\Solr\FieldMapper\Location\LocationIdFieldMapper tags: - { name: ibexa.search.solr.field.mapper.location } + + netgen.ibexa_search_extra.solr.field_mapper.content.user_enabled: + class: Netgen\IbexaSearchExtra\Core\Search\Solr\FieldMapper\Content\UserEnabledFieldMapper + tags: + - { name: ibexa.search.solr.field.mapper.content }