You are here

class SearchApiSolrMultilingualManagedSchemaBackend in Search API Multilingual Solr Search 8

Same name and namespace in other branches
  1. 8.3 src/Plugin/search_api/backend/SearchApiSolrMultilingualManagedSchemaBackend.php \Drupal\search_api_solr_multilingual\Plugin\search_api\backend\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 search server with managed schema for dynamic configuration for multilingual content.")
)

Hierarchy

Expanded class hierarchy of SearchApiSolrMultilingualManagedSchemaBackend

File

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

Namespace

Drupal\search_api_solr_multilingual\Plugin\search_api\backend
View source
class SearchApiSolrMultilingualManagedSchemaBackend extends AbstractSearchApiSolrMultilingualBackend {

  /**
   * {@inheritdoc}
   */
  public function isManagedSchema() {
    return TRUE;
  }

  /**
   * {@inheritdoc}
   */
  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;
  }

  /**
   * {@inheritdoc}
   */
  protected function createSolrMultilingualFieldType($solr_field_type_name) {

    // @todo replace the hardcoded version extension.
    $field_type_name = 'm_' . Utility::decodeSolrName($solr_field_type_name) . '_5_2_0';

    // Get the field type definition from Drupal.

    /** @var \Drupal\search_api_solr_multilingual\Entity\SolrFieldType $field_type_entity */
    $field_type_entity = SolrFieldType::load($field_type_name);
    if (!$field_type_entity) {
      throw new SearchApiSolrMultilingualException("There's no field type {$field_type_name}.");
    }
    $field_type_definition = $field_type_entity
      ->getFieldType();
    $field_type_definition['name'] = $solr_field_type_name;

    // Send the config to Solr.
    $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 (SearchApiSolrMultilingualException $e) {
      watchdog_exception('solr', $e);
      return FALSE;
    }
    return TRUE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AbstractSearchApiSolrMultilingualBackend::alterSearchApiQuery protected function Adjusts the language filter before converting the query into a Solr query.
AbstractSearchApiSolrMultilingualBackend::alterSolrDocuments protected function Replaces language unspecific fulltext fields by language specific ones.
AbstractSearchApiSolrMultilingualBackend::alterSolrResponseBody protected function @inheritdoc
AbstractSearchApiSolrMultilingualBackend::buildConfigurationForm public function
AbstractSearchApiSolrMultilingualBackend::getAutocompleteFields protected function
AbstractSearchApiSolrMultilingualBackend::getDomain public function Returns the targeted content domain of the server. Overrides SolrMultilingualBackendInterface::getDomain
AbstractSearchApiSolrMultilingualBackend::getFilterQueries protected function
AbstractSearchApiSolrMultilingualBackend::getLanguageSpecificSolrFieldNames protected function Gets a language-specific mapping from Drupal to Solr field names.
AbstractSearchApiSolrMultilingualBackend::getSchemaLanguageStatistics public function Gets schema language statistics for the multilingual Solr server. Overrides SolrMultilingualBackendInterface::getSchemaLanguageStatistics
AbstractSearchApiSolrMultilingualBackend::hasLanguageUndefinedFallback public function Indicates if the fallback for not supported languages is active. Overrides SolrMultilingualBackendInterface::hasLanguageUndefinedFallback
AbstractSearchApiSolrMultilingualBackend::isPartOfSchema protected function Indicates if an 'element' is part of the Solr server's schema.
AbstractSearchApiSolrMultilingualBackend::postQuery protected function
AbstractSearchApiSolrMultilingualBackend::preQuery protected function Modify the query before it is sent to solr.
AbstractSearchApiSolrMultilingualBackend::setFacets protected function
AbstractSearchApiSolrMultilingualBackend::submitConfigurationForm public function
AbstractSearchApiSolrMultilingualBackend::validateConfigurationForm public function
AbstractSearchApiSolrMultilingualBackend::viewSettings public function
SearchApiSolrMultilingualManagedSchemaBackend::createSolrDynamicField protected function Creates and deploys a missing dynamic Solr field if the server supports it. Overrides AbstractSearchApiSolrMultilingualBackend::createSolrDynamicField
SearchApiSolrMultilingualManagedSchemaBackend::createSolrMultilingualFieldType protected function Creates and deploys a missing Solr Field Type if the server supports it. Overrides AbstractSearchApiSolrMultilingualBackend::createSolrMultilingualFieldType
SearchApiSolrMultilingualManagedSchemaBackend::isManagedSchema public function Indicates if the Solr server uses a managed schema. Overrides AbstractSearchApiSolrMultilingualBackend::isManagedSchema