You are here

private function SearchApiAlgoliaBackend::extractConditions in Search API Algolia 2.0.x

Same name and namespace in other branches
  1. 8 src/Plugin/search_api/backend/SearchApiAlgoliaBackend.php \Drupal\search_api_algolia\Plugin\search_api\backend\SearchApiAlgoliaBackend::extractConditions()
  2. 3.0.x src/Plugin/search_api/backend/SearchApiAlgoliaBackend.php \Drupal\search_api_algolia\Plugin\search_api\backend\SearchApiAlgoliaBackend::extractConditions()

Extract conditions.

Parameters

\Drupal\search_api\Query\ConditionGroupInterface $condition_group: Condition group.

array $options: Algolia options to updatesearch_api_algolia.module.

array $facets: Facets.

1 call to SearchApiAlgoliaBackend::extractConditions()
SearchApiAlgoliaBackend::search in src/Plugin/search_api/backend/SearchApiAlgoliaBackend.php

File

src/Plugin/search_api/backend/SearchApiAlgoliaBackend.php, line 733

Class

SearchApiAlgoliaBackend
Class SearchApiAlgoliaBackend.

Namespace

Drupal\search_api_algolia\Plugin\search_api\backend

Code

private function extractConditions(ConditionGroupInterface $condition_group, array &$options, array $facets) {
  foreach ($condition_group
    ->getConditions() as $condition) {
    if ($condition instanceof ConditionGroupInterface) {
      $this
        ->extractConditions($condition, $options, $facets);
      continue;
    }
    $field = $condition
      ->getField();

    /** @var \Drupal\search_api\Query\Condition $condition */

    // We support limited operators for now.
    if ($condition
      ->getOperator() == '=') {
      $query = $field . ':' . $condition
        ->getValue();
      if (in_array($field, $facets)) {
        $options['facetFilters'][$field][] = $query;
        $options['disjunctiveFacets'][$field] = $field;
      }
      else {
        $options['filters'] = isset($options['filters']) ? ' AND ' . $query : $query;
      }
    }
    elseif (in_array($condition
      ->getOperator(), [
      '<',
      '>',
      '<=',
      '>=',
    ])) {
      $options['numericFilters'][] = $field . ' ' . $condition
        ->getOperator() . ' ' . $condition
        ->getValue();
    }
  }
}