Merge pull request #38 from rosiel/QueryEventHandler
Query alter done via an event handler for Search API Solr 4.3 deprecations.
This commit is contained in:
commit
6aa6af25bd
3 changed files with 47 additions and 13 deletions
|
|
@ -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().
|
* Implements hook_form_form_id_alter().
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
4
advanced_search.services.yml
Normal file
4
advanced_search.services.yml
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
services:
|
||||||
|
Drupal\advanced_search\EventSubscriber\PostConvertedQueryEventSubscriber:
|
||||||
|
tags:
|
||||||
|
- { name: 'event_subscriber' }
|
||||||
43
src/EventSubscriber/PostConvertedQueryEventSubscriber.php
Normal file
43
src/EventSubscriber/PostConvertedQueryEventSubscriber.php
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\advanced_search\EventSubscriber;
|
||||||
|
|
||||||
|
use Drupal\advanced_search\AdvancedSearchQuery;
|
||||||
|
use Drupal\search_api_solr\Event\PostConvertedQueryEvent;
|
||||||
|
use Drupal\search_api_solr\Event\SearchApiSolrEvents;
|
||||||
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subscribes to PostConvertedQueryEvents.
|
||||||
|
*
|
||||||
|
* @package Drupal\advanced_search\EventSubscriber
|
||||||
|
*/
|
||||||
|
class PostConvertedQueryEventSubscriber implements EventSubscriberInterface {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public static function getSubscribedEvents() {
|
||||||
|
$events[SearchAPISolrEvents::POST_CONVERT_QUERY][] = ['alter'];
|
||||||
|
|
||||||
|
return $events;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alter the query.
|
||||||
|
*/
|
||||||
|
public function alter(PostConvertedQueryEvent $event) {
|
||||||
|
$search_api_query = $event->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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue