Commit d428f355 authored by Markus Kalkbrenner's avatar Markus Kalkbrenner Committed by Markus Kalkbrenner
Browse files

Issue #3197168 by Taran2L, mkalkbrenner: treat language "zxx" like "und"

parent ac09c6db
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@ class ConfigSubscriber implements EventSubscriberInterface {
    $saved_config = $event->getConfig();

    if (preg_match('@^language\.entity\.(.+)@', $saved_config->getName(), $matches) &&
        $matches[1] != LanguageInterface::LANGCODE_NOT_SPECIFIED) {
        $matches[1] != LanguageInterface::LANGCODE_NOT_SPECIFIED && $matches[1] != LanguageInterface::LANGCODE_NOT_APPLICABLE) {
      $restrict_by_dependency = [
        'module' => 'search_api_solr',
      ];
+3 −0
Original line number Diff line number Diff line
@@ -1139,6 +1139,9 @@ class SearchApiSolrBackend extends BackendPluginBase implements SolrBackendInter
    /** @var \Drupal\search_api\Item\ItemInterface[] $items */
    foreach ($items as $id => $item) {
      $language_id = $item->getLanguage();
      if ($language_id === LanguageInterface::LANGCODE_NOT_APPLICABLE) {
        $language_id = LanguageInterface::LANGCODE_NOT_SPECIFIED;
      }
      $field_names = $this->getLanguageSpecificSolrFieldNames($language_id, $index);
      $boost_terms = [];

+1 −1
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ interface SolrBackendInterface extends BackendInterface {
   *
   * @todo replace by an automatic detection when core provides module versions.
   */
  public const SEARCH_API_SOLR_SCHEMA_VERSION = '4.2.4';
  public const SEARCH_API_SOLR_SCHEMA_VERSION = '4.2.5';

  /**
   * The minimum required Solr schema version.
+8 −2
Original line number Diff line number Diff line
@@ -1215,6 +1215,12 @@ class Utility {

    $settings = self::getIndexSolrSettings($index);
    $language_ids = $query->getLanguages();
    array_walk($language_ids, function(&$item, $key) {
      if (LanguageInterface::LANGCODE_NOT_APPLICABLE === $item) {
        $item = LanguageInterface::LANGCODE_NOT_SPECIFIED;
      }
    });
    $language_ids = array_unique($language_ids);

    // If there are no languages set, we need to set them. As an example, a
    // language might be set by a filter in a search view.
@@ -1235,8 +1241,8 @@ class Utility {

    if ($settings['multilingual']['include_language_independent']) {
      $language_ids[] = LanguageInterface::LANGCODE_NOT_SPECIFIED;
      // LanguageInterface::LANGCODE_NOT_APPLICABLE never appears in Search API
      // at the moment.
      // LanguageInterface::LANGCODE_NOT_APPLICABLE is mapped to
      // LanguageInterface::LANGCODE_NOT_SPECIFIED above.
    }

    $query->setLanguages(array_unique($language_ids));
+15 −1
Original line number Diff line number Diff line
@@ -676,6 +676,20 @@ class SearchApiSolrTest extends SolrBackendTestBase {
    $this->assertEquals('tm_X3b_en_body:("some text")', $fq[0]['query']);
    $this->assertArrayNotHasKey(1, $fq);

    $query = $this->buildSearch();
    $query->setLanguages([LanguageInterface::LANGCODE_NOT_SPECIFIED]);
    $query->addCondition('body', 'some text', '=');
    $fq = $this->invokeMethod($backend, 'getFilterQueries', [$query, &$options]);
    $this->assertEquals('tm_X3b_und_body:("some text")', $fq[0]['query']);
    $this->assertArrayNotHasKey(1, $fq);

    $query = $this->buildSearch();
    $query->setLanguages([LanguageInterface::LANGCODE_NOT_APPLICABLE]);
    $query->addCondition('body', 'some text', '=');
    $fq = $this->invokeMethod($backend, 'getFilterQueries', [$query, &$options]);
    $this->assertEquals('tm_X3b_und_body:("some text")', $fq[0]['query']);
    $this->assertArrayNotHasKey(1, $fq);

    $parse_mode_manager = \Drupal::service('plugin.manager.search_api.parse_mode');
    $parse_mode_phrase = $parse_mode_manager->createInstance('phrase');

@@ -1322,7 +1336,7 @@ class SearchApiSolrTest extends SolrBackendTestBase {
      'name' => 'und 8',
      'body' => 'genes',
      'type' => 'item',
      'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
      'langcode' => LanguageInterface::LANGCODE_NOT_APPLICABLE,
    ]);
    $count = \Drupal::entityQuery('entity_test_mulrev_changed')->count()->execute();
    $this->assertEquals(8, $count, "$count items inserted.");