You are here

public static function TestsHelper::search in Search API Autocomplete 8

Executes a search on this server.

Parameters

\Drupal\search_api\Backend\BackendInterface $backend: The test backend on which the query is executed.

\Drupal\search_api\Query\QueryInterface $query: The query to execute.

Throws

\Drupal\search_api\SearchApiException If the index doesn't have the "entity:entity_test_mulrev_changed" datasource.

See also

\Drupal\search_api_test\Plugin\search_api\backend\TestBackend::search()

File

src/Tests/TestsHelper.php, line 83

Class

TestsHelper
Contains helper methods for running tests.

Namespace

Drupal\search_api_autocomplete\Tests

Code

public static function search(BackendInterface $backend, QueryInterface $query) {
  $args = array_slice(func_get_args(), 1);
  static::logMethodCall('backend', __FUNCTION__, $args);
  $results = $query
    ->getResults();
  $index = $query
    ->getIndex();
  $datasource_id = 'entity:entity_test_mulrev_changed';
  $datasource = $index
    ->getDatasource($datasource_id);
  $fields_helper = \Drupal::getContainer()
    ->get('search_api.fields_helper');
  $result_items = [];
  foreach ([
    3,
    4,
    2,
  ] as $i) {
    $item_id = Utility::createCombinedId($datasource_id, "{$i}:en");
    $item = $fields_helper
      ->createItem($index, $item_id, $datasource);
    $result_items[$item_id] = $item;
  }
  $results
    ->setResultItems($result_items);
  $results
    ->setResultCount(count($result_items));
}