You are here

function search_api_solr_update_8307 in Search API Solr 8.3

Same name and namespace in other branches
  1. 4.x search_api_solr.install \search_api_solr_update_8307()

Avoid redundant text files in generated Solr config files.

File

./search_api_solr.install, line 1008
Install, update and uninstall functions for the Search API Solr module.

Code

function search_api_solr_update_8307() {
  foreach (search_api_solr_update_helper_get_field_type_configs() as $field_type_name => $field_type_config) {
    if (strpos($field_type_name, 'text_phonetic') !== FALSE || strpos($field_type_name, 'text_edge_und') !== FALSE || strpos($field_type_name, 'text_ngram_und') !== FALSE) {
      $dependency = str_replace([
        'text_phonetic',
        'text_edge_und',
        'text_ngram_und',
      ], [
        'text',
        'text_und',
        'text_und',
      ], $field_type_name);
      if (!isset($field_type_config['dependencies']['config']) || !in_array($dependency, $field_type_config['dependencies']['config'])) {
        $field_type_config['dependencies']['config'][] = $dependency;
      }
      if (!empty($field_type_config['field_type']) && !empty($field_type_config['field_type']['analyzers'])) {
        foreach ($field_type_config['field_type']['analyzers'] as &$component) {
          if (!empty($component['charFilters'])) {
            foreach ($component['charFilters'] as &$charFilter) {
              if ($charFilter['class'] === 'solr.MappingCharFilterFactory') {
                $charFilter['mapping'] = 'accents_' . $field_type_config['field_type_language_code'] . '.txt';
              }
            }
          }
          foreach ($component['filters'] as &$filter) {
            if ($filter['class'] === 'solr.WordDelimiterFilterFactory' || $filter['class'] === 'solr.WordDelimiterGraphFilterFactory') {
              $filter['protected'] = 'protwords_' . $field_type_config['field_type_language_code'] . '.txt';
            }
            elseif ($filter['class'] === 'solr.DictionaryCompoundWordTokenFilterFactory') {
              $filter['dictionary'] = 'nouns_' . $field_type_config['field_type_language_code'] . '.txt';
            }
            elseif ($filter['class'] === 'solr.StopFilterFactory') {
              $filter['words'] = 'stopwords_' . $field_type_config['field_type_language_code'] . '.txt';
            }
            elseif ($filter['class'] === 'solr.SynonymFilterFactory' || $filter['class'] === 'solr.SynonymGraphFilterFactory') {
              $filter['synonyms'] = 'synonyms_' . $field_type_config['field_type_language_code'] . '.txt';
            }
          }
        }
      }
      if (!empty($field_type_config['text_files'])) {
        $field_type_config['text_files'] = [];
      }
      search_api_solr_update_helper_save_field_type_config($field_type_name, $field_type_config);
    }
  }
}