You are here

public function SearchApiQuery::addField in Search API 8

Adds a field to the table.

This replicates the interface of Views' default SQL backend to simplify the Views integration of the Search API. If you are writing Search API-specific Views code, you should better use the addRetrievedFieldValue() method.

Parameters

string|null $table: Ignored.

string $field: The combined property path of the property that should be retrieved.

string $alias: (optional) Ignored.

array $params: (optional) Ignored.

Return value

string The name that this field can be referred to as (always $field).

See also

\Drupal\views\Plugin\views\query\Sql::addField()

\Drupal\search_api\Plugin\views\query\SearchApiQuery::addRetrievedFieldValue()

1 call to SearchApiQuery::addField()
SearchApiQuery::addRetrievedProperty in src/Plugin/views/query/SearchApiQuery.php
Adds a property to be retrieved.

File

src/Plugin/views/query/SearchApiQuery.php, line 336

Class

SearchApiQuery
Defines a Views query class for searching on Search API indexes.

Namespace

Drupal\search_api\Plugin\views\query

Code

public function addField($table, $field, $alias = '', array $params = []) {

  // Ignore calls for built-in fields which don't need to be retrieved.
  $built_in = [
    'search_api_id' => TRUE,
    'search_api_datasource' => TRUE,
    'search_api_language' => TRUE,
    'search_api_relevance' => TRUE,
    'search_api_excerpt' => TRUE,
  ];
  if (isset($built_in[$field])) {
    return $field;
  }
  foreach ($this
    ->getIndex()
    ->getFields(TRUE) as $field_id => $field_object) {
    if ($field_object
      ->getCombinedPropertyPath() === $field) {
      $this
        ->addRetrievedFieldValue($field_id);
      break;
    }
  }
  return $field;
}