public function SolrFieldType::setFieldTypeAsJson in Search API Solr 4.x
Same name and namespace in other branches
- 8.3 src/Entity/SolrFieldType.php \Drupal\search_api_solr\Entity\SolrFieldType::setFieldTypeAsJson()
- 8.2 src/Entity/SolrFieldType.php \Drupal\search_api_solr\Entity\SolrFieldType::setFieldTypeAsJson()
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
self Field type as json.
Overrides SolrFieldTypeInterface::setFieldTypeAsJson
File
- src/
Entity/ SolrFieldType.php, line 264
Class
- SolrFieldType
- Defines the SolrFieldType entity.
Namespace
Drupal\search_api_solr\EntityCode
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. Therefore we need to add some
// conversion logic.
$analyzers = [
'index' => 'indexAnalyzer',
'query' => 'queryAnalyzer',
'multiterm' => 'multiTermAnalyzer',
'analyzer' => 'analyzer',
];
foreach ($analyzers 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;
}