* 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');
* @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 -
* 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';
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");
}
}
}
}
-
+
/// 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());
-?>
+?>
\ No newline at end of file
<?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, " ", 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"
."<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');
}
-?>
+?>
\ No newline at end of file
* @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
/**
* 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
//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
$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();
/**
* 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 {
}
} //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;
}
// object to insert into db
- $doc = new object();
$doc->doctype = $document->doctype;
$doc->docid = $document->docid;
$doc->itemtype = $document->itemtype;
$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;
}
/**
* 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));
}
}
* @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
*
*/
-/*
-// 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
* @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;
}
}
}
/// 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;
}
}
}
/// 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);
* 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
*/
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
print round(microtime(true) - $GLOBALS['search_script_start_time'], 6).' '.get_string('seconds', 'search');
if (!$cli) print '</em>';
unset($GLOBALS['search_script_start_time']);
- }
- else {
+ } else {
$GLOBALS['search_script_start_time'] = microtime(true);
}
-} //search_stopwatch
+}
/**
* print and exit (for debugging)
print $str."<br/>";
}
exit(0);
-} //search_pexit
+}
?>
* @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\"");
$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);
}
}
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);
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
* // 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
$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;
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";
* @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
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
<?php
-/**
+/**
* Global Search Engine for Moodle
*
* @package search
* @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
*
* 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",
- "<a href=\"index.php\">$strsearch</a> -> $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))) {
$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("<strong>{$datadirectorystr}</strong>", '<em><strong>'.$indexinfo->path.'</strong></em>');
$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("<strong>{$errorsstr}</strong>", ' ');
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, '<a href="tests/index.php" target="_blank">tests/index.php</a>');
$admin_table->data[] = array($runindexerstr, '<a href="indexersplash.php" target="_blank">indexersplash.php</a>');
-
+
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("<strong>{$databasestr}</strong>", "<em><strong>{$CFG->prefix}".SEARCH_DATABASE_TABLE.'</strong></em>');
-
+
/// 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