Skip to content
Snippets Groups Projects
Commit c72c62eb authored by Quentin Fahrner's avatar Quentin Fahrner Committed by Nikolay Ignatov
Browse files

Issue #2922149 by Renrhaf, sbesselsen: Default search API language filter support

parent fd1e547f
Branches
Tags 8.x-6.0-alpha1
No related merge requests found
......@@ -218,6 +218,12 @@ class SearchBuilder {
drupal_set_message($e->getMessage(), 'error');
}
$languages = $this->query->getLanguages();
if ($languages !== NULL) {
$this->query->getConditionGroup()
->addCondition('_language', $languages, 'IN');
}
// Filters.
try {
$parsed_query_filters = $this->getQueryFilters(
......@@ -372,6 +378,7 @@ class SearchBuilder {
*/
protected function getQueryFilters(ConditionGroupInterface $condition_group, array $index_fields) {
$filters = [];
$backend_fields = ['_language' => TRUE];
if (!empty($condition_group)) {
$conjunction = $condition_group->getConjunction();
......@@ -389,7 +396,7 @@ class SearchBuilder {
}
$field_id = $condition->getField();
if (!isset($index_fields[$field_id])) {
if (!isset($index_fields[$field_id]) && !isset ($backend_fields[$field_id])) {
// TODO: proper exception.
throw new \Exception(
t(
......
......@@ -113,7 +113,9 @@ class IndexFactory {
$params = IndexFactory::index($index, TRUE);
foreach ($items as $id => $item) {
$data = [];
$data = [
'_language' => $item->getLanguage(),
];
/** @var \Drupal\search_api\Item\FieldInterface $field */
foreach ($item as $name => $field) {
$field_type = $field->getType();
......@@ -195,6 +197,10 @@ class IndexFactory {
}
}
$properties['_language'] = [
'type' => 'keyword',
];
$params['body'][$params['type']]['properties'] = $properties;
// Allow other modules to alter index mapping before we create it.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment