You are here

protected function SearchApiSolrMultilingualManagedSchemaBackend::createSolrDynamicField in Search API Multilingual Solr Search 8

Creates and deploys a missing dynamic Solr field if the server supports it.

Parameters

string $solr_field_name: The name of the new dynamic Solr field.

string $solr_field_type_name: The name of the Solr Field Type to be used for the new dynamic Solr field.

Overrides AbstractSearchApiSolrMultilingualBackend::createSolrDynamicField

File

src/Plugin/search_api/backend/SearchApiSolrMultilingualManagedSchemaBackend.php, line 29

Class

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…

Namespace

Drupal\search_api_solr_multilingual\Plugin\search_api\backend

Code

protected function createSolrDynamicField($solr_field_name, $solr_field_type_name) {

  // @todo leverage SolrFieldType::getDynamicFields().
  $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 (SearchApiSolrMultilingualException $e) {
    watchdog_exception('solr', $e);
    return FALSE;
  }
  return TRUE;
}