From: diml Date: Mon, 23 Mar 2009 21:07:02 +0000 (+0000) Subject: Addresses the tracker MDL - 18638 and MDL 18474 X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=63c13a82f1a5b70d44dc2dae90328e57c32252fc;p=moodle.git Addresses the tracker MDL - 18638 and MDL 18474 --- diff --git a/search/cron_php5.php b/search/cron_php5.php index 4a0e9f9f2c..a9cd57fcb5 100644 --- a/search/cron_php5.php +++ b/search/cron_php5.php @@ -3,21 +3,28 @@ * Moodle global search engine * This is a special externalized code for cron handling in PHP5. * Should never be called by a php 4.3.0 implementation. +* @package search +* @category core +* @subpackage search_engine +* @author Michael Champanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8 +* @date 2008/03/31 +* @version prepared for 2.0 +* @license http://www.gnu.org/copyleft/gpl.html GNU Public License */ try{ // overrides php limits $maxtimelimit = ini_get('max_execution_time'); - ini_set('max_execution_time', 300); + ini_set('max_execution_time', 600); $maxmemoryamount = ini_get('memory_limit'); - ini_set('memory_limit', '48M'); + ini_set('memory_limit', '96M'); mtrace("\n--DELETE----"); - require_once("$CFG->dirroot/search/delete.php"); + require_once($CFG->dirroot.'/search/delete.php'); mtrace("--UPDATE----"); - require_once("$CFG->dirroot/search/update.php"); + require_once($CFG->dirroot.'/search/update.php'); mtrace("--ADD-------"); - require_once("$CFG->dirroot/search/add.php"); + require_once($CFG->dirroot.'/search/add.php'); mtrace("------------"); //mtrace("cron finished."); mtrace('done'); diff --git a/search/indexer.php b/search/indexer.php index c4b4e29415..2cbf011ae9 100644 --- a/search/indexer.php +++ b/search/indexer.php @@ -7,6 +7,7 @@ * @subpackage search_engine * @author Michael Champanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8 * @date 2008/03/31 +* @version prepared for Moodle 2.0 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License * * The indexer logic - @@ -34,20 +35,18 @@ * includes and requires */ require_once('../config.php'); -require_once("$CFG->dirroot/search/lib.php"); -//require_once("debugging.php"); +require_once($CFG->dirroot.'/search/lib.php'); -$separator = (array_key_exists('WINDIR', $_SERVER)) ? ';' : ':' ; - ini_set('include_path', $CFG->dirroot.'\search'.$separator.ini_get('include_path')); + ini_set('include_path', $CFG->dirroot.PATH_SEPARATOR.'search'.PATH_SEPARATOR.ini_get('include_path')); /// only administrators can index the moodle installation, because access to all pages is required require_login(); - + if (empty($CFG->enableglobalsearch)) { print_error('globalsearchdisabled', 'search'); } - + if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) { print_error('beadmin', 'search', get_login_url()); } @@ -55,104 +54,94 @@ $separator = (array_key_exists('WINDIR', $_SERVER)) ? ';' : ':' ; /// confirmation flag to prevent accidental reindexing (indexersplash.php is the correct entry point) $sure = strtolower(optional_param('areyousure', '', PARAM_ALPHA)); - + if ($sure != 'yes') { mtrace("
Sorry, you need to confirm indexing via indexersplash.php"
               .". (Back to query page).
"); - + exit(0); } - + /// check for php5 (lib.php) //php5 found, continue including php5-only files //require_once("$CFG->dirroot/search/Zend/Search/Lucene.php"); - require_once("$CFG->dirroot/search/indexlib.php"); - + require_once($CFG->dirroot.'/search/indexlib.php'); + mtrace(''); mtrace('
Server Time: '.date('r',time())."\n");
-
+    
     if (isset($CFG->search_indexer_busy) && $CFG->search_indexer_busy == '1') {
         //means indexing was not finished previously
         mtrace("Warning: Indexing was not successfully completed last time, restarting.\n");
     }
-
+    
 /// turn on busy flag
 
     set_config('search_indexer_busy', '1');
