You are here

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

Gets the Solr Field Type definition as JSON.

The JSON format is used to interact with a managed Solr schema.

Return value

string The Solr Field Type definition as JSON.

Overrides SolrFieldTypeInterface::getFieldTypeAsJson

File

src/Entity/SolrFieldType.php, line 149

Class

SolrFieldType
Defines the SolrFieldType entity.

Namespace

Drupal\search_api_solr_multilingual\Entity

Code

public function getFieldTypeAsJson() {

  // 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.
  $field_type = $this->field_type;
  unset($field_type['analyzers']);
  foreach ($this->field_type['analyzers'] as $analyzer) {
    $type = 'analyzer';
    if (!empty($analyzer['type'])) {
      if ('multiterm' == $analyzer['type']) {
        $type = 'multiTermAnalyzer';
      }
      else {
        $type = $analyzer['type'] . 'Analyzer';
      }
      unset($analyzer['type']);
    }
    $field_type[$type] = $analyzer;
  }
  return Json::encode($field_type);
}