You are here

public function SearchApiSolrService::configurationForm in Search API Solr 7

Implements SearchApiServiceInterface::__construct().

Returns an empty form by default.

Overrides SearchApiAbstractService::configurationForm

File

includes/service.inc, line 62

Class

SearchApiSolrService
Search service class using Solr server.

Code

public function configurationForm(array $form, array &$form_state) {
  if ($this->options) {

    // Editing this server
    $form['server_description'] = array(
      '#type' => 'item',
      '#title' => t('Solr server URI'),
      '#description' => $this
        ->getServerLink(),
    );
  }
  $options = $this->options + array(
    'scheme' => 'http',
    'host' => 'localhost',
    'port' => '8983',
    'path' => '/solr',
    'http_user' => '',
    'http_pass' => '',
    'excerpt' => FALSE,
    'retrieve_data' => FALSE,
    'highlight_data' => FALSE,
    'skip_schema_check' => FALSE,
    'log_query' => FALSE,
    'log_response' => FALSE,
    'commits_disabled' => FALSE,
    'solr_version' => '',
    'http_method' => 'AUTO',
    // Default to TRUE for new servers, but to FALSE for existing ones.
    'clean_ids' => $this->options ? FALSE : TRUE,
    'site_hash' => $this->options ? FALSE : TRUE,
    'autocorrect_spell' => TRUE,
    'autocorrect_suggest_words' => TRUE,
    'highlight_prefix' => '',
    'highlight_suffix' => '',
  );
  if (!$options['clean_ids']) {
    if (module_exists('advanced_help')) {
      $variables['@url'] = url('help/search_api_solr/README.txt');
    }
    else {
      $variables['@url'] = url(drupal_get_path('module', 'search_api_solr') . '/README.txt');
    }
    $description = t('Change Solr field names to be more compatible with advanced features. Doing this leads to re-indexing of all indexes on this server. See <a href="@url">README.txt</a> for details.', $variables);
    $form['clean_ids_form'] = array(
      '#type' => 'fieldset',
      '#title' => t('Clean field identifiers'),
      '#description' => $description,
      '#collapsible' => TRUE,
    );
    $form['clean_ids_form']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Switch to clean field identifiers'),
      '#submit' => array(
        '_search_api_solr_switch_to_clean_ids',
      ),
    );
  }
  $form['clean_ids'] = array(
    '#type' => 'value',
    '#value' => $options['clean_ids'],
  );
  if (!$options['site_hash']) {
    $description = t('If you want to index content from multiple sites on a single Solr server, you should enable the multi-site compatibility here. Note, however, that this will completely clear all search indexes (from this site) lying on this server. All content will have to be re-indexed.');
    $form['site_hash_form'] = array(
      '#type' => 'fieldset',
      '#title' => t('Multi-site compatibility'),
      '#description' => $description,
      '#collapsible' => TRUE,
    );
    $form['site_hash_form']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Turn on multi-site compatibility and clear all indexes'),
      '#submit' => array(
        '_search_api_solr_switch_to_site_hash',
      ),
    );
  }
  $form['site_hash'] = array(
    '#type' => 'value',
    '#value' => $options['site_hash'],
  );
  $form['scheme'] = array(
    '#type' => 'select',
    '#title' => t('HTTP protocol'),
    '#description' => t('The HTTP protocol to use for sending queries.'),
    '#default_value' => $options['scheme'],
    '#options' => array(
      'http' => 'http',
      'https' => 'https',
    ),
  );
  $form['host'] = array(
    '#type' => 'textfield',
    '#title' => t('Solr host'),
    '#description' => t('The host name or IP of your Solr server, e.g. <code>localhost</code> or <code>www.example.com</code>.'),
    '#default_value' => $options['host'],
    '#required' => TRUE,
  );
  $form['port'] = array(
    '#type' => 'textfield',
    '#title' => t('Solr port'),
    '#description' => t('The Jetty example server is at port 8983, while Tomcat uses 8080 by default.'),
    '#default_value' => $options['port'],
    '#required' => TRUE,
  );
  $form['path'] = array(
    '#type' => 'textfield',
    '#title' => t('Solr path'),
    '#description' => t('The path that identifies the Solr instance to use on the server. (For Solr versions 4 and above, this should include the name of the core to use.)'),
    '#default_value' => $options['path'],
  );
  $form['http'] = array(
    '#type' => 'fieldset',
    '#title' => t('Basic HTTP authentication'),
    '#description' => t('If your Solr server is protected by basic HTTP authentication, enter the login data here.'),
    '#collapsible' => TRUE,
    '#collapsed' => empty($options['http_user']),
  );
  $form['http']['http_user'] = array(
    '#type' => 'textfield',
    '#title' => t('Username'),
    '#default_value' => $options['http_user'],
    // This prefix with no-op text and password field will keep most browsers
    // from autocompleting these fields, which is hardly ever what the user
    // wants.
    '#prefix' => '<input type="text" style="display:none" /><input type="password" style="display:none" />',
  );
  $form['http']['http_pass'] = array(
    '#type' => 'password',
    '#title' => t('Password'),
    '#description' => t('If this field is left blank and the HTTP username is filled out, the current password will not be changed.'),
  );
  $form['advanced'] = array(
    '#type' => 'fieldset',
    '#title' => t('Advanced'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['advanced']['excerpt'] = array(
    '#type' => 'checkbox',
    '#title' => t('Return an excerpt for all results'),
    '#description' => t("If search keywords are given, use Solr's capabilities to create a highlighted search excerpt for each result. " . 'Whether the excerpts will actually be displayed depends on the settings of the search, though.'),
    '#default_value' => $options['excerpt'],
  );

  // Make in-built highlighting from the solr server configurable.
  $form['advanced']['highlight_prefix'] = array(
    '#type' => 'textfield',
    '#title' => t('Highlight prefix'),
    '#default_value' => $options['highlight_prefix'],
    '#description' => t('Change the prefix if using Solr to perform highlighting (not highlight processor). If empty, defaults to %tag', array(
      '%tag' => '<strong>',
    )),
    '#states' => array(
      'invisible' => array(
        array(
          ':input[name="options[form][advanced][excerpt]"]' => array(
            'checked' => FALSE,
          ),
        ),
      ),
    ),
  );
  $form['advanced']['highlight_suffix'] = array(
    '#type' => 'textfield',
    '#title' => t('Highlight suffix'),
    '#default_value' => $options['highlight_suffix'],
    '#description' => t('Change the suffix if using Solr to perform highlighting (not highlight processor). If empty, defaults to %tag', array(
      '%tag' => '</strong>',
    )),
    '#states' => array(
      'invisible' => array(
        array(
          ':input[name="options[form][advanced][excerpt]"]' => array(
            'checked' => FALSE,
          ),
        ),
      ),
    ),
  );
  $form['advanced']['retrieve_data'] = array(
    '#type' => 'checkbox',
    '#title' => t('Retrieve result data from Solr'),
    '#description' => 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' => $options['retrieve_data'],
  );
  $form['advanced']['highlight_data'] = array(
    '#type' => 'checkbox',
    '#title' => t('Highlight retrieved data'),
    '#description' => t('When retrieving result data from the Solr server, try to highlight the search terms in the returned fulltext fields. <strong>Note:</strong> Do not use the "Highlighting" processor for the index together with this option – use one or the other.'),
    '#default_value' => $options['highlight_data'],
  );

  // Highlighting retrieved data only makes sense when we retrieve data.
  // (Actually, internally it doesn't really matter. However, from a user's
  // perspective, having to check both probably makes sense.)
  $form['advanced']['highlight_data']['#states']['invisible'][':input[name="options[form][advanced][retrieve_data]"]']['checked'] = FALSE;
  $form['advanced']['skip_schema_check'] = array(
    '#type' => 'checkbox',
    '#title' => t('Skip schema verification'),
    '#description' => t('Skip the automatic check for schema-compatibility. Use this override if you are seeing an error-message about an incompatible schema.xml configuration file, and you are sure the configuration is compatible.'),
    '#default_value' => $options['skip_schema_check'],
  );
  $form['advanced']['solr_version'] = array(
    '#type' => 'select',
    '#title' => t('Solr version override'),
    '#description' => t('Specify the Solr version manually in case it cannot be retrieved automatically. The version can be found in the Solr admin interface under "Solr Specification Version" or "solr-spec".'),
    '#options' => array(
      '' => t('Determine automatically'),
      '3' => '3.x',
      '4' => '4.x',
      '5' => '5.x',
    ),
    '#default_value' => $options['solr_version'],
  );
  $form['advanced']['http_method'] = array(
    '#type' => 'select',
    '#title' => t('HTTP method'),
    '#description' => t('The HTTP method to use for sending queries. GET will often fail with larger queries, while POST should not be cached. AUTO will use GET when possible, and POST for queries that are too large.'),
    '#default_value' => $options['http_method'],
    '#options' => array(
      'AUTO' => t('AUTO'),
      'POST' => 'POST',
      'GET' => 'GET',
    ),
  );
  $form['advanced']['log_query'] = array(
    '#type' => 'checkbox',
    '#title' => t('Log search requests'),
    '#description' => t('Log all outgoing Solr search requests.'),
    '#default_value' => $options['log_query'],
  );
  $form['advanced']['log_response'] = array(
    '#type' => 'checkbox',
    '#title' => t('Log search results'),
    '#description' => t('Log all search result responses received from Solr. NOTE: This may slow down your site since all response data (including possible retrieved data) will be saved in the Drupal log.'),
    '#default_value' => $options['log_response'],
  );
  $form['advanced']['commits_disabled'] = array(
    '#type' => 'checkbox',
    '#title' => t('Disable explicit committing'),
    '#description' => t('Do not send any commit commands to the Solr server.'),
    '#default_value' => $options['commits_disabled'],
  );
  if (module_exists('search_api_autocomplete')) {
    $form['advanced']['autocomplete'] = array(
      '#type' => 'fieldset',
      '#title' => t('Autocomplete'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $form['advanced']['autocomplete']['autocorrect_spell'] = array(
      '#type' => 'checkbox',
      '#title' => t('Use spellcheck for autocomplete suggestions'),
      '#description' => t('If activated, spellcheck suggestions ("Did you mean") will be included in the autocomplete suggestions. Since the used dictionary contains words from all indexes, this might lead to leaking of sensitive data, depending on your setup.'),
      '#default_value' => $options['autocorrect_spell'],
    );
    $form['advanced']['autocomplete']['autocorrect_suggest_words'] = array(
      '#type' => 'checkbox',
      '#title' => t('Suggest additional words'),
      '#description' => t('If activated and the user enters a complete word, Solr will suggest additional words the user wants to search, which are often found (not searched!) together. This has been known to lead to strange results in some configurations – if you see inappropriate additional-word suggestions, you might want to deactivate this option.'),
      '#default_value' => $options['autocorrect_suggest_words'],
    );
  }
  return $form;
}