You are here

public function FuzzySearchService::configurationForm in Fuzzy Search 7

Implements SearchApiServiceInterface::__construct().

Returns an empty form by default.

Overrides SearchApiAbstractService::configurationForm

File

includes/service.inc, line 16

Class

FuzzySearchService
Search service class using the database for storing index information.

Code

public function configurationForm(array $form, array &$form_state) {
  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}",
      );
    }
    $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. A higher Fuzzy Search ngram length will override this.'),
      '#options' => drupal_map_assoc(array(
        1,
        2,
        3,
        4,
        5,
        6,
      )),
      '#default_value' => 3,
    );
  }
  else {
    $form = array(
      'database' => array(
        '#type' => 'value',
        // Slight hack for the "View server" page.
        '#title' => t('Database'),
        '#value' => $this->options['database'],
      ),
      'database_text' => array(
        '#type' => 'item',
        '#title' => t('Database'),
        '#markup' => check_plain(str_replace(':', ' > ', $this->options['database'])),
      ),
      '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' => $this->options['min_chars'],
      ),
    );
  }
  return $form;
}