protected function BackendTest::searchSuccessMinChars in Search API 8
Tests the results of some test searches with minimum word length of 4.
1 call to BackendTest::searchSuccessMinChars()
- 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 417
Class
- BackendTest
- Tests index and search capabilities using the Database search backend.
Namespace
Drupal\Tests\search_api_db\KernelCode
protected function searchSuccessMinChars() {
$results = $this
->getIndex()
->query()
->keys('test')
->range(1, 2)
->execute();
$this
->assertEquals(4, $results
->getResultCount(), 'Search for »test« returned correct number of results.');
$this
->assertEquals($this
->getItemIds([
4,
1,
]), array_keys($results
->getResultItems()), 'Search for »test« returned correct result.');
$this
->assertEmpty($results
->getIgnoredSearchKeys());
$this
->assertEmpty($results
->getWarnings());
$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, 'Search with multi-field fulltext filter');
$results = $this
->buildSearch(NULL, [
'body,test foobar',
])
->execute();
$this
->assertResults([
3,
], $results, 'Search with multi-term fulltext filter');
$results = $this
->getIndex()
->query()
->keys('test foo')
->execute();
$this
->assertResults([
2,
4,
1,
3,
], $results, 'Search for »test foo«', [
'foo',
]);
$results = $this
->buildSearch('foo', [
'type,item',
])
->execute();
$this
->assertResults([
1,
2,
3,
], $results, 'Search for »foo«', [
'foo',
], [
'No valid search keys were present in the query.',
]);
$keys = [
'#conjunction' => 'AND',
'test',
[
'#conjunction' => 'OR',
'baz',
'foobar',
],
[
'#conjunction' => 'OR',
'#negation' => TRUE,
'bar',
'fooblob',
],
];
$results = $this
->buildSearch($keys)
->execute();
$this
->assertResults([
3,
], $results, 'Complex search 1', [
'baz',
'bar',
]);
$keys = [
'#conjunction' => 'AND',
'test',
[
'#conjunction' => 'OR',
'baz',
'foobar',
],
[
'#conjunction' => 'OR',
'#negation' => TRUE,
'bar',
'fooblob',
],
];
$results = $this
->buildSearch($keys)
->execute();
$this
->assertResults([
3,
], $results, 'Complex search 2', [
'baz',
'bar',
]);
$results = $this
->buildSearch(NULL, [
'keywords,orange',
])
->execute();
$this
->assertResults([
1,
2,
5,
], $results, 'Filter query 1 on multi-valued field');
$conditions = [
'keywords,orange',
'keywords,apple',
];
$results = $this
->buildSearch(NULL, $conditions)
->execute();
$this
->assertResults([
2,
], $results, 'Filter query 2 on multi-valued field');
$results = $this
->buildSearch()
->addCondition('keywords', 'orange', '<>')
->execute();
$this
->assertResults([
3,
4,
], $results, 'Negated filter on multi-valued field');
$results = $this
->buildSearch()
->addCondition('keywords', NULL)
->execute();
$this
->assertResults([
3,
], $results, 'Query with NULL filter');
$results = $this
->buildSearch()
->addCondition('keywords', NULL, '<>')
->execute();
$this
->assertResults([
1,
2,
4,
5,
], $results, 'Query with NOT NULL filter');
}