You are here

protected function SearchApiElasticsearchElastica::parseFilter in Search API Elasticsearch 7

Recursively parse Search API filters.

Overrides SearchApiElasticsearchAbstractService::parseFilter

1 call to SearchApiElasticsearchElastica::parseFilter()
SearchApiElasticsearchElastica::getSearchQueryOptions in modules/elastica/includes/SearchApiElasticsearchElastica.inc
Helper function return associative array with query options.

File

modules/elastica/includes/SearchApiElasticsearchElastica.inc, line 422
Provides Elastica client for Search API Elasticsearch.

Class

SearchApiElasticsearchElastica
Search API Elasticsearch Elastica service 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);
          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;
  }
}