You are here

protected function BackendTestBase::buildSearch in Search API 8

Builds a search query for testing purposes.

Used as a helper method during testing.

Parameters

string|array|null $keys: (optional) The search keys to set, if any.

string[] $conditions: (optional) Conditions to set on the query, in the format "field,value".

string[]|null $fields: (optional) Fulltext fields to search for the keys.

bool $place_id_sort: (optional) Whether to place a default sort on the item ID.

Return value

\Drupal\search_api\Query\QueryInterface A search query on the test index.

23 calls to BackendTestBase::buildSearch()
BackendTest::checkDbQueryAlter in modules/search_api_db/tests/src/Kernel/BackendTest.php
Checks whether the module's specific alter hook and event work correctly.
BackendTest::checkModuleUninstall in modules/search_api_db/tests/src/Kernel/BackendTest.php
Tests whether removing the configuration again works as it should.
BackendTest::checkSecondServer in modules/search_api_db/tests/src/Kernel/BackendTest.php
Tests that a second server doesn't interfere with the first.
BackendTest::regressionTest2511860 in modules/search_api_db/tests/src/Kernel/BackendTest.php
Tests searching for multiple two-letter words.
BackendTest::regressionTest2994022 in modules/search_api_db/tests/src/Kernel/BackendTest.php
Tests facets functionality for empty result sets.

... See full list

File

tests/src/Kernel/BackendTestBase.php, line 211

Class

BackendTestBase
Provides a base class for backend tests.

Namespace

Drupal\Tests\search_api\Kernel

Code

protected function buildSearch($keys = NULL, array $conditions = [], array $fields = NULL, $place_id_sort = TRUE) {
  static $i = 0;
  $query = $this
    ->getIndex()
    ->query();
  if ($keys) {
    $query
      ->keys($keys);
    if ($fields) {
      $query
        ->setFulltextFields($fields);
    }
  }
  foreach ($conditions as $condition) {
    list($field, $value) = explode(',', $condition, 2);
    $query
      ->addCondition($field, $value);
  }
  $query
    ->range(0, 10);
  if ($place_id_sort) {

    // Use the normal "id" and the magic "search_api_id" field alternately, to
    // make sure both work as expected.
    $query
      ->sort(++$i % 2 ? 'id' : 'search_api_id');
  }
  return $query;
}