function SearchMatchTest::_testQueryScores

Same name in other branches
  1. 8.9.x core/modules/search/tests/src/Kernel/SearchMatchTest.php \Drupal\Tests\search\Kernel\SearchMatchTest::_testQueryScores()
  2. 10 core/modules/search/tests/src/Kernel/SearchMatchTest.php \Drupal\Tests\search\Kernel\SearchMatchTest::_testQueryScores()
  3. 11.x core/modules/search/tests/src/Kernel/SearchMatchTest.php \Drupal\Tests\search\Kernel\SearchMatchTest::_testQueryScores()

Tests the scoring abilities of the engine.

Verify if a query produces normalized, monotonous scores.

1 call to SearchMatchTest::_testQueryScores()
SearchMatchTest::_testQueries in core/modules/search/tests/src/Kernel/SearchMatchTest.php
Run predefine queries looking for indexed terms.

File

core/modules/search/tests/src/Kernel/SearchMatchTest.php, line 244

Class

SearchMatchTest
Indexes content and queries it.

Namespace

Drupal\Tests\search\Kernel

Code

public function _testQueryScores($query, $set, $results) {
    // Get result scores.
    $scores = [];
    foreach ($set as $item) {
        $scores[] = $item->calculated_score;
    }
    // Check order.
    $sorted = $scores;
    sort($sorted);
    $this->assertEquals($scores, array_reverse($sorted), "Query order '{$query}'");
    // Check range.
    $this->assertTrue(!count($scores) || min($scores) > 0.0 && max($scores) <= 1.0001, "Query scoring '{$query}'");
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.