You are here

public function SolrFieldType::getDynamicFields in Search API Solr 4.x

Same name and namespace in other branches
  1. 8.3 src/Entity/SolrFieldType.php \Drupal\search_api_solr\Entity\SolrFieldType::getDynamicFields()
  2. 8.2 src/Entity/SolrFieldType.php \Drupal\search_api_solr\Entity\SolrFieldType::getDynamicFields()

Gets a list of dynamic Solr fields that will use this Solr Field Type.

Parameters

int|null $solr_major_version:

Return value

array An array of dynamic field definitions.

Overrides SolrFieldTypeInterface::getDynamicFields

File

src/Entity/SolrFieldType.php, line 422

Class

SolrFieldType
Defines the SolrFieldType entity.

Namespace

Drupal\search_api_solr\Entity

Code

public function getDynamicFields(?int $solr_major_version = NULL) {
  $dynamic_fields = [];
  $prefixes = $this->custom_code ? [
    'tc' . $this->custom_code,
    'toc' . $this->custom_code,
    'tuc' . $this->custom_code,
  ] : [
    't',
    'to',
    'tu',
  ];
  foreach ($prefixes as $prefix_without_cardinality) {
    foreach ([
      's',
      'm',
    ] as $cardinality) {
      $prefix = $prefix_without_cardinality . $cardinality;
      $name = $prefix . SolrBackendInterface::SEARCH_API_SOLR_LANGUAGE_SEPARATOR . $this->field_type_language_code . '_';
      $dynamic_fields[] = $dynamic_field = [
        'name' => SearchApiSolrUtility::encodeSolrName($name) . '*',
        'type' => strpos($prefix, 'tu') === 0 && !empty($this->unstemmed_field_type) ? $this->unstemmed_field_type['name'] : $this->field_type['name'],
        'stored' => TRUE,
        'indexed' => TRUE,
        'multiValued' => 'm' === $cardinality,
        'termVectors' => TRUE,
        'omitNorms' => strpos($prefix, 'to') === 0,
      ];
      if (LanguageInterface::LANGCODE_NOT_SPECIFIED === $this->field_type_language_code) {

        // Add a language-unspecific default dynamic field as fallback for
        // languages we don't have a dedicated config for.
        $dynamic_field['name'] = SearchApiSolrUtility::encodeSolrName($prefix) . '_*';
        $dynamic_fields[] = $dynamic_field;
      }
    }
  }
  if ($spellcheck_field = $this
    ->getSpellcheckField()) {

    // Spellcheck fields need to be dynamic to have a language fallback, for
    // example de-at => de.
    $dynamic_fields[] = $spellcheck_field;
    if (LanguageInterface::LANGCODE_NOT_SPECIFIED === $this->field_type_language_code) {

      // Add a language-unspecific default dynamic spellcheck field as
      // fallback for languages we don't have a dedicated config for.
      $spellcheck_field['name'] = 'spellcheck_*';
      $dynamic_fields[] = $spellcheck_field;
    }
  }
  if ($collated_field = $this
    ->getCollatedField($solr_major_version)) {
    $dynamic_fields[] = $collated_field;
    if (LanguageInterface::LANGCODE_NOT_SPECIFIED === $this->field_type_language_code) {

      // Add a language-unspecific default dynamic sort field as fallback for
      // languages we don't have a dedicated config for.
      $collated_field['name'] = 'sort_*';
      $dynamic_fields[] = $collated_field;
    }
  }
  return $dynamic_fields;
}