You are here

public function SearchApiSolrBackend::buildConfigurationForm in Search API Solr 4.x

Same name and namespace in other branches
  1. 8.3 src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::buildConfigurationForm()
  2. 8 src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::buildConfigurationForm()
  3. 8.2 src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::buildConfigurationForm()

Throws

\Drupal\Component\Plugin\Exception\PluginException

\Drupal\search_api\SearchApiException

Overrides PluginFormInterface::buildConfigurationForm

File

src/Plugin/search_api/backend/SearchApiSolrBackend.php, line 301

Class

SearchApiSolrBackend
Apache Solr backend for search api.

Namespace

Drupal\search_api_solr\Plugin\search_api\backend

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $solr_connector_options = $this
    ->getSolrConnectorOptions();
  $form['connector'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Solr Connector'),
    '#description' => $this
      ->t('Choose a connector to use for this Solr server.'),
    '#options' => $solr_connector_options,
    '#default_value' => $this->configuration['connector'],
    '#required' => TRUE,
    '#ajax' => [
      'callback' => [
        get_class($this),
        'buildAjaxSolrConnectorConfigForm',
      ],
      'wrapper' => 'search-api-solr-connector-config-form',
      'method' => 'replace',
      'effect' => 'fade',
    ],
  ];
  $this
    ->buildConnectorConfigForm($form, $form_state);
  $form['advanced'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Advanced'),
  ];
  $form['advanced']['rows'] = [
    '#type' => 'number',
    '#min' => 0,
    // The max rows that could be returned by Solr are the max 32bit integer.
    '#max' => 2147483630,
    '#title' => $this
      ->t('Default result rows'),
    '#description' => $this
      ->t('Solr always requires to limit the search results. This default value will be set if the Search API query itself is not limited. 2147483630 is the theoretical maximum since the result pointer is an integer. But be careful! Especially in Solr Cloud setups too high values might cause an OutOfMemoryException because Solr reserves this rows limit per shard for sorting the combined result. This sum must not exceed the maximum integer value! And even if there is no exception any too high memory consumption per query on your server is a bad thing in general.'),
    '#default_value' => $this->configuration['rows'] ?: 10,
    '#required' => TRUE,
  ];
  $form['advanced']['index_single_documents_fallback_count'] = [
    '#type' => 'number',
    '#min' => 0,
    '#max' => 100,
    '#title' => $this
      ->t('Index single documents fallback count'),
    '#description' => $this
      ->t('In case of an erroneous document that causes a Solr exception, the entire batch of documents will not be indexed. In order to identify the erroneous document and to keep indexing the others, the indexing process falls back to index documents one by one instead of a batch. This setting limits the amount of single documents to be indexed per batch to avoid too many commits that might slow doen the Solr server. Setting the value to "0" disables the fallback.'),
    '#default_value' => $this->configuration['index_single_documents_fallback_count'] ?: 10,
    '#required' => TRUE,
  ];
  $form['advanced']['retrieve_data'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Retrieve result data from Solr'),
    '#description' => $this
      ->t('When checked, result data will be retrieved directly from the Solr server. This might make item loads unnecessary. Only indexed fields can be retrieved. Note also that the returned field data might not always be correct, due to preprocessing and caching issues.'),
    '#default_value' => $this->configuration['retrieve_data'],
  ];
  $form['advanced']['highlight_data'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Retrieve highlighted snippets'),
    '#description' => $this
      ->t('Return a highlighted version of the indexed fulltext fields. These will be used by the "Highlighting Processor" directly instead of applying its own PHP algorithm.'),
    '#default_value' => $this->configuration['highlight_data'],
  ];
  $form['advanced']['fallback_multiple'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Fallback to multiValued field types'),
    '#description' => $this
      ->t('If the cardinality of a field or a property could not be detected (due to incomplete custom module implementations), a single value field type will be used within the Solr index for better performance. If this leads to "multiple values encountered for non multiValued field" exceptions you can set this option to change the fallback to multiValued.'),
    '#default_value' => $this->configuration['fallback_multiple'],
  ];
  $form['advanced']['server_prefix'] = [
    '#type' => 'textfield',
    '#title' => t('All index prefix'),
    '#description' => t("By default, the index ID in the Solr server is the same as the index's machine name in Drupal. This setting will let you specify an additional prefix. Only use alphanumeric characters and underscores. Since changing the prefix makes the currently indexed data inaccessible, you should not change this variable when no data is indexed."),
    '#default_value' => $this->configuration['server_prefix'],
  ];
  $domains = SolrFieldType::getAvailableDomains();
  $form['advanced']['domain'] = [
    '#type' => 'select',
    '#options' => array_combine($domains, $domains),
    '#title' => $this
      ->t('Targeted content domain'),
    '#description' => $this
      ->t('For example "UltraBot3000" would be indexed as "Ultra" "Bot" "3000" in a generic domain, "CYP2D6" has to stay like it is in a scientific domain.'),
    '#default_value' => isset($this->configuration['domain']) ? $this->configuration['domain'] : 'generic',
  ];
  $environments = Utility::getAvailableEnvironments();
  $form['advanced']['environment'] = [
    '#type' => 'select',
    '#options' => array_combine($environments, $environments),
    '#title' => $this
      ->t('Targeted environment'),
    '#description' => $this
      ->t('For example "dev", "stage" or "prod".'),
    '#default_value' => isset($this->configuration['environment']) ? $this->configuration['environment'] : 'default',
  ];
  $form['advanced']['i_know_what_i_do'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Optimize the Solr index'),
    '#description' => $this
      ->t('Optimize the Solr index once a day. Even if this option "sounds good", think twice before activating it! For most Solr setups it\'s recommended to NOT enable this feature!'),
    '#default_value' => $this->configuration['optimize'],
  ];
  $form['advanced']['optimize'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t("Yes, I know what I'm doing and want to enable a daily optimization!"),
    '#default_value' => $this->configuration['optimize'],
    '#states' => [
      'invisible' => [
        ':input[name="backend_config[advanced][i_know_what_i_do]"]' => [
          'checked' => FALSE,
        ],
      ],
    ],
  ];
  $form['multisite'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Multi-site compatibility'),
    '#description' => $this
      ->t("By default a single Solr backend based Search API server is able to index the data of multiple Drupal sites. But this is an expert-only and dangerous feature that mainly exists for backward compatibility. If you really index multiple sites in one index and don't activate 'Retrieve results for this site only' below you have to ensure that you enable 'Retrieve result data from Solr'! Otherwise it could lead to any kind of errors!"),
  ];
  $description = $this
    ->t("Automatically filter all searches to only retrieve results from this Drupal site. The default and intended behavior is to display results from all sites. WARNING: Enabling this filter might break features like autocomplete, spell checking or suggesters!");
  $form['multisite']['site_hash'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Retrieve results for this site only'),
    '#description' => $description,
    '#default_value' => $this->configuration['site_hash'],
  ];
  $form['disabled_field_types'] = [
    '#type' => 'value',
    '#value' => $this
      ->getDisabledFieldTypes(),
  ];
  $form['disabled_caches'] = [
    '#type' => 'value',
    '#value' => $this
      ->getDisabledCaches(),
  ];
  $form['disabled_request_handlers'] = [
    '#type' => 'value',
    '#value' => $this
      ->getDisabledRequestHandlers(),
  ];
  $form['disabled_request_dispatchers'] = [
    '#type' => 'value',
    '#value' => $this
      ->getDisabledRequestDispatchers(),
  ];
  return $form;
}