You are here

public function SolrFieldType::setFieldTypeAsJson in Search API Multilingual Solr Search 8

Sets the Solr Field Type definition as JSON.

Decodes the Solr Field Type definition encoded as JSON and stores an nested associative array internally. This method in useful to import a field type from an existing Solr server.

Parameters

string $field_type: The Solr Field Type definition as JSON.

Return value

$this

Overrides SolrFieldTypeInterface::setFieldTypeAsJson

File

src/Entity/SolrFieldType.php, line 177

Class

SolrFieldType
Defines the SolrFieldType entity.

Namespace

Drupal\search_api_solr_multilingual\Entity

Code

public function setFieldTypeAsJson($field_type) {
  $field_type = $this->field_type = Json::decode($field_type);

  // Unfortunately the JSON encoded field type definition still uses the
  // element names "indexAnalyzer", "queryAnalyzer" and "multiTermAnalyzer"
  // which are deprecated in the XML format. Therefor we need to add some
  // conversion logic.
  foreach ([
    'index' => 'indexAnalyzer',
    'query' => 'queryAnalyzer',
    'multiterm' => 'multiTermAnalyzer',
    'analyzer' => 'analyzer',
  ] as $type => $analyzer) {
    if (!empty($field_type[$analyzer])) {
      unset($this->field_type[$analyzer]);
      if ($type != $analyzer) {
        $field_type[$analyzer]['type'] = $type;
      }
      $this->field_type['analyzers'][] = $field_type[$analyzer];
    }
  }
  return $this;
}