You are here

public function SearchApiTestService::search in Search API 7

Implements SearchApiServiceInterface::indexItems().

Will ignore all query settings except the range, as only the item IDs are indexed.

Overrides SearchApiServiceInterface::search

File

tests/search_api_test.module, line 336
Test functions and classes for testing the Search API.

Class

SearchApiTestService
Test service class.

Code

public function search(SearchApiQueryInterface $query) {
  $options = $query
    ->getOptions();
  $ret = array();
  $index_id = $query
    ->getIndex()->machine_name;
  if (empty($this->options['indexes'][$index_id])) {
    return array(
      'result count' => 0,
      'results' => array(),
    );
  }
  $items = $this->options['indexes'][$index_id];
  $min = isset($options['offset']) ? $options['offset'] : 0;
  $max = $min + (isset($options['limit']) ? $options['limit'] : count($items));
  $i = 0;
  $ret['result count'] = count($items);
  $ret['results'] = array();
  foreach ($items as $id) {
    ++$i;
    if ($i > $max) {
      break;
    }
    if ($i > $min) {
      $ret['results'][$id] = array(
        'id' => $id,
        'score' => 1,
      );
    }
  }
  return $ret;
}