From c575286d2122b4342a0a6507a9d83ba4a0359704 Mon Sep 17 00:00:00 2001 From: Markus Kalkbrenner Date: Wed, 27 Nov 2024 15:19:59 +0100 Subject: [PATCH] Issue #3490233 by mkalkbrenner: solr_date field type is not mapped anymore with search_api 1.36 --- composer.json | 2 +- src/EventSubscriber/SearchApiSubscriber.php | 14 ++++++++++++++ .../search_api/backend/SearchApiSolrBackend.php | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index a4c301d9..67618b97 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "ext-json": "*", "ext-simplexml": "*", "composer-runtime-api": ">=2.0", - "drupal/search_api": "~1.36", + "drupal/search_api": "^1.37|1.x-dev", "composer/semver": "^1.0|^3.0", "consolidation/annotated-command": "^2.12|^4.1", "maennchen/zipstream-php": "^2.2.1|^3.0.2", diff --git a/src/EventSubscriber/SearchApiSubscriber.php b/src/EventSubscriber/SearchApiSubscriber.php index c14e8df7..d041df3c 100644 --- a/src/EventSubscriber/SearchApiSubscriber.php +++ b/src/EventSubscriber/SearchApiSubscriber.php @@ -2,6 +2,7 @@ namespace Drupal\search_api_solr\EventSubscriber; +use Drupal\search_api\Event\MappingFieldTypesEvent; use Drupal\search_api\Event\MappingViewsFieldHandlersEvent; use Drupal\search_api\Event\MappingViewsHandlersEvent; use Drupal\search_api\Event\SearchApiEvents; @@ -12,6 +13,18 @@ */ class SearchApiSubscriber implements EventSubscriberInterface { + /** + * Adds the mapping how to treat some Solr special fields in views. + * + * @param \Drupal\search_api\Event\MappingViewsFieldHandlersEvent $event + * The Search API event. + */ + public function onMappingFieldTypes(MappingFieldTypesEvent $event) { + $mapping = & $event->getFieldTypeMapping(); + + $mapping['solr_date'] = 'date'; + } + /** * Adds the mapping how to treat some Solr special fields in views. * @@ -59,6 +72,7 @@ public static function getSubscribedEvents(): array { } return [ + SearchApiEvents::MAPPING_FIELD_TYPES => 'onMappingFieldTypes', SearchApiEvents::MAPPING_VIEWS_FIELD_HANDLERS => 'onMappingViewsFieldHandlers', SearchApiEvents::MAPPING_VIEWS_HANDLERS => 'onMappingViewsHandlers', ]; diff --git a/src/Plugin/search_api/backend/SearchApiSolrBackend.php b/src/Plugin/search_api/backend/SearchApiSolrBackend.php index 6adb79ac..2c4f3283 100644 --- a/src/Plugin/search_api/backend/SearchApiSolrBackend.php +++ b/src/Plugin/search_api/backend/SearchApiSolrBackend.php @@ -771,6 +771,7 @@ public function supportsDataType($type) { $built_in_support = [ 'location', 'rpt', + 'solr_date_range', 'solr_string_storage', 'solr_string_docvalues', 'solr_text_omit_norms', @@ -780,7 +781,6 @@ public function supportsDataType($type) { 'solr_text_wstoken', 'solr_text_custom', 'solr_text_custom_omit_norms', - 'solr_date_range', ]; if (in_array($type, $built_in_support)) { return TRUE;