1.8 * @date 2008/03/31 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License * * The query page - accepts a user-entered query string and returns results. * * Queries are boolean-aware, e.g.: * * '+' term required * '-' term must not be present * '' (no modifier) term's presence increases rank, but isn't required * 'field:' search this field * * Examples: * * 'earthquake +author:michael' * Searches for documents written by 'michael' that contain 'earthquake' * * 'earthquake +doctype:wiki' * Search all wiki pages for 'earthquake' * * '+author:helen +author:foster' * All articles written by Helen Foster * */ /** * includes and requires */ require_once('../config.php'); require_once("$CFG->dirroot/search/lib.php"); // include "debugging.php"; if ($CFG->forcelogin) { require_login(); } if (empty($CFG->enableglobalsearch)) { error(get_string('globalsearchdisabled', 'search')); } $adv = new Object(); /// check for php5, but don't die yet (see line 52) require_once($CFG->dirroot.'/search/querylib.php'); $page_number = optional_param('page', -1, PARAM_INT); $pages = ($page_number == -1) ? false : true; $advanced = (optional_param('a', '0', PARAM_INT) == '1') ? true : false; $query_string = stripslashes(optional_param('query_string', '', PARAM_CLEAN)); /// discard harmfull searches if (!isset($CFG->block_search_utf8dir)){ set_config('block_search_utf8dir', 1); } /// discard harmfull searches if (preg_match("/^[\*\?]+$/", $query_string)){ $query_string = ''; $error = get_string('fullwildcardquery','search'); } if ($pages && isset($_SESSION['search_advanced_query'])) { // if both are set, then we are busy browsing through the result pages of an advanced query $adv = unserialize($_SESSION['search_advanced_query']); } elseif ($advanced) { // otherwise we are dealing with a new advanced query unset($_SESSION['search_advanced_query']); session_unregister('search_advanced_query'); // chars to strip from strings (whitespace) $chars = " \t\n\r\0\x0B,-+"; // retrieve advanced query variables $adv->mustappear = trim(optional_param('mustappear', '', PARAM_CLEAN), $chars); $adv->notappear = trim(optional_param('notappear', '', PARAM_CLEAN), $chars); $adv->canappear = trim(optional_param('canappear', '', PARAM_CLEAN), $chars); $adv->module = optional_param('module', '', PARAM_CLEAN); $adv->title = trim(optional_param('title', '', PARAM_CLEAN), $chars); $adv->author = trim(optional_param('author', '', PARAM_CLEAN), $chars); } if ($advanced) { //parse the advanced variables into a query string //TODO: move out to external query class (QueryParse?) $query_string = ''; // get all available module types adding third party modules $module_types = array_merge(array('all'), array_values(search_get_document_types())); $module_types = array_merge($module_types, array_values(search_get_document_types('X_SEARCH_TYPE'))); $adv->module = in_array($adv->module, $module_types) ? $adv->module : 'all'; // convert '1 2' into '+1 +2' for required words field if (strlen(trim($adv->mustappear)) > 0) { $query_string = ' +'.implode(' +', preg_split("/[\s,;]+/", $adv->mustappear)); } // convert '1 2' into '-1 -2' for not wanted words field if (strlen(trim($adv->notappear)) > 0) { $query_string .= ' -'.implode(' -', preg_split("/[\s,;]+/", $adv->notappear)); } // this field is left untouched, apart from whitespace being stripped if (strlen(trim($adv->canappear)) > 0) { $query_string .= ' '.implode(' ', preg_split("/[\s,;]+/", $adv->canappear)); } // add module restriction $doctypestr = 'doctype'; $titlestr = 'title'; $authorstr = 'author'; if ($adv->module != 'all') { $query_string .= " +{$doctypestr}:".$adv->module; } // create title search string if (strlen(trim($adv->title)) > 0) { $query_string .= " +{$titlestr}:".implode(" +{$titlestr}:", preg_split("/[\s,;]+/", $adv->title)); } // create author search string if (strlen(trim($adv->author)) > 0) { $query_string .= " +{$authorstr}:".implode(" +{$authorstr}:", preg_split("/[\s,;]+/", $adv->author)); } // save our options if the query is valid if (!empty($query_string)) { $_SESSION['search_advanced_query'] = serialize($adv); } } // normalise page number if ($page_number < 1) { $page_number = 1; } //run the query against the index ensuring internal coding works in UTF-8 Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive()); $sq = new SearchQuery($query_string, $page_number, 10, false); if (!$site = get_site()) { redirect("index.php"); } $strsearch = get_string('search', 'search'); $strquery = get_string('enteryoursearchquery', 'search'); // if ($CFG->version < 2007032200){ NOT RELIABLE if (!function_exists('build_navigation')){ print_header("$site->shortname: $strsearch: $strquery", "$site->fullname", "$strsearch -> $strquery"); } else { $navlinks[] = array('name' => $strsearch, 'link' => "index.php", 'type' => 'misc'); $navlinks[] = array('name' => $strquery, 'link' => null, 'type' => 'misc'); $navigation = build_navigation($navlinks); $site = get_site(); print_header("$strsearch", "$site->fullname" , $navigation, "", "", true, " ", navmenu($site)); } if (!empty($error)){ notice ($error); } print_box_start(); print_heading($strquery); print_box_start(); $vars = get_object_vars($adv); if (isset($vars)) { foreach ($vars as $key => $value) { // htmlentities breaks non-ascii chars $adv->key = stripslashes($value); //$adv->$key = stripslashes(htmlentities($value)); } } ?>
' . get_string('noindexmessage', 'search') . '' . get_string('createanindex', 'search')."
\n"; } ?>