-
+    
     //paths
     $index_path = SEARCH_INDEX_PATH;
     $index_db_file = "{$CFG->dirroot}/search/db/$CFG->dbtype.sql";
     $dbcontrol = new IndexDBControl();
-
+    
 /// setup directory in data root
 
     if (!file_exists($index_path)) {
         mtrace("Data directory ($index_path) does not exist, attempting to create.");
         if (!mkdir($index_path)) {
             search_pexit("Error creating data directory at: $index_path. Please correct.");
-        }
+        } 
         else {
             mtrace("Directory successfully created.");
-        }
-    }
+        } 
+    } 
     else {
-        mtrace("Using $index_path as data directory.");
-    }
-
-    Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8());
+        mtrace("Using {$index_path} as data directory.");
+    } 
+    
+    Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive());
     $index = new Zend_Search_Lucene($index_path, true);
-
+    
 /// New regeneration
 
     mtrace('Deleting old index entries.');
-    delete_records(SEARCH_DATABASE_TABLE);
-
+    $DB->delete_records(SEARCH_DATABASE_TABLE);
+    
 /// begin timer
 
     search_stopwatch();
     mtrace("Starting activity modules\n");
-
+    
     //the presence of the required search functions -
     // * mod_iterator
     // * mod_get_content_for_index
     //are the sole basis for including a module in the index at the moment.
 
     $searchables = search_collect_searchables();
-
+    
 /// start indexation
 
     if ($searchables){
         foreach ($searchables as $mod) {
-
+        
+            mtrace("starting indexing {$mod->name}\n");
+        
             $key = 'search_in_'.$mod->name;
             if (isset($CFG->$key) && !$CFG->$key) {
                 mtrace("module $key has been administratively disabled. Skipping...\n");
                 continue;
             }
-
+        
             if ($mod->location == 'internal'){
                 $class_file = $CFG->dirroot.'/search/documents/'.$mod->name.'_document.php';
             } else {
                 $class_file = $CFG->dirroot.'/'.$mod->location.'/'.$mod->name.'/search_document.php';
             }
-
-            /*
-            if (!file_exists($class_file)){
-                if (defined("PATH_FOR_SEARCH_TYPE_{$mod->name}")){
-                    eval("\$pluginpath = PATH_FOR_SEARCH_TYPE_{$mod->name}");
-                    $class_file = "{$CFG->dirroot}/{$pluginpath}/searchlib.php";
-                } else {
-                   mtrace ("No search document found for plugin {$mod->name}. Ignoring.");
-                   continue;
-                }
-            }
-            */
-
+            
             if (file_exists($class_file)) {
                 include_once($class_file);
-
+    
                 //build function names
                 $iter_function = $mod->name.'_iterator';
                 $index_function = $mod->name.'_get_content_for_index';
@@ -163,35 +152,35 @@ $separator = (array_key_exists('WINDIR', $_SERVER)) ? ';' : ':' ;
                     if ($sources){
                         foreach ($sources as $i) {
                             $documents = $index_function($i);
-
+                  
                             //begin transaction
                             if ($documents){
                                 foreach($documents as $document) {
                                     $counter++;
-
+                                    
                                     //object to insert into db
                                     $dbid = $dbcontrol->addDocument($document);
-
+                                    
                                     //synchronise db with index
                                     $document->addField(Zend_Search_Lucene_Field::Keyword('dbid', $dbid));
-
+                                    
                                     //add document to index
                                     $index->addDocument($document);
-
+                                    
                                     //commit every x new documents, and print a status message
                                     if (($counter % 2000) == 0) {
                                         $index->commit();
                                         mtrace(".. $counter");
-                                    }
+                                    } 
                                 }
                             }
                             //end transaction
                         }
                     }
-
+            
                     //commit left over documents, and finish up
                     $index->commit();
-
+          
                     mtrace("-- $counter documents indexed");
                     mtrace("done.\n");
                 }
@@ -200,25 +189,25 @@ $separator = (array_key_exists('WINDIR', $_SERVER)) ? ';' : ':' ;
             }
         }
     }
-
+      
 /// finished modules
 
     mtrace('Finished activity modules');
     search_stopwatch();
