00001 <?php
00002
00003
00012 function search_wipe_confirm() {
00013 return confirm_form(array(), t('Are you sure you want to re-index the site?'),
00014 'admin/settings/search', t(' The search index is not cleared but systematically updated to reflect the new settings. Searching will continue to work but new content won\'t be indexed until all existing content has been re-indexed. This action cannot be undone.'), t('Re-index site'), t('Cancel'));
00015 }
00016
00020 function search_wipe_confirm_submit(&$form, &$form_state) {
00021 if ($form['confirm']) {
00022 search_wipe();
00023 drupal_set_message(t('The index will be rebuilt.'));
00024 $form_state['redirect'] = 'admin/settings/search';
00025 return;
00026 }
00027 }
00028
00036 function search_admin_settings() {
00037
00038 $remaining = 0;
00039 $total = 0;
00040 foreach (module_list() as $module) {
00041 if (module_hook($module, 'search')) {
00042 $status = module_invoke($module, 'search', 'status');
00043 $remaining += $status['remaining'];
00044 $total += $status['total'];
00045 }
00046 }
00047 $count = format_plural($remaining, 'There is 1 item left to index.', 'There are @count items left to index.');
00048 $percentage = ((int)min(100, 100 * ($total - $remaining) / max(1, $total))) . '%';
00049 $status = '<p><strong>' . t('%percentage of the site has been indexed.', array('%percentage' => $percentage)) . ' ' . $count . '</strong></p>';
00050 $form['status'] = array('#type' => 'fieldset', '#title' => t('Indexing status'));
00051 $form['status']['status'] = array('#value' => $status);
00052 $form['status']['wipe'] = array('#type' => 'submit', '#value' => t('Re-index site'));
00053
00054 $items = drupal_map_assoc(array(10, 20, 50, 100, 200, 500));
00055
00056
00057 $form['indexing_throttle'] = array('#type' => 'fieldset', '#title' => t('Indexing throttle'));
00058 $form['indexing_throttle']['search_cron_limit'] = array('#type' => 'select', '#title' => t('Number of items to index per cron run'), '#default_value' => variable_get('search_cron_limit', 100), '#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 the number of items to prevent timeouts and memory errors while indexing.', array('@cron' => url('admin/reports/status'))));
00059
00060 $form['indexing_settings'] = array('#type' => 'fieldset', '#title' => t('Indexing settings'));
00061 $form['indexing_settings']['info'] = array('#value' => t('<p><em>Changing the settings below will cause the site index to be rebuilt. The search index is not cleared but systematically updated to reflect the new settings. Searching will continue to work but new content won\'t be indexed until all existing content has been re-indexed.</em></p><p><em>The default settings should be appropriate for the majority of sites.</em></p>'));
00062 $form['indexing_settings']['minimum_word_size'] = array('#type' => 'textfield', '#title' => t('Minimum word length to index'), '#default_value' => variable_get('minimum_word_size', 3), '#size' => 5, '#maxlength' => 3, '#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).'));
00063 $form['indexing_settings']['overlap_cjk'] = array('#type' => 'checkbox', '#title' => t('Simple CJK handling'), '#default_value' => variable_get('overlap_cjk', TRUE), '#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.'));
00064
00065 $form['#validate'] = array('search_admin_settings_validate');
00066
00067
00068 $form = array_merge($form, module_invoke_all('search', 'admin'));
00069 return system_settings_form($form);
00070 }
00071
00075 function search_admin_settings_validate($form, &$form_state) {
00076 if ($form_state['values']['op'] == t('Re-index site')) {
00077 drupal_goto('admin/settings/search/wipe');
00078 }
00079
00080 if ((variable_get('minimum_word_size', 3) != $form_state['values']['minimum_word_size']) ||
00081 (variable_get('overlap_cjk', TRUE) != $form_state['values']['overlap_cjk'])) {
00082 drupal_set_message(t('The index will be rebuilt.'));
00083 search_wipe();
00084 }
00085 }