You are here

public function SearchApiDbService::configurationForm in Search API Database Search 7

Implements SearchApiServiceInterface::__construct().

Returns an empty form by default.

Overrides SearchApiAbstractService::configurationForm

File

./service.inc, line 78
Contains SearchApiDbService.

Class

SearchApiDbService
Indexes and searches items using the database.

Code

public function configurationForm(array $form, array &$form_state) {

  // Discern between creation and editing of a server, since we don't allow
  // the database to be changed later on.
  if (empty($this->options)) {
    global $databases;
    foreach ($databases as $key => $targets) {
      foreach ($targets as $target => $info) {
        $options[$key]["{$key}:{$target}"] = "{$key} > {$target}";
      }
    }
    if (count($options) > 1 || count(reset($options)) > 1) {
      $form['database'] = array(
        '#type' => 'select',
        '#title' => t('Database'),
        '#description' => t('Select the database key and target to use for storing indexing information in. ' . 'Cannot be changed after creation.'),
        '#options' => $options,
        '#default_value' => 'default:default',
        '#required' => TRUE,
      );
    }
    else {
      $form['database'] = array(
        '#type' => 'value',
        '#value' => "{$key}:{$target}",
      );
    }
  }
  else {
    $form = array(
      'database' => array(
        '#type' => 'value',
        '#value' => $this->options['database'],
      ),
      'database_text' => array(
        '#type' => 'item',
        '#title' => t('Database'),
        '#markup' => check_plain(str_replace(':', ' > ', $this->options['database'])),
      ),
    );
  }

  // Set default settings.
  $options = $this->options + array(
    'min_chars' => 1,
    'autocomplete' => array(),
    'partial_matches' => FALSE,
  );
  $options['autocomplete'] += array(
    'suggest_suffix' => TRUE,
    'suggest_words' => TRUE,
  );
  $form['min_chars'] = array(
    '#type' => 'select',
    '#title' => t('Minimum word length'),
    '#description' => t('The minimum number of characters a word must consist of to be indexed.'),
    '#options' => drupal_map_assoc(array(
      1,
      2,
      3,
      4,
      5,
      6,
    )),
    '#default_value' => $options['min_chars'],
  );
  $form['partial_matches'] = array(
    '#type' => 'checkbox',
    '#title' => t('Search on parts of a word'),
    '#description' => t('Find keywords in parts of a word, too. (E.g., find results with "database" when searching for "base"). <strong>Caution:</strong> This can make searches much slower on large sites!'),
    '#default_value' => $options['partial_matches'],
  );
  if (module_exists('search_api_autocomplete')) {
    $form['autocomplete'] = array(
      '#type' => 'fieldset',
      '#title' => t('Autocomplete settings'),
      '#description' => t('These settings allow you to configure how suggestions are computed when autocompletion is used. If you are seeing many inappropriate suggestions you might want to deactivate the corresponding suggestion type. You can also deactivate one method to speed up the generation of suggestions.'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $form['autocomplete']['suggest_suffix'] = array(
      '#type' => 'checkbox',
      '#title' => t('Suggest word endings'),
      '#description' => t('Suggest endings for the currently entered word.'),
      '#default_value' => $options['autocomplete']['suggest_suffix'],
    );
    $form['autocomplete']['suggest_words'] = array(
      '#type' => 'checkbox',
      '#title' => t('Suggest additional words'),
      '#description' => t('Suggest additional words the user might want to search for.'),
      '#default_value' => $options['autocomplete']['suggest_words'],
    );
  }
  return $form;
}