Permalink
Browse files

Addresses the tracker MDL - 18638 and MDL 18474

  • Loading branch information...
diml
diml committed Mar 23, 2009
1 parent 964a5e9 commit 63c13a82f1a5b70d44dc2dae90328e57c32252fc
Showing with 263 additions and 233 deletions.
  1. +12 −5 search/cron_php5.php
  2. +46 −57 search/indexer.php
  3. +37 −41 search/indexersplash.php
  4. +42 −18 search/indexlib.php
  5. +42 −39 search/lib.php
  6. +18 −13 search/querylib.php
  7. +3 −0 search/searchtypes.php
  8. +63 −60 search/stats.php
View
@@ -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.</pre>");
mtrace('done');
View
@@ -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,125 +35,113 @@
* 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());
}
/// confirmation flag to prevent accidental reindexing (indexersplash.php is the correct entry point)
$sure = strtolower(optional_param('areyousure', '', PARAM_ALPHA));
-
+
if ($sure != 'yes') {
mtrace("<pre>Sorry, you need to confirm indexing via <a href='indexersplash.php'>indexersplash.php</a>"
.". (<a href='index.php'>Back to query page</a>).</pre>");
-
+
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('<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8" /></head><body>');
mtrace('<pre>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 @@
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 @@
}
}
}
-
+
/// finished modules
mtrace('Finished activity modules');
search_stopwatch();
-
+
mtrace(".<br/><a href='index.php'>Back to query page</a>.");
mtrace('</pre>');
-
+
/// 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());
-?>
+?>
View
@@ -1,60 +1,57 @@
<?php
-/**
-* 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
-* @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, "&nbsp;", navmenu($site));
-
+
mtrace("<pre>The data directory ($indexinfo->path) contains $indexinfo->filecount files, and\n"
."there are ".$indexinfo->dbcount." records in the <em>block_search_documents</em> table.\n"
."\n"
@@ -70,8 +67,7 @@
."<a href='indexer.php?areyousure=yes'>Continue indexing</a> or <a href='index.php'>Back to query page</a>."
."</pre>");
print_footer();
- }
- else {
+ } else {
header('Location: indexer.php?areyousure=yes');
}
-?>
+?>
Oops, something went wrong.

0 comments on commit 63c13a8

Please sign in to comment.