diff --git a/advanced_search.module b/advanced_search.module index d398f6c..25e3307 100644 --- a/advanced_search.module +++ b/advanced_search.module @@ -51,19 +51,6 @@ function advanced_search_library_info_alter(&$libraries, $extension) { } } -/** - * Implements hook_search_api_solr_converted_query_alter(). - */ -function advanced_search_search_api_solr_converted_query_alter(SolariumQueryInterface $solarium_query, DrupalQueryInterface $search_api_query) { - // We must modify the query itself rather than the representation the - // search_api presents as it is not possible to use the 'OR' operator - // with it as it converts conditions into separate filter queries. - // Additionally filter queries do not affect the score so are not - // suitable for use in the advanced search queries. - $advanced_search_query = new AdvancedSearchQuery(); - $advanced_search_query->alterQuery(\Drupal::request(), $solarium_query, $search_api_query); -} - /** * Implements hook_form_form_id_alter(). */ diff --git a/advanced_search.services.yml b/advanced_search.services.yml new file mode 100644 index 0000000..981151a --- /dev/null +++ b/advanced_search.services.yml @@ -0,0 +1,4 @@ +services: + Drupal\advanced_search\EventSubscriber\PostConvertedQueryEventSubscriber: + tags: + - { name: 'event_subscriber' } diff --git a/src/EventSubscriber/PostConvertedQueryEventSubscriber.php b/src/EventSubscriber/PostConvertedQueryEventSubscriber.php new file mode 100644 index 0000000..2781c69 --- /dev/null +++ b/src/EventSubscriber/PostConvertedQueryEventSubscriber.php @@ -0,0 +1,43 @@ +getSearchApiQuery(); + $solarium_query = $event->getSolariumQuery(); + + // We must modify the query itself rather than the representation the + // search_api presents as it is not possible to use the 'OR' operator + // with it as it converts conditions into separate filter queries. + // Additionally filter queries do not affect the score so are not + // suitable for use in the advanced search queries. + $advanced_search_query = new AdvancedSearchQuery(); + $advanced_search_query->alterQuery(\Drupal::request(), $solarium_query, $search_api_query); + } + +}