public function SolrFieldType::getFieldTypeAsJson in Search API Solr 8.3
Same name and namespace in other branches
- 8.2 src/Entity/SolrFieldType.php \Drupal\search_api_solr\Entity\SolrFieldType::getFieldTypeAsJson()
- 4.x src/Entity/SolrFieldType.php \Drupal\search_api_solr\Entity\SolrFieldType::getFieldTypeAsJson()
Gets the Solr Field Type definition as JSON.
The JSON format is used to interact with a managed Solr schema.
Parameters
bool $pretty: Return pretty printed JSON.
Return value
string The Solr Field Type definition as JSON.
Overrides SolrFieldTypeInterface::getFieldTypeAsJson
File
- src/
Entity/ SolrFieldType.php, line 233
Class
- SolrFieldType
- Defines the SolrFieldType entity.
Namespace
Drupal\search_api_solr\EntityCode
public function getFieldTypeAsJson(bool $pretty = FALSE) {
// 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;
}
/** @noinspection PhpComposerExtensionStubsInspection */
return $pretty ? json_encode($field_type, JSON_PRETTY_PRINT | JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT) : Json::encode($field_type);
}