public function SearchApiSolrTest::testQueryConditionsAndLanguageFilter in Search API Solr 8.2
Same name and namespace in other branches
- 8 tests/src/Kernel/SearchApiSolrTest.php \Drupal\Tests\search_api_solr\Kernel\SearchApiSolrTest::testQueryConditionsAndLanguageFilter()
Tests the conversion of language aware queries into Solr queries.
1 method overrides SearchApiSolrTest::testQueryConditionsAndLanguageFilter()
- SearchApiSolrMultilingualTest::testQueryConditionsAndLanguageFilter in tests/
src/ Kernel/ SearchApiSolrMultilingualTest.php - Tests the conversion of language aware queries into Solr queries.
File
- tests/
src/ Kernel/ SearchApiSolrTest.php, line 470
Class
- SearchApiSolrTest
- Tests index and search capabilities using the Solr search backend.
Namespace
Drupal\Tests\search_api_solr\KernelCode
public function testQueryConditionsAndLanguageFilter() {
/** @var \Drupal\search_api_solr\SolrBackendInterface $backend */
$backend = Server::load($this->serverId)
->getBackend();
list($fields, $mapping) = $this
->getFieldsAndMapping($backend);
$options = [];
$query = $this
->buildSearch();
$query
->setLanguages([
'en',
]);
$query
->addCondition('x', 5, '=');
$fq = $this
->invokeMethod($backend, 'getFilterQueries', [
$query,
$mapping,
$fields,
&$options,
]);
$this
->assertEquals('solr_x:"5"', $fq[0]['query']);
$this
->assertEquals('ss_search_api_language:"en"', $fq[1]['query']);
$query = $this
->buildSearch();
$query
->setLanguages([
'en',
'de',
]);
$condition_group = $query
->createConditionGroup();
$condition_group
->addCondition('x', 5);
$inner_condition_group = $query
->createConditionGroup();
$inner_condition_group
->addCondition('y', [
1,
2,
3,
], 'NOT IN');
$condition_group
->addConditionGroup($inner_condition_group);
$query
->addConditionGroup($condition_group);
$fq = $this
->invokeMethod($backend, 'getFilterQueries', [
$query,
$mapping,
$fields,
&$options,
]);
$this
->assertEquals('(+solr_x:"5" +(*:* -solr_y:"1" -solr_y:"2" -solr_y:"3"))', $fq[0]['query']);
$this
->assertEquals('(ss_search_api_language:"en" ss_search_api_language:"de")', $fq[1]['query']);
}