1 search.admin.inc search_admin_settings($form, &$form_state)

Menu callback: displays the search module settings page.

See also

search_admin_settings_validate()

search_admin_settings_submit()

search_admin_reindex_submit()

Related topics

File

core/modules/search/search.admin.inc, line 113
Admin page callbacks for the Search module.

Code

function search_admin_settings($form, &$form_state) {
  $config = config('search.settings');

  $form['active'] = array(
    '#type' => 'fieldset',
    '#title' => t('Search items')
  );
  $search_info = search_get_info(TRUE);
  $module_options = array();
  foreach ($search_info as $module => $info) {
    $module_options[$module] = $info['title'];
  }
  $form['active']['search_active_modules'] = array(
    '#title' => t('Available search items'),
    '#type' => 'checkboxes',
    '#default_value' => $config->get('search_active_modules'),
    '#options' => $module_options,
    '#description' => t('Several modules expose items to the search system. Use this setting to limit what can be searched.')
  );
  $form['active']['search_default_module'] = array(
    '#title' => t('Default search'),
    '#type' => 'radios',
    '#default_value' => $config->get('search_default_module'),
    '#options' => $module_options,
    '#description' => t('Only one type of item will be searched by default. This selection will determine what appears at <a href="@search">@search</a>.', array('@search' => url('search', array('absolute' => TRUE)))),
  );

  $form['pager'] = array(
    '#type' => 'fieldset',
    '#title' => t('Pager type'),
  );
  $pager_type = $config->get('search_pager_type');
  $form['pager']['search_pager_type'] = array(
    '#type' => 'radios',
    '#title' => t('Pager type'),
    '#title_display' => 'invisible',
    '#options' => array(
      'full' => t('Full pager'),
      'mini' => t('Mini pager'),
    ),
    '#default_value' => isset($pager_type) ? $pager_type : 'full',
  );
  $form['pager']['search_pager_type']['full']['#description'] = t('Includes "Previous"/"Next" and "First"/"Last" links, as well as numbered links for each page of the search results.');
  $form['pager']['search_pager_type']['mini']['#description'] = t('Shows only "Previous"/"Next" links, and indications of the current and total number of search results pages.');

  $form['logging'] = array(
    '#type' => 'fieldset',
    '#title' => t('Logging'),
  );
  $form['logging']['search_logging'] = array(
    '#type' => 'checkbox',
    '#title' => t('Log all searches'),
    '#default_value' => $config->get('search_logging'),
    '#description' => t('This setting may affect performance. Enable only if actively inspecting logs of search queries.'),
  );
  $form['#validate'][] = 'search_admin_settings_validate';
  $form['#submit'][] = 'search_admin_settings_submit';

  // Per module settings
  foreach ($config->get('search_active_modules') as $module) {
    $added_form = module_invoke($module, 'search_admin');
    if (is_array($added_form)) {
      $form = array_merge($form, $added_form);
    }
  }
  $form['actions']['#type'] = 'actions';
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
  );

  // Indexing settings:
  $form['indexing'] = array(
    '#type' => 'fieldset',
    '#title' => t('Indexing'),
  );

  // Collect some stats
  $index_stats = search_get_stats();

  $count = format_plural($index_stats['remaining'], 'There is 1 item left to index.', 'There are @count items left to index.');
  $percentage = ((int) min(100, 100 * ($index_stats['total'] - $index_stats['remaining']) / max(1, $index_stats['total']))) . '%';
  $status = '<p><strong>' . t('%percentage of the site has been indexed.', array('%percentage' => $percentage)) . ' ' . $count . '</strong></p>';

  $form['indexing']['status'] = array('#markup' => $status);
  $form['indexing']['wipe'] = array(
    '#type' => 'submit',
    '#value' => t('Rebuild search index'),
    '#submit' => array('search_admin_reindex_submit'),
    '#attributes' => array('class' => array('button-secondary')),
  );

  $items = backdrop_map_assoc(array(10, 20, 50, 100, 200, 500));
  $form['indexing']['search_cron_limit'] = array(
    '#type' => 'select',
    '#title' => t('Number of items to index during cron runs:'),
    '#default_value' => $config->get('search_cron_limit'),
    '#options' => $items,
    '#description' => t('The maximum number of items indexed in each pass of a <a href="@cron">cron maintenance task</a>. If necessary, reduce this number to prevent timeouts and memory errors while indexing.', array('@cron' => url('admin/reports/status'))),
  );

  $form['indexing']['search_minimum_word_size'] = array(
    '#type' => 'number',
    '#title' => t('Minimum word length to index'),
    '#default_value' => $config->get('search_minimum_word_size'),
    '#min' => 1,
    '#max' => 10000,
    '#description' => t('The number of characters a word has to be to be indexed. A lower setting means better search result ranking, but also a larger database. Each search query must contain at least one keyword that is this size (or longer). <strong>Changing this setting will invalidate the search index.</strong>'),
  );
  $form['indexing']['transliteration'] = array(
    '#type' => 'checkbox',
    '#title' => t('Transliterate search index and searched strings.'),
    '#description' => t('Enable to allow searching and indexing using US-ASCII character set, i.e. to treat accented and unaccented letters the same.'),
    '#default_value' => $config->get('transliteration'),
  );
  $form['indexing']['search_overlap_cjk'] = array(
    '#type' => 'checkbox',
    '#title' => t('Simple CJK handling'),
    '#default_value' => $config->get('search_overlap_cjk'),
    '#description' => t('Whether to apply a simple Chinese/Japanese/Korean tokenizer based on overlapping sequences. Turn this off if you want to use an external preprocessor for this instead. Does not affect other languages. <strong>Changing this setting will invalidate the search index.</strong>'),
  );

  $form['actions']['#type'] = 'actions';
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
  );

  return $form;
}