public function BoostMoreRecentTest::testBoostMostRecent in Search API Solr 4.x
Tests boost by recent date queries.
Throws
\Drupal\search_api\SearchApiException
File
- tests/
src/ Kernel/ Processor/ BoostMoreRecentTest.php, line 124
Class
- BoostMoreRecentTest
- Tests the "Boost more recent" processor.
Namespace
Drupal\Tests\search_api_solr\Kernel\ProcessorCode
public function testBoostMostRecent() {
$this
->indexItems();
$this
->assertArrayHasKey('solr_boost_more_recent', $this->index
->getProcessors(), 'Boost more recent processor is added.');
$query = new Query($this->index);
$query
->sort('search_api_relevance', QueryInterface::SORT_DESC);
$query
->sort('search_api_id');
$result = $query
->execute();
$this
->assertEquals([
'entity:node/1:en',
'entity:node/2:en',
], array_keys($result
->getResultItems()));
$processor = $this->index
->getProcessor('solr_boost_more_recent');
$configuration = [
'boosts' => [
'field_date' => [
'boost' => 1,
'resolution' => 'NOW/HOUR',
'm' => '3.16e-11',
'a' => 2.0,
'b' => 0.08,
],
],
];
$processor
->setConfiguration($configuration);
$this->index
->setProcessors([
'solr_boost_more_recent' => $processor,
]);
$this->index
->save();
$query = new Query($this->index);
$query
->sort('search_api_relevance', QueryInterface::SORT_DESC);
$query
->sort('search_api_id');
$result = $query
->execute();
$this
->assertEquals([
'entity:node/2:en',
'entity:node/1:en',
], array_keys($result
->getResultItems()));
$configuration = [
'boosts' => [
'field_date' => [
'boost' => 1,
'resolution' => 'NOW',
'm' => '3.16e-11',
'a' => 1,
'b' => 1,
],
],
];
$processor
->setConfiguration($configuration);
$this->index
->setProcessors([
'solr_boost_more_recent' => $processor,
]);
$this->index
->save();
$query = new Query($this->index);
$query
->sort('search_api_relevance', QueryInterface::SORT_DESC);
$query
->sort('search_api_id');
$result = $query
->execute();
$this
->assertEquals([
'entity:node/2:en',
'entity:node/1:en',
], array_keys($result
->getResultItems()));
$configuration = [];
$processor
->setConfiguration($configuration);
$this->index
->setProcessors([
'solr_boost_more_recent' => $processor,
]);
$this->index
->save();
$query = new Query($this->index);
$query
->sort('search_api_relevance', QueryInterface::SORT_DESC);
$query
->sort('search_api_id');
$result = $query
->execute();
$this
->assertEquals([
'entity:node/1:en',
'entity:node/2:en',
], array_keys($result
->getResultItems()));
}