You are here

public function FuzzySearchService::indexItems in Fuzzy Search 7

Indexes the specified items.

Parameters

SearchApiIndex $index: The search index for which items should be indexed.

array $items: An array of items to be indexed, keyed by their id. The values are associative arrays of the fields to be stored, where each field is an array with the following keys:

  • type: One of the data types recognized by the Search API, or the special type "tokens" for fulltext fields.
  • original_type: The original type of the property, as defined by the datasource controller for the index's item type.
  • value: The value to index.

The special field "search_api_language" contains the item's language and should always be indexed.

The value of fields with the "tokens" type is an array of tokens. Each token is an array containing the following keys:

  • value: The word that the token represents.
  • score: A score for the importance of that word.

Return value

array An array of the ids of all items that were successfully indexed.

Throws

SearchApiException If indexing was prevented by a fundamental configuration error.

Overrides SearchApiServiceInterface::indexItems

File

includes/service.inc, line 356

Class

FuzzySearchService
Search service class using the database for storing index information.

Code

public function indexItems(SearchApiIndex $index, array $items) {
  if (empty($this->options['indexes'][$index->machine_name])) {
    throw new SearchApiException(t('No field settings for index with id !id.', array(
      '!id' => $index->machine_name,
    )));
  }
  $indexed = array();
  $set = $this
    ->setDb();
  foreach ($items as $id => $item) {
    try {
      if ($this
        ->indexItem($index, $id, $item)) {
        $indexed[] = $id;
      }
    } catch (Exception $e) {

      // We just log the error, hoping we can index the other items.
      watchdog('search api', $e
        ->getMessage(), NULL, WATCHDOG_WARNING);
    }
  }
  if ($set) {
    $this
      ->resetDb();
  }
  return $indexed;
}