You are here

protected function SearchApiElasticsearchAbstractService::parseFilter in Search API Elasticsearch 7

Helper function: Recursively parse Search API filters.

1 call to SearchApiElasticsearchAbstractService::parseFilter()
SearchApiElasticsearchAbstractService::getAggregationSearchFilter in includes/SearchApiElasticsearchAbstractService.inc
Helper function return Facet filter.
1 method overrides SearchApiElasticsearchAbstractService::parseFilter()
SearchApiElasticsearchElastica::parseFilter in modules/elastica/includes/SearchApiElasticsearchElastica.inc
Recursively parse Search API filters.

File

includes/SearchApiElasticsearchAbstractService.inc, line 819
Provides a Elasticsearch-based service class for the Search API.

Class

SearchApiElasticsearchAbstractService
Elasticsearch service abstract class.

Code

protected function parseFilter(SearchApiQueryFilter $query_filter, $index_fields, $ignored_field_id = '') {
  if (empty($query_filter)) {
    return NULL;
  }
  else {
    $conjunction = $query_filter
      ->getConjunction();
    $filters = array();
    try {
      foreach ($query_filter
        ->getFilters() as $filter_info) {
        $filter = NULL;

        // Simple filter [field_id, value, operator].
        if (is_array($filter_info)) {
          $filter_assoc = $this
            ->getAssociativeFilter($filter_info);
          $this
            ->correctFilter($filter_assoc, $index_fields, $ignored_field_id);

          // Check field.
          $filter = $this
            ->getFilter($filter_assoc);
          if (!empty($filter)) {
            $filters[] = $filter;
          }
        }
        elseif ($filter_info instanceof SearchApiQueryFilter) {
          $nested_filters = $this
            ->parseFilter($filter_info, $index_fields, $ignored_field_id);

          // TODO: handle error. - here is unnecessary cause in if we thow exceptions and this is still in try{}  .
          if (!empty($nested_filters)) {
            $filters = array_merge($filters, $nested_filters);
          }
        }
      }
      $filters = $this
        ->setFiltersConjunction($filters, $conjunction);
    } catch (Exception $e) {
      watchdog('Elasticsearch', check_plain($e
        ->getMessage()), array(), WATCHDOG_ERROR);
      drupal_set_message(check_plain($e
        ->getMessage()), 'error');
    }
    return $filters;
  }
}