You are here

public function BackendTest::testRegression2949962 in Search API 8

Tests negated fulltext searches with substring matching.

@dataProvider regression2949962DataProvider

Parameters

string $match_mode: The match mode to use – "partial", "prefix" or "words".

See also

https://www.drupal.org/project/search_api/issues/2949962

File

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

Class

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

Namespace

Drupal\Tests\search_api_db\Kernel

Code

public function testRegression2949962($match_mode) {
  $this
    ->insertExampleContent();
  $this
    ->setServerMatchMode($match_mode);
  $this
    ->indexItems($this->indexId);
  $searches = [
    'not this word' => [
      'keys' => [
        '#conjunction' => 'OR',
        '#negation' => TRUE,
        'test',
      ],
      'expected_results' => [
        1,
        3,
        4,
        5,
      ],
    ],
    'none of these words' => [
      'keys' => [
        '#conjunction' => 'OR',
        '#negation' => TRUE,
        'test',
        'foo',
      ],
      'expected_results' => [
        3,
        5,
      ],
    ],
    'not all of these words' => [
      'keys' => [
        '#conjunction' => 'AND',
        '#negation' => TRUE,
        'foo baz',
      ],
      'expected_results' => [
        2,
        3,
        5,
      ],
    ],
    'complex keywords' => [
      'keys' => [
        [
          'foo',
          'bar',
          '#conjunction' => 'AND',
        ],
        [
          'test',
          '#conjunction' => 'OR',
          '#negation' => TRUE,
        ],
        '#conjunction' => 'AND',
      ],
      'expected_results' => [
        1,
      ],
    ],
  ];
  foreach ($searches as $search) {
    $results = $this
      ->buildSearch($search['keys'], [], [
      'name',
    ])
      ->execute();
    $this
      ->assertResults($search['expected_results'], $results);
  }
}