-
+        
     mtrace(".
Back to query page."); mtrace('
'); - + /// finished, turn busy flag off set_config('search_indexer_busy', '0'); - + /// mark the time we last updated set_config('search_indexer_run_date', time()); - + /// and the index size set_config('search_index_size', (int)$index->count()); -?> +?> \ No newline at end of file diff --git a/search/indexersplash.php b/search/indexersplash.php index b30b410301..37ac4e6321 100644 --- a/search/indexersplash.php +++ b/search/indexersplash.php @@ -1,60 +1,57 @@ 1.8 -* @date 2008/03/31 -* @license http://www.gnu.org/copyleft/gpl.html GNU Public License -* -* This file serves as a splash-screen (entry page) to the indexer script - -* it is in place to prevent accidental reindexing which can lead to a loss -* of time, amongst other things. -*/ - -/** -* includes and requires -*/ -require_once('../config.php'); -require_once("{$CFG->dirroot}/search/lib.php"); - -/// makes inclusions of the Zend Engine more reliable -$separator = (array_key_exists('WINDIR', $_SERVER)) ? ';' : ':' ; -ini_set('include_path', $CFG->dirroot.'\search'.$separator.ini_get('include_path')); - -/// check global search is enabled - + /** + * Global Search Engine for Moodle + * + * @package search + * @category core + * @subpackage search_engine + * @author Michael Champanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8 + * @date 2008/03/31 + * @version prepared for 2.0 + * @license http://www.gnu.org/copyleft/gpl.html GNU Public License + * + * This file serves as a splash-screen (entry page) to the indexer script - + * it is in place to prevent accidental reindexing which can lead to a loss + * of time, amongst other things. + */ + + /** + * includes and requires + */ + require_once('../config.php'); + + /// makes inclusions of the Zend Engine more reliable + ini_set('include_path', $CFG->dirroot.PATH_SEPARATOR.'search'.PATH_SEPARATOR.ini_get('include_path')); + + require_once($CFG->dirroot.'/search/lib.php'); + + /// check global search is enabled + require_login(); - + if (empty($CFG->enableglobalsearch)) { print_error('globalsearchdisabled', 'search'); } - + if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) { print_error('beadmin', 'search', get_login_url()); } require_once("$CFG->dirroot/search/indexlib.php"); $indexinfo = new IndexInfo(); - + if ($indexinfo->valid()) { $strsearch = get_string('search', 'search'); $strquery = get_string('stats'); - + + // print page header $navlinks[] = array('name' => $strsearch, 'link' => "index.php", 'type' => 'misc'); $navlinks[] = array('name' => $strquery, 'link' => "stats.php", 'type' => 'misc'); $navlinks[] = array('name' => get_string('runindexer','search'), 'link' => null, 'type' => 'misc'); - // if ($CFG->version <= 2007021541){ // 1.8 branch stable timestamp NOT RELIABLE - if (!function_exists('build_navigation')){ // 1.8 branch stable timestamp - $navigation = ''; - } else { - $navigation = build_navigation($navlinks); - } + $navigation = build_navigation($navlinks); $site = get_site(); print_header("$strsearch", "$site->fullname" , $navigation, "", "", true, " ", navmenu($site)); - + mtrace("
The data directory ($indexinfo->path) contains $indexinfo->filecount files, and\n"
               ."there are ".$indexinfo->dbcount." records in the block_search_documents table.\n"
               ."\n"
@@ -70,8 +67,7 @@ ini_set('include_path', $CFG->dirroot.'\search'.$separator.ini_get('include_path
               ."Continue indexing or Back to query page."
               ."
"); print_footer(); - } - else { + } else { header('Location: indexer.php?areyousure=yes'); } -?> +?> \ No newline at end of file diff --git a/search/indexlib.php b/search/indexlib.php index be771b8b4a..3c2075ef29 100644 --- a/search/indexlib.php +++ b/search/indexlib.php @@ -7,6 +7,7 @@ * @subpackage search_engine * @author Michael Champanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8 * @date 2008/03/31 +* @version prepared for 2.0 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License * * Index info class @@ -19,8 +20,8 @@ /** * includes and requires */ -require_once("$CFG->dirroot/search/lib.php"); -require_once("$CFG->dirroot/search/Zend/Search/Lucene.php"); +require_once($CFG->dirroot.'/search/lib.php'); +require_once($CFG->dirroot.'/search/Zend/Search/Lucene.php'); /** * main class for searchable information in the Lucene index @@ -67,8 +68,6 @@ class IndexInfo { //get all the current tables in moodle $admin_tables = $DB->get_tables(); - //TODO: use new IndexDBControl class for database checks? - //check if our search table exists if (in_array(SEARCH_DATABASE_TABLE, $admin_tables)) { //retrieve database information if it does @@ -78,14 +77,14 @@ class IndexInfo { $this->dbcount = $DB->count_records(SEARCH_DATABASE_TABLE); //individual document types - // $types = search_get_document_types(); - $types = search_collect_searchables(true, false); - sort($types); + $types = search_collect_searchables(false, false); + asort($types); - foreach($types as $type) { - $c = $DB->count_records(SEARCH_DATABASE_TABLE, array('doctype'=>$type)); - $this->types[$type] = (int)$c; + foreach(array_keys($types) as $type) { + $c = $DB->count_records(SEARCH_DATABASE_TABLE, array('doctype' => $type)); + $types[$type]->records = (int)$c; } + $this->types = $types; } else { $this->dbcount = 0; $this->types = array(); @@ -178,14 +177,13 @@ class IndexDBControl { /** * does the table exist? * @deprecated - * @uses CFG, db + * @uses $CFG, $DB */ public function checkTableExists() { global $CFG, $DB; - $table = SEARCH_DATABASE_TABLE; $tables = $DB->get_tables(); - if (in_array($table, $tables)) { + if (in_array(SEARCH_DATABASE_TABLE, $tables)) { return true; } else { @@ -193,10 +191,35 @@ class IndexDBControl { } } //checkTableExists + /** + * NEVER USED + * + * is our database setup valid? + * @uses db, CFG + * @deprecated Database is installed at install and should not be dropped out + * + public function checkDB() { + global $CFG, $db; + + $sqlfile = "{$CFG->dirroot}/search/db/$CFG->dbtype.sql"; + $ret = false; + if ($this->checkTableExists()) { + execute_sql('drop table '.SEARCH_DATABASE_TABLE, false); + } + + //turn output buffering on - to hide modify_database() output + ob_start(); + $ret = modify_database($sqlfile, '', false); + + //chuck the buffer and resume normal operation + ob_end_clean(); + return $ret; + } //checkDB */ + /** * add a document record to the table * @param document must be a Lucene SearchDocument instance - * @uses db, CFG + * @uses $CFG, $DB */ public function addDocument($document=null) { global $DB, $CFG; @@ -206,7 +229,6 @@ class IndexDBControl { } // object to insert into db - $doc = new object(); $doc->doctype = $document->doctype; $doc->docid = $document->docid; $doc->itemtype = $document->itemtype; @@ -218,7 +240,8 @@ class IndexDBControl { $doc->groupid = $document->group_id; //insert summary into db - $id = $DB->insert_record(SEARCH_DATABASE_TABLE, $doc); + $table = SEARCH_DATABASE_TABLE; + $id = $DB->insert_record($table, $doc); return $id; } @@ -226,12 +249,13 @@ class IndexDBControl { /** * remove a document record from the index * @param document must be a Lucene document instance, or at least a dbid enveloppe - * @uses db + * @uses $DB */ public function delDocument($document) { global $DB; - delete_records(SEARCH_DATABASE_TABLE, 'id', $document->dbid); + $table = SEARCH_DATABASE_TABLE; + $DB->delete_records($table, array('id' => $document->dbid)); } } diff --git a/search/lib.php b/search/lib.php index 6706fc3e78..8484981379 100644 --- a/search/lib.php +++ b/search/lib.php @@ -7,6 +7,7 @@ * @subpackage search_engine * @author Michael Champanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8 * @date 2008/03/31 +* @version prepared for 2.0 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License * * General function library @@ -16,22 +17,14 @@ * */ -/* -// function reference -function search_collect_searchables($namelist=false, $verbose=true){ -function search_get_document_types($prefix = 'SEARCH_TYPE_') { -function search_get_document_types($prefix = 'X_SEARCH_TYPE_') { -function search_get_additional_modules() { -function search_shorten_url($url, $length=30) { -function search_stopwatch($cli = false) { -function search_pexit($str = "") { +/** +* Constants */ - -define('SEARCH_INDEX_PATH', "$CFG->dataroot/search"); +define('SEARCH_INDEX_PATH', $CFG->dataroot.'/search'); define('SEARCH_DATABASE_TABLE', 'block_search_documents'); // get document types -include "{$CFG->dirroot}/search/searchtypes.php"; +include_once $CFG->dirroot.'/search/searchtypes.php'; /** * collects all searchable items identities @@ -40,26 +33,29 @@ include "{$CFG->dirroot}/search/searchtypes.php"; * @return an array of names or an array of type descriptors */ function search_collect_searchables($namelist=false, $verbose=true){ - global $CFG; + global $CFG, $DB; $searchables = array(); $searchables_names = array(); /// get all installed modules - if ($mods = get_records('modules', '', '', 'name', 'id,name')){ + if ($mods = $DB->get_records('modules', null, 'name', 'id,name')){ $searchabletypes = array_values(search_get_document_types()); foreach($mods as $mod){ + $plugin = new StdClass(); + $plugin->name = $mod->name; + $plugin->type = 'mod'; if (in_array($mod->name, $searchabletypes)){ - $mod->location = 'internal'; - $searchables[$mod->name] = $mod; + $plugin->location = 'internal'; + $searchables[$plugin->name] = $plugin; $searchables_names[] = $mod->name; } else { $documentfile = $CFG->dirroot."/mod/{$mod->name}/search_document.php"; - $mod->location = 'mod'; + $plugin->location = 'mod'; if (file_exists($documentfile)){ - $searchables[$mod->name] = $mod; + $searchables[$plugin->name] = $plugin; $searchables_names[] = $mod->name; } } @@ -68,22 +64,25 @@ function search_collect_searchables($namelist=false, $verbose=true){ } /// collects blocks as indexable information may be found in blocks either - if ($blocks = get_records('block', '', '', 'name', 'id,name')) { + if ($blocks = $DB->get_records('block', null, 'name', 'id,name')) { $blocks_searchables = array(); // prepend the "block_" prefix to discriminate document type plugins foreach($blocks as $block){ - $block->dirname = $block->name; - $block->name = 'block_'.$block->name; + $plugin = new StdClass(); + $plugin->dirname = $block->name; + $plugin->name = 'block_'.$block->name; if (in_array('SEARCH_TYPE_'.strtoupper($block->name), $searchabletypes)){ - $mod->location = 'internal'; - $blocks_searchables[] = $block; - $searchables_names[] = $block->name; + $plugin->location = 'internal'; + $plugin->type = 'block'; + $blocks_searchables[$plugin->name] = $plugin; + $searchables_names[] = $plugin->name; } else { - $documentfile = $CFG->dirroot."/blocks/{$block->dirname}/search_document.php"; + $documentfile = $CFG->dirroot."/blocks/{$plugin->dirname}/search_document.php"; if (file_exists($documentfile)){ - $mod->location = 'blocks'; - $blocks_searchables[$block->name] = $block; - $searchables_names[] = $block->name; + $plugin->location = 'blocks'; + $plugin->type = 'block'; + $blocks_searchables[$plugin->name] = $plugin; + $searchables_names[] = $plugin->name; } } } @@ -93,7 +92,7 @@ function search_collect_searchables($namelist=false, $verbose=true){ /// add virtual modules onto the back of the array - $additional = search_get_additional_modules(); + $additional = search_get_additional_modules($searchables_names); if (!empty($additional)){ if ($verbose) mtrace(count($additional).' additional to search in.'); $searchables = array_merge($searchables, $additional); @@ -128,20 +127,25 @@ function search_get_document_types($prefix = 'SEARCH_TYPE_') { * virtual modules to be added to the index, i.e. non-module specific * information. */ -function search_get_additional_modules() { +function search_get_additional_modules(&$searchables_names) { $extras = array(/* additional keywords go here */); if (defined('SEARCH_EXTRAS')){ $extras = explode(',', SEARCH_EXTRAS); } $ret = array(); + $temp = new StdClass; foreach($extras as $extra) { - $temp->name = $extra; - $temp->location = 'internal'; - $ret[$temp->name] = clone($temp); + $plugin = new StdClass(); + $plugin->name = $extra; + $plugin->location = 'internal'; + eval('$plugin->type = TYPE_FOR_SEARCH_TYPE_'.strtoupper($extra).';'); + $ret[$plugin->name] = $plugin; + $searchables_names[] = $extra; } + return $ret; -} //search_get_additional_modules +} /** * shortens a url so it can fit on the results page @@ -150,7 +154,7 @@ function search_get_additional_modules() { */ function search_shorten_url($url, $length=30) { return substr($url, 0, $length)."..."; -} //search_shorten_url +} /** * simple timer function, on first call, records a current microtime stamp, outputs result on 2nd call @@ -163,11 +167,10 @@ function search_stopwatch($cli = false) { print round(microtime(true) - $GLOBALS['search_script_start_time'], 6).' '.get_string('seconds', 'search'); if (!$cli) print ''; unset($GLOBALS['search_script_start_time']); - } - else { + } else { $GLOBALS['search_script_start_time'] = microtime(true); } -} //search_stopwatch +} /** * print and exit (for debugging) @@ -181,6 +184,6 @@ function search_pexit($str = "") { print $str."
"; } exit(0); -} //search_pexit +} ?> diff --git a/search/querylib.php b/search/querylib.php index ddb1fe59dd..8591be9ccd 100644 --- a/search/querylib.php +++ b/search/querylib.php @@ -7,13 +7,14 @@ * @subpackage search_engine * @author Michael Champanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8 * @date 2008/03/31 +* @version prepared for 2.0 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License */ /** * includes and requires */ -require_once("{$CFG->dirroot}/search/Zend/Search/Lucene.php"); +require_once($CFG->dirroot.'/search/Zend/Search/Lucene.php'); define('DEFAULT_POPUP_SETTINGS', "\"menubar=0,location=0,scrollbars,resizable,width=600,height=450\""); @@ -68,17 +69,17 @@ private $mode, $last_term = $this->fetch('search_last_term'); //if this query is different from the last, clear out the last one - if ($id != false and $last_term != $id) { + if ($id != false && $last_term != $id) { $this->clear($last_term); } //store the new query if id and object are passed in - if ($object and $id) { + if ($object && $id) { $this->store('search_last_term', $id); $this->store($id, $object); return true; //otherwise return the stored results - } else if ($id and $this->exists($id)) { + } else if ($id && $this->exists($id)) { return $this->fetch($id); } } @@ -220,14 +221,18 @@ class SearchQuery { private function process_results($all=false) { global $USER; - $term = mb_convert_case($this->term, MB_CASE_LOWER, 'UTF-8'); + // unneeded since changing the default Zend Lexer + // $term = mb_convert_case($this->term, MB_CASE_LOWER, 'UTF-8'); + $term = $this->term; $page = optional_param('page', 1, PARAM_INT); //experimental - return more results - $strip_arr = array('author:', 'title:', '+', '-', 'doctype:'); - $stripped_term = str_replace($strip_arr, '', $term); + // $strip_arr = array('author:', 'title:', '+', '-', 'doctype:'); + // $stripped_term = str_replace($strip_arr, '', $term); - $hits = $this->index->find($term." title:".$stripped_term." author:".$stripped_term); + // $search_string = $term." title:".$stripped_term." author:".$stripped_term; + $search_string = $term; + $hits = $this->index->find($search_string); //-- $hitcount = count($hits); @@ -297,7 +302,7 @@ class SearchQuery { private function get_results() { $cache = new SearchCache(); - if ($this->cache and $cache->can_cache()) { + if ($this->cache && $cache->can_cache()) { if (!($resultdocs = $cache->cache($this->term))) { $resultdocs = $this->process_results(); //cache the results so we don't have to compute this on every page-load @@ -382,7 +387,7 @@ class SearchQuery { * // TODO reorder parameters more consistently */ private function can_display(&$user, $this_id, $doctype, $course_id, $group_id, $path, $item_type, $context_id, &$searchables) { - global $CFG; + global $CFG, $DB; /** * course related checks @@ -397,14 +402,14 @@ class SearchQuery { $unenroled = !in_array($course_id, array_keys($myCourses)); // if guests are allowed, logged guest can see - $isallowedguest = (isguest()) ? get_field('course', 'guest', 'id', $course_id) : false ; + $isallowedguest = (isguest()) ? $DB->get_field('course', 'guest', array('id' => $course_id)) : false ; if ($unenroled && !$isallowedguest){ return false; } // if user is enrolled or is allowed user and course is hidden, can he see it ? - $visibility = get_field('course', 'visible', 'id', $course_id); + $visibility = $DB->get_field('course', 'visible', array('id' => $course_id)); if ($visibility <= 0){ if (!has_capability('moodle/course:viewhiddencourses', get_context_instance(CONTEXT_COURSE, $course_id))){ return false; @@ -425,7 +430,7 @@ class SearchQuery { if ($searchable_instance->location == 'internal'){ include_once "{$CFG->dirroot}/search/documents/{$doctype}_document.php"; } else { - include_once "{$CFG->dirroot}/{$searchable_instance->location}/$doctype/search_document.php"; + include_once "{$CFG->dirroot}/{$searchable_instance->location}/{$doctype}/search_document.php"; } $access_check_function = "{$doctype}_check_text_access"; diff --git a/search/searchtypes.php b/search/searchtypes.php index 16f1a5cf8b..029126269e 100644 --- a/search/searchtypes.php +++ b/search/searchtypes.php @@ -8,6 +8,7 @@ * @subpackage search_engine * @author Michael Champanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8 * @date 2008/03/31 +* @version prepared for 2.0 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License * * Searcheable types @@ -25,9 +26,11 @@ define('SEARCH_TYPE_DATA', 'data'); define('SEARCH_TYPE_CHAT', 'chat'); define('SEARCH_TYPE_LESSON', 'lesson'); define('SEARCH_TYPE_ASSIGNMENT', 'assignment'); +define('SEARCH_TYPE_LABEL', 'label'); define('SEARCH_EXTRAS', 'user'); define('SEARCH_TYPE_USER', 'user'); define('PATH_FOR_SEARCH_TYPE_USER', 'user'); +define('TYPE_FOR_SEARCH_TYPE_USER', 'core'); ?> \ No newline at end of file diff --git a/search/stats.php b/search/stats.php index 4e6feae678..53225d58a6 100644 --- a/search/stats.php +++ b/search/stats.php @@ -1,5 +1,5 @@ 1.8 * @date 2008/03/31 +* @version prepared for 2.0 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License * * Prints some basic statistics about the current index. * Does some diagnostics if you are logged in as an administrator. -* +* */ /** * includes and requires */ require_once('../config.php'); -require_once("{$CFG->dirroot}/search/lib.php"); +require_once($CFG->dirroot.'/search/lib.php'); /// checks global search is enabled if ($CFG->forcelogin) { require_login(); } - + if (empty($CFG->enableglobalsearch)) { print_error('globalsearchdisabled', 'search'); } - + /// check for php5, but don't die yet - require_once("{$CFG->dirroot}/search/indexlib.php"); - + require_once($CFG->dirroot.'/search/indexlib.php'); + $indexinfo = new IndexInfo(); - + if (!$site = get_site()) { - redirect("index.php"); - } - + redirect($CFG->wwwroot.'index.php'); + } + $strsearch = get_string('search', 'search'); - $strquery = get_string('statistics', 'search'); - - 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)); - } - + $strquery = get_string('statistics', 'search'); + + $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)); + /// keep things pretty, even if php5 isn't available print_box_start(); print_heading($strquery); - + print_box_start(); - + $databasestr = get_string('database', 'search'); $documentsinindexstr = get_string('documentsinindex', 'search'); $deletionsinindexstr = get_string('deletionsinindex', 'search'); $documentsindatabasestr = get_string('documentsindatabase', 'search'); $databasestatestr = get_string('databasestate', 'search'); - + /// this table is only for admins, shows index directory size and location if (has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) { @@ -81,83 +77,90 @@ require_once("{$CFG->dirroot}/search/lib.php"); $checkdbadvicestr = get_string('checkdbadvice', 'search'); $runindexerteststr = get_string('runindexertest', 'search'); $runindexerstr = get_string('runindexer', 'search'); - - $admin_table->tablealign = "center"; - $admin_table->align = array ("right", "left"); - $admin_table->wrap = array ("nowrap", "nowrap"); + + $admin_table->tablealign = 'center'; + $admin_table->align = array ('right', 'left'); + $admin_table->wrap = array ('nowrap', 'nowrap'); $admin_table->cellpadding = 5; $admin_table->cellspacing = 0; $admin_table->width = '500'; - + $admin_table->data[] = array("{$datadirectorystr}", ''.$indexinfo->path.''); $admin_table->data[] = array($inindexdirectorystr, $indexinfo->filecount); $admin_table->data[] = array($totalsizestr, $indexinfo->size); - + if ($indexinfo->time > 0) { $admin_table->data[] = array(get_string('createdon', 'search'), date('r', $indexinfo->time)); - } + } else { $admin_table->data[] = array(get_string('createdon', 'search'), '-'); - } - + } + if (!$indexinfo->valid($errors)) { $admin_table->data[] = array("{$errorsstr}", ' '); foreach ($errors as $key => $value) { $admin_table->data[] = array($key.' ... ', $value); - } + } } - + print_table($admin_table); print_spacer(20); print_heading($solutionsstr); - + unset($admin_table->data); if (isset($errors['dir'])) { $admin_table->data[] = array($checkdirstr, $checkdiradvicestr); - } + } if (isset($errors['db'])) { $admin_table->data[] = array($checkdbstr, $checkdbadvicestr); - } - + } + $admin_table->data[] = array($runindexerteststr, 'tests/index.php'); $admin_table->data[] = array($runindexerstr, 'indexersplash.php'); - + print_table($admin_table); print_spacer(20); - } - + } + /// this is the standard summary table for normal users, shows document counts - $table->tablealign = "center"; - $table->align = array ("right", "left"); - $table->wrap = array ("nowrap", "nowrap"); + $table->tablealign = 'center'; + $table->align = array ('right', 'left'); + $table->wrap = array ('nowrap', 'nowrap'); $table->cellpadding = 5; $table->cellspacing = 0; $table->width = '500'; - + $table->data[] = array("{$databasestr}", "{$CFG->prefix}".SEARCH_DATABASE_TABLE.''); - + /// add extra fields if we're admin if (has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) { //don't want to confuse users if the two totals don't match (hint: they should) $table->data[] = array($documentsinindexstr, $indexinfo->indexcount); - + //*cough* they should match if deletions were actually removed from the index, //as it turns out, they're only marked as deleted and not returned in search results $table->data[] = array($deletionsinindexstr, (int)$indexinfo->indexcount - (int)$indexinfo->dbcount); - } - + } + $table->data[] = array($documentsindatabasestr, $indexinfo->dbcount); - - foreach($indexinfo->types as $key => $value) { - $table->data[] = array(get_string('documentsfor', 'search') . " '".get_string('modulenameplural', $key)."'", $value); - } - + + foreach($indexinfo->types as $type) { + if ($type->type == 'mod'){ + $table->data[] = array(get_string('documentsfor', 'search') . " '".get_string('modulenameplural', $type->name)."'", $type->records); + } else if ($type->type == 'block') { + $table->data[] = array(get_string('documentsfor', 'search') . " '".get_string('blockname', $type->name)."'", $type->records); + } else { + $table->data[] = array(get_string('documentsfor', 'search') . " '".get_string($type->name)."'", $type->records); + } + + } + print_heading($databasestatestr); print_table($table); - + print_box_end(); print_box_end(); print_footer(); -?> +?> \ No newline at end of file