You are here

public function SearchApiSubscriber::queryAlter in Facets 8

Same name in this branch
  1. 8 src/EventSubscriber/SearchApiSubscriber.php \Drupal\facets\EventSubscriber\SearchApiSubscriber::queryAlter()
  2. 8 modules/facets_summary/src/EventSubscriber/SearchApiSubscriber.php \Drupal\facets_summary\EventSubscriber\SearchApiSubscriber::queryAlter()

Reacts to the query alter event.

Parameters

\Drupal\search_api\Event\QueryPreExecuteEvent $event: The query alter event.

File

src/EventSubscriber/SearchApiSubscriber.php, line 33

Class

SearchApiSubscriber

Namespace

Drupal\facets\EventSubscriber

Code

public function queryAlter(QueryPreExecuteEvent $event) {
  $query = $event
    ->getQuery();
  if ($query
    ->getIndex()
    ->getServerInstance()
    ->supportsFeature('search_api_facets')) {

    // It's safe to hardcode this to the search api scheme because this is in
    // an event subscriber. If this generated source is not correct,
    // implementing the same subscriber and directly calling
    // $manager->alterQuery($query, $your_facetsource_id); will fix that.
    $facet_source = 'search_api:' . str_replace(':', '__', $query
      ->getSearchId());

    // Add the active filters.
    $this->facetManager
      ->alterQuery($query, $facet_source);
  }
}