SearchApiSolrMultilingualManagedSchemaBackend.php in Search API Solr 8.2
File
src/Plugin/search_api/backend/SearchApiSolrMultilingualManagedSchemaBackend.php
View source
<?php
namespace Drupal\search_api_solr\Plugin\search_api\backend;
use Drupal\Component\Serialization\Json;
use Drupal\search_api_solr\Utility\Utility;
use Drupal\search_api_solr\Entity\SolrFieldType;
use Drupal\search_api_solr\SearchApiSolrException;
class SearchApiSolrMultilingualManagedSchemaBackend extends AbstractSearchApiSolrMultilingualBackend {
public function isManagedSchema() {
return TRUE;
}
protected function createSolrDynamicField($solr_field_name, $solr_field_type_name) {
$command = [
'add-dynamic-field' => [
'name' => $solr_field_name,
'type' => $solr_field_type_name,
'stored' => TRUE,
'indexed' => TRUE,
'multiValued' => strpos($solr_field_name, 'tm_') === 0 ? TRUE : FALSE,
'termVectors' => strpos($solr_field_name, 't') === 0 ? TRUE : FALSE,
],
];
try {
$this
->solrHelper()
->coreRestPost('schema', Json::encode($command));
} catch (SearchApiSolrException $e) {
watchdog_exception('solr', $e);
return FALSE;
}
return TRUE;
}
protected function createSolrMultilingualFieldType($solr_field_type_name) {
$field_type_name = 'm_' . Utility::decodeSolrName($solr_field_type_name) . '_5_2_0';
$field_type_entity = SolrFieldType::load($field_type_name);
if (!$field_type_entity) {
throw new SearchApiSolrException("There's no field type {$field_type_name}.");
}
$field_type_definition = $field_type_entity
->getFieldType();
$field_type_definition['name'] = $solr_field_type_name;
$command_json = '{ "add-field-type": ' . Json::encode($field_type_definition) . '}';
$command_json = str_replace('"' . $field_type_name . '"', '"' . $solr_field_type_name . '"', $command_json);
try {
$this
->solrHelper()
->coreRestPost('schema', $command_json);
} catch (SearchApiSolrException $e) {
watchdog_exception('solr', $e);
return FALSE;
}
return TRUE;
}
}
Classes
Name |
Description |
SearchApiSolrMultilingualManagedSchemaBackend |
Plugin annotation
@SearchApiBackend(
id = "search_api_solr_multilingual_managed_schema",
label = @Translation("Multilingual Solr Managed Schema (Experimental, don't use in production)."),
description = @Translation("Index items using an Solr… |