Search guidelines
The search page allows you to search the web site's content. You can specify multiple words, and they will all be searched for. You can also use wildcards, so 'walk*' will match 'walk', 'walking', 'walker', 'walkable' and so on. Furthermore, searches are not case sensitive so searching for 'walk', 'Walk' or 'WALK' will yield exactly the same results.
Words excluded from the searchWords that frequently occur, typically called 'noise words', are ignored. Example words are 'a', 'at', 'and', 'are', 'as', 'how', 'where', etc. Words shorter than %number letters are also ignored.
", array('%number' => variable_get('minimum_word_size', 2))); case 'admin/modules#description': return t('Enables site-wide keyword searching.'); case 'admin/settings/search': return t('The search engine works by keeping an index of "interesting" words. To make sure we only get "interesting" words you need to set the following.'); } } /** * Implementation of hook_perm(). */ function search_perm() { return array('search content', 'administer search'); } /** * Implementation of hook_link(). */ function search_link($type) { $links = array(); if ($type == 'page' && user_access('search content')) { $links[] = l(t('search'), 'search', array('title' => t('Search for older content.'))); } return $links; } /** * Implementation of hook_menu(). */ function search_menu() { $items = array(); $items[] = array('path' => 'search', 'title' => t('search'), 'callback' => 'search_view', 'access' => user_access('search content'), 'type' => MENU_SUGGESTED_ITEM); $items[] = array('path' => 'search/help', 'title' => t('search help'), 'callback' => 'search_help_page', 'access' => user_access('search content'), 'type' => MENU_SUGGESTED_ITEM); $items[] = array('path' => 'search/search', 'title' => t('search'), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10); $items[] = array('path' => 'search/configure', 'title' => t('configure'), 'callback' => 'search_configure', 'access' => user_access('administer site configuration'), 'type' => MENU_LOCAL_TASK); return $items; } /** * Menu callback; displays the search module settings page. */ function search_configure() { if ($_POST) { system_settings_save(); } // Indexing settings: $group = form_textfield(t('Minimum word length to index'), 'minimum_word_size', variable_get('minimum_word_size', 2), 10, 10, t('The number of characters a word has to be to be indexed. Words shorter than this will not be searchable.')); $group .= form_textfield(t('Minimum word length to search for'), 'remove_short', variable_get('remove_short', 0), 10, 10, t('The number of characters a word has to be to be searched for.')); $group .= form_textarea(t('Noise words'), 'noisewords', variable_get('noisewords', ''), 70, 10, t('These words will not be indexed. Enter a comma separated list; linebreaks and whitespace do not matter. Example: and, or, not, a, to, I, it, ...')); $output = form_group(t('Indexing settings'), $group); // Visual settings: $group = form_radios(t('Help text position'), 'help_pos', variable_get('help_pos', 1), array('1' => t('Above search output'), '2' => t('Below search output'), '3' => t('Link from above search output'), '4' => t('Link from below search output')), t('Where to show the help text for users on the search page.')); $output .= form_group(t('Viewing options'), $group); print theme('page', system_settings_form($output)); } /** * Implementation of hook_cron(). * * Fires hook_update_index() in all modules and uses the results to make * the search index current. */ function search_cron() { foreach (module_list() as $module) { $module_array = module_invoke($module, 'update_index'); if ($module_array) { update_index($module_array); } $module_array = null; } return; } /** * Perform a search on a word or words. * * This function is called by each node that supports the indexed search. * * @param $search_array * An array as returned from hook_search(). The format of this array is * array('keys' => ..., 'type' => ..., 'select' => ...). See the hook_search() * documentation for an explanation of the array values. * * @return * An array of search results, of which each element is an array with the * keys "count", "title", "link", "user" (name), "date", and "keywords". */ function do_search($search_array) { $keys = strtolower($search_array['keys']); $type = $search_array['type']; $select = $search_array['select']; // Replace wildcards with MySQL wildcards. $keys = str_replace('*', '%', $keys); // Split the words entered into an array. $words = explode(' ', $keys); foreach ($words as $word) { // If the word is too short, and we've got it set to skip them, loop. if (strlen($word) < variable_get('remove_short', 0)) { continue; } // Put the next search word into the query and do the query. $query = str_replace("'%'", "'". check_query($word) ."'", $select); $result = db_query($query); if (db_num_rows($result) != 0) { // At least one matching record was found. $found = 1; // Create an in memory array of the results. while ($row = db_fetch_array($result)) { $lno = $row['lno']; $nid = $row['nid']; $title = $row['title']; $created = $row['created']; $uid = $row['uid']; $name = $row['name']; $count = $row['count']; // Build reduction variable. $reduction[$lno][$word] = true; // Check whether the just-fetched row is already in the table. if ($results[$lno]['lno'] != $lno) { $results[$lno]['count'] = $count; $results[$lno]['lno'] = $lno; $results[$lno]['nid'] = $nid; $results[$lno]['title'] = $title; $results[$lno]['created'] = $created; $results[$lno]['uid'] = $uid; $results[$lno]['name'] = $name; } else { // Different word, but existing "lno". Increase the count of // matches against this "lno" by the number of times this // word appears in the text. $results[$lno]['count'] = $results[$lno]['count'] + $count; } } } } if ($found) { foreach ($results as $lno => $values) { $pass = true; foreach ($words as $word) { if (!$reduction[$lno][$word]) { $pass = false; } } if ($pass) { $fullresults[$lno] = $values; } } $results = $fullresults; if (!is_array($results)) { $found = 0; } } if ($found) { // Black magic here to sort the results. array_multisort($results, SORT_DESC); // Now, output the results. foreach ($results as $key => $value) { $lno = $value['lno']; $nid = $value['nid']; $title = $value['title']; $created = $value['created']; $uid = $value['uid']; $name = $value['name']; $count = $value['count']; switch ($type) { case 'node': $find[$i++] = array('count' => $count, 'title' => $title, 'link' => url("node/$lno"), 'user' => $name, 'date' => $created, 'keywords' => implode('|', $words)); break; case 'comment': $find[$i++] = array('count' => $count, 'title' => $title, 'link' => (strstr(request_uri(), 'admin') ? url("admin/comment/edit/$lno") : url("node/$nid", NULL, "comment-$lno")), 'user' => $name, 'date' => $created, 'keywords' => implode('|', $words)); break; break; } } } return $find; } /** * Update the search_index table. * * @param $search_array * An array as returned from hook_update_index(). */ function update_index($search_array) { $last_update = variable_get($search_array['last_update'], 1); $node_type = $search_array['node_type']; $select = $search_array['select']; $minimum_word_size = variable_get('minimum_word_size', 2); //watchdog('user', "$last_update