mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 00:42:54 +02:00
mismatched code version in file.
This commit is contained in:
parent
678e8898aa
commit
f1776f8f9b
114
search/query.php
114
search/query.php
@ -2,7 +2,7 @@
|
||||
/**
|
||||
* Global Search Engine for Moodle
|
||||
* Michael Champanis (mchampan) [cynnical@gmail.com]
|
||||
* review 1.8+ : Valery Fremaux [valery.fremaux@club-internet.fr]
|
||||
* review 1.8+ : Valery Fremaux [valery.fremaux@club-internet.fr]
|
||||
* 2007/08/02
|
||||
*
|
||||
* The query page - accepts a user-entered query string and returns results.
|
||||
@ -52,15 +52,15 @@ if ($check = search_check_php5()) {
|
||||
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']);
|
||||
}
|
||||
}
|
||||
else if ($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);
|
||||
@ -68,84 +68,82 @@ if ($check = search_check_php5()) {
|
||||
$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
|
||||
$module_types = array_merge(array('all'), array_values(search_get_document_types()));
|
||||
$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 = get_string('doctype', 'search');
|
||||
$titlestr = get_string('title', 'search');
|
||||
$authorstr = get_string('author', 'search');
|
||||
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
|
||||
$sq = new SearchQuery($query_string, $page_number, 10, false);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$site = get_site()) {
|
||||
redirect("index.php");
|
||||
}
|
||||
}
|
||||
|
||||
$strsearch = get_string('search', 'search');
|
||||
$strsearch = get_string('search', 'search');
|
||||
$strquery = get_string('enteryoursearchquery', 'search');
|
||||
$navlinks = array();
|
||||
$navlinks[] = array('name' => $strsearch, 'link' => "index.php", 'type' => 'misc');
|
||||
$navlinks[] = array('name' => $strquery, 'link' => null, 'type' => 'misc');
|
||||
$navigation = build_navigation($navlinks);
|
||||
print_header("$site->shortname: $strsearch: $strquery", "$site->fullname", $navigation);
|
||||
|
||||
print_header("$site->shortname: $strsearch: $strquery", "$site->fullname",
|
||||
"<a href=\"index.php\">$strsearch</a> -> $strquery");
|
||||
|
||||
//keep things pretty, even if php5 isn't available
|
||||
if (!$check) {
|
||||
print_heading(search_check_php5(true));
|
||||
print_footer();
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
print_box_start();
|
||||
print_heading($strquery);
|
||||
@ -157,20 +155,20 @@ $vars = get_object_vars($adv);
|
||||
if (isset($vars)) {
|
||||
foreach ($vars as $key => $value) {
|
||||
$adv->$key = stripslashes(htmlentities($value));
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<form id="query" method="get" action="query.php">
|
||||
<?php
|
||||
if (!$advanced) {
|
||||
<?php
|
||||
if (!$advanced) {
|
||||
?>
|
||||
<input type="text" name="query_string" length="50" value="<?php print stripslashes($query_string) ?>" />
|
||||
<input type="submit" value="<?php print_string('search', 'search') ?>" />
|
||||
<a href="query.php?a=1"><?php print_string('advancedsearch', 'search') ?></a> |
|
||||
<a href="stats.php"><?php print_string('statistics', 'search') ?></a>
|
||||
<?php
|
||||
}
|
||||
<?php
|
||||
}
|
||||
else {
|
||||
print_box_start();
|
||||
?>
|
||||
@ -197,7 +195,7 @@ else {
|
||||
<td><?php print_string('whichmodulestosearch?', 'search') ?>:</td>
|
||||
<td>
|
||||
<select name="module">
|
||||
<?php
|
||||
<?php
|
||||
foreach($module_types as $mod) {
|
||||
if ($mod == $adv->module) {
|
||||
if ($mod != 'all'){
|
||||
@ -206,7 +204,7 @@ else {
|
||||
else{
|
||||
print "<option value='$mod' selected=\"selected\">".get_string('all', 'search')."</option>\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ($mod != 'all'){
|
||||
print "<option value='$mod'>".get_string('modulenameplural', $mod)."</option>\n";
|
||||
@ -214,8 +212,8 @@ else {
|
||||
else{
|
||||
print "<option value='$mod'>".get_string('all', 'search')."</option>\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
@ -248,7 +246,7 @@ else {
|
||||
</table>
|
||||
<?php
|
||||
print_box_end();
|
||||
}
|
||||
}
|
||||
?>
|
||||
</form>
|
||||
<br/>
|
||||
@ -260,10 +258,10 @@ print_string('searching', 'search') . ': ';
|
||||
if ($sq->is_valid_index()) {
|
||||
//use cached variable to show up-to-date index size (takes deletions into account)
|
||||
print $CFG->search_index_size;
|
||||
}
|
||||
}
|
||||
else {
|
||||
print "0";
|
||||
}
|
||||
}
|
||||
|
||||
print ' ';
|
||||
print_string('documents', 'search');
|
||||
@ -271,7 +269,7 @@ print '.';
|
||||
|
||||
if (!$sq->is_valid_index() and isadmin()) {
|
||||
print '<p>' . get_string('noindexmessage', 'search') . '<a href="indexersplash.php">' . get_string('createanindex', 'search')."</a></p>\n";
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
</div>
|
||||
@ -281,28 +279,28 @@ print_box_end();
|
||||
// prints all the results in a box
|
||||
if ($sq->is_valid()) {
|
||||
print_box_start();
|
||||
|
||||
|
||||
search_stopwatch();
|
||||
$hit_count = $sq->count();
|
||||
|
||||
|
||||
print "<br />";
|
||||
|
||||
|
||||
print $hit_count.' '.get_string('resultsreturnedfor', 'search') . " '".stripslashes($query_string)."'.";
|
||||
print "<br />";
|
||||
|
||||
|
||||
if ($hit_count > 0) {
|
||||
$page_links = $sq->page_numbers();
|
||||
$hits = $sq->results();
|
||||
|
||||
|
||||
if ($advanced) {
|
||||
// if in advanced mode, search options are saved in the session, so
|
||||
// we can remove the query string var from the page links, and replace
|
||||
// it with a=1 (Advanced = on) instead
|
||||
$page_links = preg_replace("/query_string=[^&]+/", 'a=1', $page_links);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
print "<ol>";
|
||||
|
||||
|
||||
$typestr = get_string('type', 'search');
|
||||
$scorestr = get_string('score', 'search');
|
||||
$authorstr = get_string('author', 'search');
|
||||
@ -317,17 +315,17 @@ if ($sq->is_valid()) {
|
||||
."{$typestr}: ".$listing->doctype.", {$scorestr}: ".round($listing->score, 3).", {$authorstr}: ".$listing->author."\n"
|
||||
."</li>\n";
|
||||
}
|
||||
|
||||
|
||||
print "</ol>";
|
||||
print $page_links;
|
||||
}
|
||||
}
|
||||
|
||||
print_box_end();
|
||||
?>
|
||||
<div align="center">
|
||||
<?php
|
||||
<?php
|
||||
print_string('ittook', 'search');
|
||||
search_stopwatch();
|
||||
search_stopwatch();
|
||||
print_string('tofetchtheseresults', 'search');
|
||||
?>.
|
||||
</div>
|
||||
@ -336,4 +334,4 @@ if ($sq->is_valid()) {
|
||||
}
|
||||
print_box_end();
|
||||
print_footer();
|
||||
?>
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user