function SearchMatchTest::_testQueries in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/search/src/Tests/SearchMatchTest.php \Drupal\search\Tests\SearchMatchTest::_testQueries()
Run predefine queries looking for indexed terms.
1 call to SearchMatchTest::_testQueries()
- SearchMatchTest::testMatching in core/
modules/ search/ src/ Tests/ SearchMatchTest.php - Test search indexing.
File
- core/
modules/ search/ src/ Tests/ SearchMatchTest.php, line 108 - Contains \Drupal\search\Tests\SearchMatchTest.
Class
- SearchMatchTest
- Indexes content and queries it.
Namespace
Drupal\search\TestsCode
function _testQueries() {
// Note: OR queries that include short words in OR groups are only accepted
// if the ORed terms are ANDed with at least one long word in the rest of
// the query. Examples:
// enim dolore OR ut = enim (dolore OR ut) = (enim dolor) OR (enim ut)
// is good, and
// dolore OR ut = (dolore) OR (ut)
// is bad. This is a design limitation to avoid full table scans.
$queries = array(
// Simple AND queries.
'ipsum' => array(
1,
),
'enim' => array(
4,
5,
6,
),
'xxxxx' => array(),
'enim minim' => array(
5,
6,
),
'enim xxxxx' => array(),
'dolore eu' => array(
7,
),
'dolore xx' => array(),
'ut minim' => array(
5,
),
'xx minim' => array(),
'enim veniam am minim ut' => array(
5,
),
// Simple OR and AND/OR queries.
'dolore OR ipsum' => array(
1,
2,
7,
),
'dolore OR xxxxx' => array(
2,
7,
),
'dolore OR ipsum OR enim' => array(
1,
2,
4,
5,
6,
7,
),
'ipsum OR dolore sit OR cillum' => array(
2,
7,
),
'minim dolore OR ipsum' => array(
7,
),
'dolore OR ipsum veniam' => array(
7,
),
'minim dolore OR ipsum OR enim' => array(
5,
6,
7,
),
'dolore xx OR yy' => array(),
'xxxxx dolore OR ipsum' => array(),
// Sequence of OR queries.
'minim' => array(
5,
6,
7,
),
'minim OR xxxx' => array(
5,
6,
7,
),
'minim OR xxxx OR minim' => array(
5,
6,
7,
),
'minim OR xxxx minim' => array(
5,
6,
7,
),
'minim OR xxxx minim OR yyyy' => array(
5,
6,
7,
),
'minim OR xxxx minim OR cillum' => array(
6,
7,
5,
),
'minim OR xxxx minim OR xxxx' => array(
5,
6,
7,
),
// Negative queries.
'dolore -sit' => array(
7,
),
'dolore -eu' => array(
2,
),
'dolore -xxxxx' => array(
2,
7,
),
'dolore -xx' => array(
2,
7,
),
// Phrase queries.
'"dolore sit"' => array(
2,
),
'"sit dolore"' => array(),
'"am minim veniam es"' => array(
6,
7,
),
'"minim am veniam es"' => array(),
// Mixed queries.
'"am minim veniam es" OR dolore' => array(
2,
6,
7,
),
'"minim am veniam es" OR "dolore sit"' => array(
2,
),
'"minim am veniam es" OR "sit dolore"' => array(),
'"am minim veniam es" -eu' => array(
6,
),
'"am minim veniam" -"cillum dolore"' => array(
5,
6,
),
'"am minim veniam" -"dolore cillum"' => array(
5,
6,
7,
),
'xxxxx "minim am veniam es" OR dolore' => array(),
'xx "minim am veniam es" OR dolore' => array(),
);
foreach ($queries as $query => $results) {
$result = db_select('search_index', 'i')
->extend('Drupal\\search\\SearchQuery')
->searchExpression($query, SEARCH_TYPE)
->execute();
$set = $result ? $result
->fetchAll() : array();
$this
->_testQueryMatching($query, $set, $results);
$this
->_testQueryScores($query, $set, $results);
}
// These queries are run against the second index type, SEARCH_TYPE_2.
$queries = array(
// Simple AND queries.
'ipsum' => array(),
'enim' => array(),
'enim minim' => array(),
'dear' => array(
8,
),
'germany' => array(
11,
12,
),
);
foreach ($queries as $query => $results) {
$result = db_select('search_index', 'i')
->extend('Drupal\\search\\SearchQuery')
->searchExpression($query, SEARCH_TYPE_2)
->execute();
$set = $result ? $result
->fetchAll() : array();
$this
->_testQueryMatching($query, $set, $results);
$this
->_testQueryScores($query, $set, $results);
}
// These queries are run against the third index type, SEARCH_TYPE_JPN.
$queries = array(
// Simple AND queries.
'呂波耳' => array(
13,
),
'以呂波耳' => array(
13,
),
'ほへと ヌルヲ' => array(
13,
),
'とちリ' => array(),
'ドルーパル' => array(
14,
),
'パルが大' => array(
14,
),
'コーヒー' => array(
15,
),
'ヒーキ' => array(),
);
foreach ($queries as $query => $results) {
$result = db_select('search_index', 'i')
->extend('Drupal\\search\\SearchQuery')
->searchExpression($query, SEARCH_TYPE_JPN)
->execute();
$set = $result ? $result
->fetchAll() : array();
$this
->_testQueryMatching($query, $set, $results);
$this
->_testQueryScores($query, $set, $results);
}
}