You are here

protected function BackendTest::searchSuccessPartial in Search API 8

Tests whether partial searches work.

1 call to BackendTest::searchSuccessPartial()
BackendTest::checkBackendSpecificFeatures in modules/search_api_db/tests/src/Kernel/BackendTest.php
Checks backend specific features.

File

modules/search_api_db/tests/src/Kernel/BackendTest.php, line 297

Class

BackendTest
Tests index and search capabilities using the Database search backend.

Namespace

Drupal\Tests\search_api_db\Kernel

Code

protected function searchSuccessPartial() {
  $results = $this
    ->buildSearch('foobaz')
    ->range(0, 1)
    ->execute();
  $this
    ->assertResults([
    1,
  ], $results, 'Partial search for »foobaz«');
  $results = $this
    ->buildSearch('foo', [], [], FALSE)
    ->sort('search_api_relevance', QueryInterface::SORT_DESC)
    ->sort('id')
    ->execute();
  $this
    ->assertResults([
    1,
    2,
    4,
    3,
    5,
  ], $results, 'Partial search for »foo«');
  $results = $this
    ->buildSearch('foo tes')
    ->execute();
  $this
    ->assertResults([
    1,
    2,
    3,
    4,
  ], $results, 'Partial search for »foo tes«');
  $results = $this
    ->buildSearch('oob est')
    ->execute();
  $this
    ->assertResults([
    1,
    2,
    3,
  ], $results, 'Partial search for »oob est«');
  $results = $this
    ->buildSearch('foo nonexistent')
    ->execute();
  $this
    ->assertResults([], $results, 'Partial search for »foo nonexistent«');
  $results = $this
    ->buildSearch('bar nonexistent')
    ->execute();
  $this
    ->assertResults([], $results, 'Partial search for »bar nonexistent«');
  $keys = [
    '#conjunction' => 'AND',
    'oob',
    [
      '#conjunction' => 'OR',
      'est',
      'nonexistent',
    ],
  ];
  $results = $this
    ->buildSearch($keys)
    ->execute();
  $this
    ->assertResults([
    1,
    2,
    3,
  ], $results, 'Partial search for complex keys');
  $results = $this
    ->buildSearch('foo', [
    'category,item_category',
  ], [], FALSE)
    ->sort('id', QueryInterface::SORT_DESC)
    ->execute();
  $this
    ->assertResults([
    2,
    1,
  ], $results, 'Partial search for »foo« with additional filter');
  $query = $this
    ->buildSearch();
  $conditions = $query
    ->createConditionGroup('OR');
  $conditions
    ->addCondition('name', 'test');
  $conditions
    ->addCondition('body', 'test');
  $query
    ->addConditionGroup($conditions);
  $results = $query
    ->execute();
  $this
    ->assertResults([
    1,
    2,
    3,
    4,
  ], $results, 'Partial search with multi-field fulltext filter');
}