public function SearchApiSolrMultilingualTest::testQueryConditionsAndLanguageFilter in Search API Solr 8.2
Tests the conversion of language aware queries into Solr queries.
Overrides SearchApiSolrTest::testQueryConditionsAndLanguageFilter
File
- tests/
src/ Kernel/ SearchApiSolrMultilingualTest.php, line 77
Class
- SearchApiSolrMultilingualTest
- 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('(+ss_search_api_language:"en" +solr_x:"5")', $fq[0]['query']);
$this
->assertFalse(isset($fq[1]));
$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('(+ss_search_api_language:"en" +(+solr_x:"5" +(*:* -solr_y:"1" -solr_y:"2" -solr_y:"3"))) (+ss_search_api_language:"de" +(+solr_x:"5" +(*:* -solr_y:"1" -solr_y:"2" -solr_y:"3")))', $fq[0]['query']);
$this
->assertFalse(isset($fq[1]));
}