You are here

public function SearchApiMultiQuery::fields in Search API Multi-Index Searches 7

Sets the fields that will be searched for the search keys.

If this method is not called on the query before execution, or it is called with NULL, all fulltext fields should be searched.

Parameters

array|null $fields: An array containing fulltext fields that should be searched, or NULL if all fields should be searched.

Return value

SearchApiMultiQueryInterface The called object.

Throws

SearchApiException If one of the fields isn't of type "text".

Overrides SearchApiMultiQueryInterface::fields

File

./search_api_multi.query.inc, line 547

Class

SearchApiMultiQuery
Standard implementation of SearchApiMultiQueryInterface.

Code

public function fields($fields = NULL) {
  $this->index_fields = array();
  if ($fields) {
    foreach ($fields as $spec) {
      list($index_id, $field) = explode(':', $spec, 2);
      $index = $this->indexes[$index_id];
      if (empty($index->options['fields'][$field]) || !search_api_is_text_type($index->options['fields'][$field]['type'])) {
        throw new SearchApiException(t('Trying to search on field @field which is no indexed fulltext field.', array(
          '@field' => $field,
        )));
      }
      $this->used_indexes[$index_id] = TRUE;
      $this->index_fields[$index_id][] = $field;
    }
  }
  $this->fields = $fields;
  return $this;
}