/[drupal]/drupal/modules/search/search.admin.inc
ViewVC logotype

Contents of /drupal/modules/search/search.admin.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.12 - (show annotations) (download) (as text)
Fri Sep 18 00:12:47 2009 UTC (2 months, 1 week ago) by webchick
Branch: MAIN
CVS Tags: DRUPAL-7-0-UNSTABLE-10, HEAD
Changes since 1.11: +2 -2 lines
File MIME type: text/x-php
#571086 by sun and merlinofchaos: Added a 'wrapper callback' that executes
before a form builder function, to facilitate common form elements. Clean-up
from form_builder changes from CTools patch. Has nice side-benefit of making
all form functions' signatures consistent.
1 <?php
2 // $Id: search.admin.inc,v 1.11 2009/08/29 21:05:16 dries Exp $
3
4 /**
5 * @file
6 * Admin page callbacks for the search module.
7 */
8
9 /**
10 * Menu callback: confirm wiping of the index.
11 */
12 function search_reindex_confirm() {
13 return confirm_form(array(), t('Are you sure you want to re-index the site?'),
14 'admin/config/search/settings', 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'));
15 }
16
17 /**
18 * Handler for wipe confirmation
19 */
20 function search_reindex_confirm_submit(&$form, &$form_state) {
21 if ($form['confirm']) {
22 search_reindex();
23 drupal_set_message(t('The index will be rebuilt.'));
24 $form_state['redirect'] = 'admin/config/search/settings';
25 return;
26 }
27 }
28
29 /**
30 * Helper function to get real module names.
31 */
32 function _search_get_module_names() {
33
34 $search_info = search_get_info();
35 $modules = db_select('system', 's')
36 ->fields('s', array('name', 'info'))
37 ->condition('s.status', 1)
38 ->condition('s.type', 'module')
39 ->condition('s.name', array_keys($search_info), 'IN')
40 ->orderBy('s.name')
41 ->execute();
42 $names = array();
43 foreach ($modules as $item) {
44 $info = unserialize($item->info);
45 $names[$item->name] = $info['name'];
46 }
47 return $names;
48 }
49
50 /**
51 * Menu callback; displays the search module settings page.
52 *
53 * @ingroup forms
54 * @see system_settings_form()
55 * @see search_admin_settings_submit()
56 * @see search_admin_reindex_submit()
57 */
58 function search_admin_settings($form) {
59 // Collect some stats
60 $remaining = 0;
61 $total = 0;
62 foreach(variable_get('search_active_modules', array('node', 'user')) as $module) {
63 if ($status = module_invoke($module, 'search_status')) {
64 $remaining += $status['remaining'];
65 $total += $status['total'];
66 }
67 }
68
69 $count = format_plural($remaining, 'There is 1 item left to index.', 'There are @count items left to index.');
70 $percentage = ((int)min(100, 100 * ($total - $remaining) / max(1, $total))) . '%';
71 $status = '<p><strong>' . t('%percentage of the site has been indexed.', array('%percentage' => $percentage)) . ' ' . $count . '</strong></p>';
72 $form['status'] = array('#type' => 'fieldset', '#title' => t('Indexing status'));
73 $form['status']['status'] = array('#markup' => $status);
74 $form['status']['wipe'] = array('#type' => 'submit', '#value' => t('Re-index site'), '#submit' => array('search_admin_reindex_submit'));
75
76 $items = drupal_map_assoc(array(10, 20, 50, 100, 200, 500));
77
78 // Indexing throttle:
79 $form['indexing_throttle'] = array(
80 '#type' => 'fieldset',
81 '#title' => t('Indexing throttle')
82 );
83 $form['indexing_throttle']['search_cron_limit'] = array(
84 '#type' => 'select',
85 '#title' => t('Number of items to index per cron run'),
86 '#default_value' => 100,
87 '#options' => $items,
88 '#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')))
89 );
90 // Indexing settings:
91 $form['indexing_settings'] = array(
92 '#type' => 'fieldset',
93 '#title' => t('Indexing settings')
94 );
95 $form['indexing_settings']['info'] = array(
96 '#markup' => 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>')
97 );
98 $form['indexing_settings']['minimum_word_size'] = array(
99 '#type' => 'textfield',
100 '#title' => t('Minimum word length to index'),
101 '#default_value' => 3,
102 '#size' => 5,
103 '#maxlength' => 3,
104 '#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).')
105 );
106 $form['indexing_settings']['overlap_cjk'] = array(
107 '#type' => 'checkbox',
108 '#title' => t('Simple CJK handling'),
109 '#default_value' => TRUE,
110 '#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.')
111 );
112
113 $form['search_active_modules'] = array(
114 '#type' => 'checkboxes',
115 '#title' => t('Active search modules'),
116 '#default_value' => array('node', 'user'),
117 '#options' => _search_get_module_names(),
118 '#description' => t('Determine which search modules are active from the available modules.')
119 );
120
121 $form['#submit'][] = 'search_admin_settings_submit';
122
123 // Per module settings
124 foreach(variable_get('search_active_modules', array('node', 'user')) as $module) {
125 $added_form = module_invoke($module, 'search_admin');
126 if (is_array($added_form)) {
127 $form = array_merge($form, $added_form);
128 }
129 }
130
131 return system_settings_form($form, TRUE);
132 }
133
134 /**
135 * Submit callback.
136 */
137 function search_admin_settings_submit($form, &$form_state) {
138 // If these settings change, the index needs to be rebuilt.
139 if ((variable_get('minimum_word_size', 3) != $form_state['values']['minimum_word_size']) ||
140 (variable_get('overlap_cjk', TRUE) != $form_state['values']['overlap_cjk'])) {
141 drupal_set_message(t('The index will be rebuilt.'));
142 search_reindex();
143 }
144 $current_modules = variable_get('search_active_modules', array('node', 'user'));
145 // Check whether we are resetting the values.
146 if ($form_state['clicked_button']['#value'] == t('Reset to defaults')) {
147 $new_modules = array('node', 'user');
148 }
149 else {
150 $new_modules = array_filter($form_state['values']['search_active_modules']);
151 }
152 if (array_diff($current_modules, $new_modules)) {
153 drupal_set_message(t('The active search modules have been changed.'));
154 variable_set('menu_rebuild_needed', TRUE);
155 }
156 }
157
158 /**
159 * Submit callback.
160 */
161 function search_admin_reindex_submit($form, &$form_state) {
162 // send the user to the confirmation page
163 $form_state['redirect'] = 'admin/config/search/settings/reindex';
164 }

  ViewVC Help
Powered by ViewVC 1.1.2