diff options
author | Dries Buytaert <dries@buytaert.net> | 2004-12-31 09:30:12 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2004-12-31 09:30:12 +0000 |
commit | 1dbe0dc2ee80fc8d67e42785b12203513dc11820 (patch) | |
tree | ff4db2592bb43981e685a92dbf075a7095d63793 /modules/search.module | |
parent | 828be2ad6198538def4eb3da0ce03a34961a38e9 (diff) | |
download | brdo-1dbe0dc2ee80fc8d67e42785b12203513dc11820.tar.gz brdo-1dbe0dc2ee80fc8d67e42785b12203513dc11820.tar.bz2 |
- Patch #14917 by UnConeD/Steven:
1) The different types of search, which used to be radio button options in the search form, are now subtabs of "search" (default "search/node"). This seems better from a UI point of view, but also has another advantage: modules which implement a custom search form (flexinode, project) can add it as a subtab of search. This means that all search forms will be located in the same place, and also without needing an extra api call to search.module.
2) The current code was a bit hackish, as the indexing of comments along with nodes was hardcoded in node.module. Instead, I created a nodeapi operation "update index" which allows modules to add more data for a node that is being indexed. Comments are now indexed using this mechanism and from comment.module, which is a lot cleaner.
3) The search results format was also hardcoded to include "N comments". I replaced this with a nodeapi operation "search result" and moved the comment code to comment.module where it belongs. This op is quite useful, as for example I also modified upload.module to add "N attachments" to a search result if any are present.
Diffstat (limited to 'modules/search.module')
-rw-r--r-- | modules/search.module | 46 |
1 files changed, 21 insertions, 25 deletions
diff --git a/modules/search.module b/modules/search.module index fe70f94ba..9c812402b 100644 --- a/modules/search.module +++ b/modules/search.module @@ -74,12 +74,20 @@ function search_menu($may_cache) { $items = array(); if ($may_cache) { - $items[] = array('path' => 'search', 'title' => t('search'), + $items[] = array('path' => 'search', 'title' => t('search for'), 'callback' => 'search_view', 'access' => user_access('search content'), 'type' => MENU_SUGGESTED_ITEM); - $items[] = array('path' => 'search/search', 'title' => t('search'), - 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10); + + foreach (module_list() as $name) { + if (module_hook($name, 'search')) { + $items[] = array('path' => 'search/'. $name, 'title' => module_invoke($name, 'search', 'name'), + 'callback' => 'search_view', + 'access' => user_access('search content'), + 'type' => $name == 'node' ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK); + } + } + $items[] = array('path' => 'admin/settings/search', 'title' => t('search'), 'callback' => 'search_admin', 'type' => MENU_NORMAL_ITEM, @@ -465,7 +473,7 @@ function do_search($keys, $type, $join = '', $where = '1') { */ function search_view() { $keys = isset($_GET['keys']) ? $_GET['keys'] : $_POST['edit']['keys']; - $type = isset($_GET['type']) ? $_GET['type'] : ($_POST['edit']['type'] ? $_POST['edit']['type'] : 'node'); + $type = arg(1) ? arg(1) : (isset($_GET['type']) ? $_GET['type'] : ($_POST['edit']['type'] ? $_POST['edit']['type'] : 'node')); if (user_access('search content')) { // Only perform search if there is non-whitespace search term: @@ -538,6 +546,9 @@ function search_form($action = '', $keys = '', $type = null, $options = FALSE) { if (!$action) { $action = url('search'); } + if (!$type) { + $type = 'node'; + } $output = ' <div class="search-form">'; $box = '<div class="container-inline">'; @@ -545,24 +556,7 @@ function search_form($action = '', $keys = '', $type = null, $options = FALSE) { $box .= form_submit(t('Search'));; $box .= '</div>'; $output .= form_item(t('Enter your keywords'), $box); - - if ($options) { - $output .= '<div class="container-inline">'. t('Search for') .': '; - - if (!isset($edit['type'])) { - $edit['type'] = $type; - } - - foreach (module_list() as $name) { - if (module_hook($name, 'search')) { - $output .= form_radio(module_invoke($name, 'search', 'name'), 'type', $name, $edit['type'] == $name); - } - } - $output .= '</div>'; - } - else if ($type) { - $output .= form_hidden('type', $type); - } + $output .= form_hidden('type', $type); $output .= '</div>'; return form($output, 'post', $action); @@ -712,7 +706,9 @@ function _search_excerpt_replace($text) { * * @param $item * A single search result as returned by hook_search(). The result should be - * an array with keys "count", "link", "title", "user", "date", and "keywords". + * 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 "comment". */ @@ -732,8 +728,8 @@ function theme_search_item($item, $type) { if ($item['date']) { $info[] = format_date($item['date'], 'small'); } - if (isset($item['extra'])) { - $info[] = $item['extra']; + if (is_array($item['extra'])) { + $info = array_merge($info, $item['extra']); } $output .= ' <dd>'. ($item['snippet'] ? '<p>'. $item['snippet'] . '</p>' : '') . '<p class="search-info">' . implode(' - ', $info) .'</p></dd>'; } |