summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/search/search.admin.inc85
-rw-r--r--modules/search/search.module217
-rw-r--r--modules/search/search.pages.inc136
3 files changed, 236 insertions, 202 deletions
diff --git a/modules/search/search.admin.inc b/modules/search/search.admin.inc
new file mode 100644
index 000000000..c19333c0c
--- /dev/null
+++ b/modules/search/search.admin.inc
@@ -0,0 +1,85 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Admin page callbacks for the search module.
+ */
+
+/**
+ * Menu callback: confirm wiping of the index.
+ */
+function search_wipe_confirm() {
+ return confirm_form(array(), t('Are you sure you want to re-index the site?'),
+ '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'));
+}
+
+/**
+ * Handler for wipe confirmation
+ */
+function search_wipe_confirm_submit(&$form, &$form_state) {
+ if ($form['confirm']) {
+ search_wipe();
+ drupal_set_message(t('The index will be rebuilt.'));
+ $form_state['redirect'] = 'admin/settings/search';
+ return;
+ }
+}
+
+/**
+ * Menu callback; displays the search module settings page.
+ *
+ * @ingroup forms
+ * @see system_settings_form().
+ * @see search_admin_settings_validate().
+ */
+function search_admin_settings() {
+ // Collect some stats
+ $remaining = 0;
+ $total = 0;
+ foreach (module_list() as $module) {
+ if (module_hook($module, 'search')) {
+ $status = module_invoke($module, 'search', 'status');
+ $remaining += $status['remaining'];
+ $total += $status['total'];
+ }
+ }
+ $count = format_plural($remaining, 'There is 1 item left to index.', 'There are @count items left to index.');
+ $percentage = ((int)min(100, 100 * ($total - $remaining) / max(1, $total))) .'%';
+ $status = '<p><strong>'. t('%percentage of the site has been indexed.', array('%percentage' => $percentage)) .' '. $count .'</strong></p>';
+ $form['status'] = array('#type' => 'fieldset', '#title' => t('Indexing status'));
+ $form['status']['status'] = array('#value' => $status);
+ $form['status']['wipe'] = array('#type' => 'submit', '#value' => t('Re-index site'));
+
+ $items = drupal_map_assoc(array(10, 20, 50, 100, 200, 500));
+
+ // Indexing throttle:
+ $form['indexing_throttle'] = array('#type' => 'fieldset', '#title' => t('Indexing throttle'));
+ $form['indexing_throttle']['search_cron_limit'] = array('#type' => 'select', '#title' => t('Items to index per cron run'), '#default_value' => variable_get('search_cron_limit', 100), '#options' => $items, '#description' => t('The maximum amount of items that will be indexed in one cron run. Set this number lower if your cron is timing out or if PHP is running out of memory.'));
+ // Indexing settings:
+ $form['indexing_settings'] = array('#type' => 'fieldset', '#title' => t('Indexing settings'));
+ $form['indexing_settings']['info'] = array('#value' => '<em>'. t('<p>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.</p><p>The default settings should be appropriate for the majority of sites.</p>') .'</em>');
+ $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).'));
+ $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.'));
+
+ $form['#validate'] = array('search_admin_settings_validate');
+
+ // Per module settings
+ $form = array_merge($form, module_invoke_all('search', 'admin'));
+ return system_settings_form($form);
+}
+
+/**
+ * Validate callback.
+ */
+function search_admin_settings_validate($form, &$form_state) {
+ if ($form_state['values']['op'] == t('Re-index site')) {
+ drupal_goto('admin/settings/search/wipe');
+ }
+ // If these settings change, the index needs to be rebuilt.
+ if ((variable_get('minimum_word_size', 3) != $form_state['values']['minimum_word_size']) ||
+ (variable_get('overlap_cjk', TRUE) != $form_state['values']['overlap_cjk'])) {
+ drupal_set_message(t('The index will be rebuilt.'));
+ search_wipe();
+ }
+} \ No newline at end of file
diff --git a/modules/search/search.module b/modules/search/search.module
index 95c043db0..e684f391f 100644
--- a/modules/search/search.module
+++ b/modules/search/search.module
@@ -124,9 +124,11 @@ function search_theme() {
),
'search_item' => array(
'arguments' => array('item' => NULL, 'type' => NULL),
+ 'file' => 'search.pages.inc',
),
'search_page' => array(
'arguments' => array('results' => NULL, 'type' => NULL),
+ 'file' => 'search.pages.inc',
),
);
}
@@ -164,6 +166,7 @@ function search_menu() {
'page callback' => 'search_view',
'access arguments' => array('search content'),
'type' => MENU_SUGGESTED_ITEM,
+ 'file' => 'search.pages.inc',
);
$items['admin/settings/search'] = array(
'title' => 'Search settings',
@@ -172,6 +175,7 @@ function search_menu() {
'page arguments' => array('search_admin_settings'),
'access arguments' => array('administer search'),
'type' => MENU_NORMAL_ITEM,
+ 'file' => 'search.admin.inc',
);
$items['admin/settings/search/wipe'] = array(
'title' => 'Clear index',
@@ -179,6 +183,7 @@ function search_menu() {
'page arguments' => array('search_wipe_confirm'),
'access arguments' => array('administer search'),
'type' => MENU_CALLBACK,
+ 'file' => 'search.admin.inc',
);
$items['admin/logs/search'] = array(
'title' => 'Top search phrases',
@@ -199,6 +204,7 @@ function search_menu() {
'access arguments' => array($name),
'type' => MENU_LOCAL_TASK,
'parent' => 'search',
+ 'file' => 'search.pages.inc',
);
}
return $items;
@@ -209,80 +215,6 @@ function _search_menu($name) {
}
/**
- * Validate callback.
- */
-function search_admin_settings_validate($form, &$form_state) {
- if ($form_state['values']['op'] == t('Re-index site')) {
- drupal_goto('admin/settings/search/wipe');
- }
- // If these settings change, the index needs to be rebuilt.
- if ((variable_get('minimum_word_size', 3) != $form_state['values']['minimum_word_size']) ||
- (variable_get('overlap_cjk', TRUE) != $form_state['values']['overlap_cjk'])) {
- drupal_set_message(t('The index will be rebuilt.'));
- search_wipe();
- }
-}
-
-/**
- * Menu callback; displays the search module settings page.
- */
-function search_admin_settings() {
- // Collect some stats
- $remaining = 0;
- $total = 0;
- foreach (module_list() as $module) {
- if (module_hook($module, 'search')) {
- $status = module_invoke($module, 'search', 'status');
- $remaining += $status['remaining'];
- $total += $status['total'];
- }
- }
- $count = format_plural($remaining, 'There is 1 item left to index.', 'There are @count items left to index.');
- $percentage = ((int)min(100, 100 * ($total - $remaining) / max(1, $total))) .'%';
- $status = '<p><strong>'. t('%percentage of the site has been indexed.', array('%percentage' => $percentage)) .' '. $count .'</strong></p>';
- $form['status'] = array('#type' => 'fieldset', '#title' => t('Indexing status'));
- $form['status']['status'] = array('#value' => $status);
- $form['status']['wipe'] = array('#type' => 'submit', '#value' => t('Re-index site'));
-
- $items = drupal_map_assoc(array(10, 20, 50, 100, 200, 500));
-
- // Indexing throttle:
- $form['indexing_throttle'] = array('#type' => 'fieldset', '#title' => t('Indexing throttle'));
- $form['indexing_throttle']['search_cron_limit'] = array('#type' => 'select', '#title' => t('Items to index per cron run'), '#default_value' => variable_get('search_cron_limit', 100), '#options' => $items, '#description' => t('The maximum amount of items that will be indexed in one cron run. Set this number lower if your cron is timing out or if PHP is running out of memory.'));
- // Indexing settings:
- $form['indexing_settings'] = array('#type' => 'fieldset', '#title' => t('Indexing settings'));
- $form['indexing_settings']['info'] = array('#value' => '<em>'. t('<p>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.</p><p>The default settings should be appropriate for the majority of sites.</p>') .'</em>');
- $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).'));
- $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.'));
-
- $form['#validate'] = array('search_admin_settings_validate');
-
- // Per module settings
- $form = array_merge($form, module_invoke_all('search', 'admin'));
- return system_settings_form($form);
-}
-
-/**
- * Menu callback: confirm wiping of the index.
- */
-function search_wipe_confirm() {
- return confirm_form(array(), t('Are you sure you want to re-index the site?'),
- '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'));
-}
-
-/**
- * Handler for wipe confirmation
- */
-function search_wipe_confirm_submit(&$form, &$form_state) {
- if ($form['confirm']) {
- search_wipe();
- drupal_set_message(t('The index will be rebuilt.'));
- $form_state['redirect'] = 'admin/settings/search';
- return;
- }
-}
-
-/**
* Wipes a part of or the entire search index.
*
* @param $sid
@@ -924,49 +856,6 @@ function search_get_keys() {
}
/**
- * Menu callback; presents the search form and/or search results.
- */
-function search_view($type = 'node') {
- // Search form submits with POST but redirects to GET. This way we can keep
- // the search query URL clean as a whistle:
- // search/type/keyword+keyword
- if (!isset($_POST['form_id'])) {
- if ($type == '') {
- // Note: search/node can not be a default tab because it would take on the
- // path of its parent (search). It would prevent remembering keywords when
- // switching tabs. This is why we drupal_goto to it from the parent instead.
- drupal_goto('search/node');
- }
-
- $keys = search_get_keys();
- // Only perform search if there is non-whitespace search term:
- $results = '';
- if (trim($keys)) {
- // Log the search keys:
- watchdog('search', '%keys (@type).', array('%keys' => $keys, '@type' => module_invoke($type, 'search', 'name')), WATCHDOG_NOTICE, l(t('results'), 'search/'. $type .'/'. $keys));
-
- // Collect the search results:
- $results = search_data($keys, $type);
-
- if ($results) {
- $results = theme('box', t('Search results'), $results);
- }
- else {
- $results = theme('box', t('Your search yielded no results'), search_help('search#noresults', drupal_help_arg()));
- }
- }
-
- // Construct the search form.
- $output = drupal_get_form('search_form', NULL, $keys, $type);
- $output .= $results;
-
- return $output;
- }
-
- return drupal_get_form('search_form', NULL, empty($keys) ? array() : $keys, $type);
-}
-
-/**
* @defgroup search Search interface
* @{
* The Drupal search interface manages a global search mechanism.
@@ -1044,32 +933,11 @@ function search_form(&$form_state, $action = '', $keys = '', $type = NULL, $prom
}
/**
- * As the search form collates keys from other modules hooked in via
- * hook_form_alter, the validation takes place in _submit.
- * search_form_validate() is used solely to set the 'processed_keys' form
- * value for the basic search form.
- */
-function search_form_validate($form, &$form_state) {
- form_set_value($form['basic']['inline']['processed_keys'], trim($form_state['values']['keys']), $form_state);
-}
-
-/**
- * Process a search form submission.
- */
-function search_form_submit($form, &$form_state) {
- $keys = $form_state['values']['processed_keys'];
- if ($keys == '') {
- form_set_error('keys', t('Please enter some keywords.'));
- // Fall through to the drupal_goto() call.
- }
-
- $type = $form_state['values']['module'] ? $form_state['values']['module'] : 'node';
- $form_state['redirect'] = 'search/'. $type .'/'. $keys;
- return;
-}
-
-/**
- * Output a search form for the search block and the theme's search box.
+ * Form builder; Output a search form for the search block and the theme's search box.
+ *
+ * @ingroup forms
+ * @see search_box_form_submit().
+ * @see theme_search_box_form().
*/
function search_box(&$form_state, $form_id) {
// Use search_keys instead of keys to avoid ID conflicts with the search block.
@@ -1101,6 +969,8 @@ function search_box_form_submit($form, &$form_state) {
/**
* Theme the theme search form.
+ *
+ * @ingroup themeable
*/
function theme_search_theme_form($form) {
return '<div id="search" class="container-inline">'. drupal_render($form) .'</div>';
@@ -1108,6 +978,8 @@ function theme_search_theme_form($form) {
/**
* Theme the block search form.
+ *
+ * @ingroup themeable
*/
function theme_search_block_form($form) {
return '<div class="container-inline">'. drupal_render($form) .'</div>';
@@ -1256,65 +1128,6 @@ function _search_excerpt_replace(&$text) {
$text = preg_quote($text, '/');
}
-/**
- * Format a single result entry of a search query. This function is normally
- * called by theme_search_page() or hook_search_page().
- *
- * @param $item
- * A single search result as returned by hook_search(). The result should be
- * an array with keys "link", "title", "type", "user", "date", and "snippet".
- * Optionally, "extra" can be an array of extra info to show along with the
- * result.
- * @param $type
- * The type of item found, such as "user" or "node".
- *
- * @ingroup themeable
- */
-function theme_search_item($item, $type) {
- $output = ' <dt class="title"><a href="'. check_url($item['link']) .'">'. check_plain($item['title']) .'</a></dt>';
- $info = array();
- if (!empty($item['type'])) {
- $info[] = $item['type'];
- }
- if (!empty($item['user'])) {
- $info[] = $item['user'];
- }
- if (!empty($item['date'])) {
- $info[] = format_date($item['date'], 'small');
- }
- if (isset($item['extra']) && is_array($item['extra'])) {
- $info = array_merge($info, $item['extra']);
- }
- $output .= ' <dd>'. (!empty($item['snippet']) ? '<p>'. $item['snippet'] .'</p>' : '') .'<p class="search-info">'. implode(' - ', $info) .'</p></dd>';
- return $output;
-}
-
-/**
- * Format the result page of a search query.
- *
- * Modules may implement hook_search_page() in order to override this default
- * function to display search results. In that case it is expected they provide
- * their own themeable functions.
- *
- * @param $results
- * All search result as returned by hook_search().
- * @param $type
- * The type of item found, such as "user" or "node".
- *
- * @ingroup themeable
- */
-function theme_search_page($results, $type) {
- $output = '<dl class="search-results">';
-
- foreach ($results as $entry) {
- $output .= theme('search_item', $entry, $type);
- }
- $output .= '</dl>';
- $output .= theme('pager', NULL, 10, 0);
-
- return $output;
-}
-
function search_forms() {
$forms['search_theme_form']= array(
'callback' => 'search_box',
diff --git a/modules/search/search.pages.inc b/modules/search/search.pages.inc
new file mode 100644
index 000000000..e54e7af7e
--- /dev/null
+++ b/modules/search/search.pages.inc
@@ -0,0 +1,136 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * User page callbacks for the search module.
+ */
+
+/**
+ * Menu callback; presents the search form and/or search results.
+ */
+function search_view($type = 'node') {
+ // Search form submits with POST but redirects to GET. This way we can keep
+ // the search query URL clean as a whistle:
+ // search/type/keyword+keyword
+ if (!isset($_POST['form_id'])) {
+ if ($type == '') {
+ // Note: search/node can not be a default tab because it would take on the
+ // path of its parent (search). It would prevent remembering keywords when
+ // switching tabs. This is why we drupal_goto to it from the parent instead.
+ drupal_goto('search/node');
+ }
+
+ $keys = search_get_keys();
+ // Only perform search if there is non-whitespace search term:
+ $results = '';
+ if (trim($keys)) {
+ // Log the search keys:
+ watchdog('search', '%keys (@type).', array('%keys' => $keys, '@type' => module_invoke($type, 'search', 'name')), WATCHDOG_NOTICE, l(t('results'), 'search/'. $type .'/'. $keys));
+
+ // Collect the search results:
+ $results = search_data($keys, $type);
+
+ if ($results) {
+ $results = theme('box', t('Search results'), $results);
+ }
+ else {
+ $results = theme('box', t('Your search yielded no results'), search_help('search#noresults', drupal_help_arg()));
+ }
+ }
+
+ // Construct the search form.
+ $output = drupal_get_form('search_form', NULL, $keys, $type);
+ $output .= $results;
+
+ return $output;
+ }
+
+ return drupal_get_form('search_form', NULL, empty($keys) ? array() : $keys, $type);
+}
+
+/**
+ * Format the result page of a search query.
+ *
+ * Modules may implement hook_search_page() in order to override this default
+ * function to display search results. In that case it is expected they provide
+ * their own themeable functions.
+ *
+ * @param $results
+ * All search result as returned by hook_search().
+ * @param $type
+ * The type of item found, such as "user" or "node".
+ *
+ * @ingroup themeable
+ */
+function theme_search_page($results, $type) {
+ $output = '<dl class="search-results">';
+
+ foreach ($results as $entry) {
+ $output .= theme('search_item', $entry, $type);
+ }
+ $output .= '</dl>';
+ $output .= theme('pager', NULL, 10, 0);
+
+ return $output;
+}
+
+
+/**
+ * Format a single result entry of a search query. This function is normally
+ * called by theme_search_page() or hook_search_page().
+ *
+ * @param $item
+ * A single search result as returned by hook_search(). The result should be
+ * an array with keys "link", "title", "type", "user", "date", and "snippet".
+ * Optionally, "extra" can be an array of extra info to show along with the
+ * result.
+ * @param $type
+ * The type of item found, such as "user" or "node".
+ *
+ * @ingroup themeable
+ */
+function theme_search_item($item, $type) {
+ $output = ' <dt class="title"><a href="'. check_url($item['link']) .'">'. check_plain($item['title']) .'</a></dt>';
+ $info = array();
+ if (!empty($item['type'])) {
+ $info[] = $item['type'];
+ }
+ if (!empty($item['user'])) {
+ $info[] = $item['user'];
+ }
+ if (!empty($item['date'])) {
+ $info[] = format_date($item['date'], 'small');
+ }
+ if (isset($item['extra']) && is_array($item['extra'])) {
+ $info = array_merge($info, $item['extra']);
+ }
+ $output .= ' <dd>'. (!empty($item['snippet']) ? '<p>'. $item['snippet'] .'</p>' : '') .'<p class="search-info">'. implode(' - ', $info) .'</p></dd>';
+ return $output;
+}
+
+/**
+ * As the search form collates keys from other modules hooked in via
+ * hook_form_alter, the validation takes place in _submit.
+ * search_form_validate() is used solely to set the 'processed_keys' form
+ * value for the basic search form.
+ */
+function search_form_validate($form, &$form_state) {
+ form_set_value($form['basic']['inline']['processed_keys'], trim($form_state['values']['keys']), $form_state);
+}
+
+/**
+ * Process a search form submission.
+ */
+function search_form_submit($form, &$form_state) {
+ $keys = $form_state['values']['processed_keys'];
+ if ($keys == '') {
+ form_set_error('keys', t('Please enter some keywords.'));
+ // Fall through to the drupal_goto() call.
+ }
+
+ $type = $form_state['values']['module'] ? $form_state['values']['module'] : 'node';
+ $form_state['redirect'] = 'search/'. $type .'/'. $keys;
+ return;
+}
+