Permalink
Browse files

global sync to HEAD for passing fixes

  • Loading branch information...
diml
diml committed Apr 7, 2008
1 parent 3702d88 commit 2e47bfb16b833d8fe2950419b69ac60001509aae
@@ -1,22 +1,25 @@
<?php
/* This is the global search shortcut block - a single query can be entered, and
- the user will be redirected to the query page where they can enter more
- advanced queries, and view the results of their search. When searching from
- this block, the broadest possible selection of documents is searched.
-
- Author: Michael Champanis (mchampan)
- Date: 2006 06 25
-
- Todo: make strings -> get_string()
+ * the user will be redirected to the query page where they can enter more
+ * advanced queries, and view the results of their search. When searching from
+ * this block, the broadest possible selection of documents is searched.
+ *
+ *
+ * Todo: make strings -> get_string()
+ *
+ * @package search
+ * @subpackage search block
+ * @author: Michael Champanis (mchampan), reengineered by Valery Fremaux
+ * @date: 2006 06 25
*/
class block_search extends block_base {
function init() {
$this->title = get_string('blockname', 'block_search');
$this->cron = 1;
- $this->version = 2007081100;
+ $this->version = 2008031500;
} //init
// only one instance of this block is required
@@ -55,6 +55,20 @@
} ?>"/><br/><br/>
</td>
</tr>
+ <tr>
+ <td valign="top" align="right">
+ <b><?php print_string('usemoodleroot', 'block_search') ?>:</b>
+ </td>
+ <td valign="top" align="left">
+ <?php
+ $usemoodleroot = (isset($CFG->block_search_usemoodleroot)) ? 'checked="checked"' : '' ;
+ $notusemoodleroot = (!isset($CFG->block_search_usemoodleroot)) ? 'checked="checked"' : '' ;
+ ?>
+ <input id="block_search_usemoodleroot" type="radio" name="block_search_usemoodleroot" <?php echo $usemoodleroot ?> value="1"/> <?php print_string('yes') ?> -
+ <input id="block_search_usemoodleroot" type="radio" name="block_search_usemoodleroot" <?php echo $notusemoodleroot ?> value="0"/> <?php print_string('no') ?>
+ <br/><br/>
+ </td>
+ </tr>
<tr>
<td valign="top" align="right">
<b><?php print_string('configpdftotextcmd', 'block_search') ?>:</b>
View
@@ -1,5 +1,5 @@
Cette distribution partielle contient une refonte du moteur de
-recherche globalde Moodle.
+recherche globale de Moodle.
Le moteur de recherche est capable d'indexer et de rechercher
des informations dans un grand nombre de contenus stock�s
View
@@ -1,144 +1,158 @@
<?php
/**
* Global Search Engine for Moodle
-* Michael Champanis (mchampan) [cynnical@gmail.com]
-* review 1.8+ : Valery Fremaux [valery.fremaux@club-internet.fr]
-* 2007/08/02
+*
+* @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
*
* Asynchronous adder for new indexable contents
*
* Major chages in this review is passing the xxxx_db_names return to
* multiple arity to handle multiple document types modules
*/
+/**
+* includes and requires
+*/
require_once('../config.php');
require_once("$CFG->dirroot/search/lib.php");
-require_login();
-
-if (empty($CFG->enableglobalsearch)) {
- error(get_string('globalsearchdisabled', 'search'));
-}
-
-if (!isadmin()) {
- error(get_string('beadmin', 'search'), "$CFG->wwwroot/login/index.php");
-}
-
-//check for php5 (lib.php)
-if (!search_check_php5()) {
- $phpversion = phpversion();
- mtrace("Sorry, global search requires PHP 5.0.0 or later (currently using version $phpversion)");
- exit(0);
-}
-
-require_once("$CFG->dirroot/search/indexlib.php");
-
-$index = new Zend_Search_Lucene(SEARCH_INDEX_PATH);
-$dbcontrol = new IndexDBControl();
-$addition_count = 0;
-$startindextime = time();
-
-$indexdate = $CFG->search_indexer_run_date;
-
-mtrace('<pre>Starting index update (additions)...');
-mtrace('Index size before: '.$CFG->search_index_size."\n");
+/// checks global search activation
+
+ require_login();
+
+ if (empty($CFG->enableglobalsearch)) {
+ error(get_string('globalsearchdisabled', 'search'));
+ }
+
+ if (!isadmin()) {
+ error(get_string('beadmin', 'search'), "$CFG->wwwroot/login/index.php");
+ }
+
+/// check for php5 (lib.php)
-//get all modules
-if ($mods = get_records_select('modules')) {
+ if (!search_check_php5()) {
+ $phpversion = phpversion();
+ mtrace("Sorry, global search requires PHP 5.0.0 or later (currently using version ".phpversion().")");
+ exit(0);
+ }
+
+ require_once("$CFG->dirroot/search/indexlib.php");
+
+ $index = new Zend_Search_Lucene(SEARCH_INDEX_PATH);
+ $dbcontrol = new IndexDBControl();
+ $addition_count = 0;
+ $startindextime = time();
+
+ $indexdate = $CFG->search_indexer_run_date;
+
+ mtrace('Starting index update (additions)...');
+ mtrace('Index size before: '.$CFG->search_index_size."\n");
+
+/// get all modules
+ if ($mods = get_records_select('modules')) {
+
+/// append virtual modules onto array
-//append virtual modules onto array
-$mods = array_merge($mods, search_get_additional_modules());
- foreach ($mods as $mod) {
- //build include file and function names
- $class_file = $CFG->dirroot.'/search/documents/'.$mod->name.'_document.php';
- $db_names_function = $mod->name.'_db_names';
- $get_document_function = $mod->name.'_single_document';
- $get_newrecords_function = $mod->name.'_new_records';
- $additions = array();
-
- if (file_exists($class_file)) {
- require_once($class_file);
+ $mods = array_merge($mods, search_get_additional_modules());
+ foreach ($mods as $mod) {
+ //build include file and function names
+ $class_file = $CFG->dirroot.'/search/documents/'.$mod->name.'_document.php';
+ $db_names_function = $mod->name.'_db_names';
+ $get_document_function = $mod->name.'_single_document';
+ $get_newrecords_function = $mod->name.'_new_records';
+ $additions = array();
- //if both required functions exist
- if (function_exists($db_names_function) and function_exists($get_document_function)) {
- mtrace("Checking $mod->name module for additions.");
- $valuesArray = $db_names_function();
- if ($valuesArray){
- foreach($valuesArray as $values){
- $where = (isset($values[5])) ? 'AND ('.$values[5].')' : '';
- $itemtypes = ($values[4] != '*') ? " AND itemtype = '{$values[4]}' " : '' ;
-
- //select records in MODULE table, but not in SEARCH_DATABASE_TABLE
- $table = SEARCH_DATABASE_TABLE;
- $query = "
- SELECT
- docid,
- itemtype
- FROM
- {$CFG->prefix}{$table}
- WHERE
- doctype = '{$mod->name}'
- $itemtypes
- ";
- $docIds = get_records_sql_menu($query);
- $docIdList = ($docIds) ? implode("','", array_keys($docIds)) : '' ;
-
- $query = "
- SELECT id,
- {$values[0]} as docid
- FROM
- {$CFG->prefix}{$values[1]}
- WHERE
- id NOT IN ('{$docIdList}') and
- {$values[2]} > {$indexdate}
- $where
- ";
- $records = get_records_sql($query);
-
- // foreach record, build a module specific search document using the get_document function
- if (is_array($records)) {
- foreach($records as $record) {
- $add = $get_document_function($record->docid, $values[4]);
- // some documents may not be indexable
- if ($add)
- $additions[] = $add;
+ if (file_exists($class_file)) {
+ require_once($class_file);
+
+ //if both required functions exist
+ if (function_exists($db_names_function) and function_exists($get_document_function)) {
+ mtrace("Checking $mod->name module for additions.");
+ $valuesArray = $db_names_function();
+ if ($valuesArray){
+ foreach($valuesArray as $values){
+ $where = (isset($values[5])) ? 'AND ('.$values[5].')' : '';
+ $itemtypes = ($values[4] != '*' && $values[4] != 'any') ? " AND itemtype = '{$values[4]}' " : '' ;
+
+ //select records in MODULE table, but not in SEARCH_DATABASE_TABLE
+ $table = SEARCH_DATABASE_TABLE;
+ $query = "
+ SELECT
+ docid,
+ itemtype
+ FROM
+ {$CFG->prefix}{$table}
+ WHERE
+ doctype = '{$mod->name}'
+ $itemtypes
+ ";
+ $docIds = get_records_sql_menu($query);
+ $docIdList = ($docIds) ? implode("','", array_keys($docIds)) : '' ;
+
+ $query = "
+ SELECT id,
+ {$values[0]} as docid
+ FROM
+ {$CFG->prefix}{$values[1]}
+ WHERE
+ id NOT IN ('{$docIdList}') and
+ {$values[2]} > {$indexdate}
+ $where
+ ";
+ $records = get_records_sql($query);
+
+ // foreach record, build a module specific search document using the get_document function
+ if (is_array($records)) {
+ foreach($records as $record) {
+ $add = $get_document_function($record->docid, $values[4]);
+ // some documents may not be indexable
+ if ($add)
+ $additions[] = $add;
+ }
}
}
- }
-
- // foreach document, add it to the index and database table
- foreach ($additions as $add) {
- ++$addition_count;
- // object to insert into db
- $dbid = $dbcontrol->addDocument($add);
-
- // synchronise db with index
- $add->addField(Zend_Search_Lucene_Field::Keyword('dbid', $dbid));
-
- mtrace(" Add: $add->title (database id = $add->dbid, moodle instance id = $add->docid)");
-
- $index->addDocument($add);
- }
- }
- else{
- mtrace("No types to add.\n");
- }
- mtrace("Finished $mod->name.\n");
+ // foreach document, add it to the index and database table
+ foreach ($additions as $add) {
+ ++$addition_count;
+
+ // object to insert into db
+ $dbid = $dbcontrol->addDocument($add);
+
+ // synchronise db with index
+ $add->addField(Zend_Search_Lucene_Field::Keyword('dbid', $dbid));
+
+ mtrace(" Add: $add->title (database id = $add->dbid, moodle instance id = $add->docid)");
+
+ $index->addDocument($add);
+ }
+ }
+ else{
+ mtrace("No types to add.\n");
+ }
+ mtrace("Finished $mod->name.\n");
+ }
}
}
}
-}
+
+/// commit changes
-// commit changes
-$index->commit();
+ $index->commit();
+
+/// update index date and size
-// update index date and size
-set_config("search_indexer_run_date", $startindextime);
-set_config("search_index_size", (int)$CFG->search_index_size + (int)$addition_count);
+ set_config("search_indexer_run_date", $startindextime);
+ set_config("search_index_size", (int)$CFG->search_index_size + (int)$addition_count);
+
+/// print some additional info
-// print some additional info
-mtrace("Added $addition_count documents.");
-mtrace('Index size after: '.$index->count().'</pre>');
+ mtrace("Added $addition_count documents.");
+ mtrace('Index size after: '.$index->count());
?>
View
@@ -12,7 +12,10 @@
* adds documents created since the last index run
*/
- require_once('../config.php');
+ if (!defined('MOODLE_INTERNAL')) {
+ die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
+ }
+
require_once("$CFG->dirroot/search/lib.php");
if (!search_check_php5()) {
View
@@ -4,22 +4,23 @@
* This is a special externalized code for cron handling in PHP5.
* Should never be called by a php 4.3.0 implementation.
*/
+
try{
// overrides php limits
$maxtimelimit = ini_get('max_execution_time');
ini_set('max_execution_time', 300);
$maxmemoryamount = ini_get('memory_limit');
ini_set('memory_limit', '48M');
- mtrace("<pre>Starting cron...\n");
- mtrace("--DELETE----");
+ mtrace("\n--DELETE----");
require_once("$CFG->dirroot/search/delete.php");
mtrace("--UPDATE----");
require_once("$CFG->dirroot/search/update.php");
mtrace("--ADD-------");
require_once("$CFG->dirroot/search/add.php");
mtrace("------------");
- mtrace("cron finished.</pre>");
+ //mtrace("cron finished.</pre>");
+ mtrace('done');
// set back normal values for php limits
ini_set('max_execution_time', $maxtimelimit);
Oops, something went wrong.

0 comments on commit 2e47bfb

Please sign in to comment.