3 * Global Search Engine for Moodle
7 * @subpackage search_engine
8 * @author Michael Champanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
10 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
12 * Prints some basic statistics about the current index.
13 * Does some diagnostics if you are logged in as an administrator.
18 * includes and requires
20 require_once('../config.php');
21 require_once("{$CFG->dirroot}/search/lib.php");
23 /// checks global search is enabled
25 if ($CFG->forcelogin
) {
29 if (empty($CFG->enableglobalsearch
)) {
30 error(get_string('globalsearchdisabled', 'search'));
33 /// check for php5, but don't die yet
35 require_once("{$CFG->dirroot}/search/indexlib.php");
37 $indexinfo = new IndexInfo();
39 if (!$site = get_site()) {
40 redirect("index.php");
43 $strsearch = get_string('search', 'search');
44 $strquery = get_string('statistics', 'search');
46 if (!function_exists('build_navigation')){
47 print_header("$site->shortname: $strsearch: $strquery", "$site->fullname",
48 "<a href=\"index.php\">$strsearch</a> -> $strquery");
50 $navlinks[] = array('name' => $strsearch, 'link' => "index.php", 'type' => 'misc');
51 $navlinks[] = array('name' => $strquery, 'link' => null, 'type' => 'misc');
52 $navigation = build_navigation($navlinks);
54 print_header("$strsearch", "$site->fullname" , $navigation, "", "", true, " ", navmenu($site));
57 /// keep things pretty, even if php5 isn't available
60 print_heading($strquery);
64 $databasestr = get_string('database', 'search');
65 $documentsinindexstr = get_string('documentsinindex', 'search');
66 $deletionsinindexstr = get_string('deletionsinindex', 'search');
67 $documentsindatabasestr = get_string('documentsindatabase', 'search');
68 $databasestatestr = get_string('databasestate', 'search');
70 /// this table is only for admins, shows index directory size and location
72 if (has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM
))) {
73 $datadirectorystr = get_string('datadirectory', 'search');
74 $inindexdirectorystr = get_string('filesinindexdirectory', 'search');
75 $totalsizestr = get_string('totalsize', 'search');
76 $errorsstr = get_string('errors', 'search');
77 $solutionsstr = get_string('solutions', 'search');
78 $checkdirstr = get_string('checkdir', 'search');
79 $checkdbstr = get_string('checkdb', 'search');
80 $checkdiradvicestr = get_string('checkdiradvice', 'search');
81 $checkdbadvicestr = get_string('checkdbadvice', 'search');
82 $runindexerteststr = get_string('runindexertest', 'search');
83 $runindexerstr = get_string('runindexer', 'search');
85 $admin_table->tablealign
= "center";
86 $admin_table->align
= array ("right", "left");
87 $admin_table->wrap
= array ("nowrap", "nowrap");
88 $admin_table->cellpadding
= 5;
89 $admin_table->cellspacing
= 0;
90 $admin_table->width
= '500';
92 $admin_table->data
[] = array("<strong>{$datadirectorystr}</strong>", '<em><strong>'.$indexinfo->path
.'</strong></em>');
93 $admin_table->data
[] = array($inindexdirectorystr, $indexinfo->filecount
);
94 $admin_table->data
[] = array($totalsizestr, $indexinfo->size
);
96 if ($indexinfo->time
> 0) {
97 $admin_table->data
[] = array(get_string('createdon', 'search'), date('r', $indexinfo->time
));
100 $admin_table->data
[] = array(get_string('createdon', 'search'), '-');
103 if (!$indexinfo->valid($errors)) {
104 $admin_table->data
[] = array("<strong>{$errorsstr}</strong>", ' ');
105 foreach ($errors as $key => $value) {
106 $admin_table->data
[] = array($key.' ... ', $value);
110 print_table($admin_table);
112 print_heading($solutionsstr);
114 unset($admin_table->data
);
115 if (isset($errors['dir'])) {
116 $admin_table->data
[] = array($checkdirstr, $checkdiradvicestr);
118 if (isset($errors['db'])) {
119 $admin_table->data
[] = array($checkdbstr, $checkdbadvicestr);
122 $admin_table->data
[] = array($runindexerteststr, '<a href="tests/index.php" target="_blank">tests/index.php</a>');
123 $admin_table->data
[] = array($runindexerstr, '<a href="indexersplash.php" target="_blank">indexersplash.php</a>');
125 print_table($admin_table);
129 /// this is the standard summary table for normal users, shows document counts
131 $table->tablealign
= "center";
132 $table->align
= array ("right", "left");
133 $table->wrap
= array ("nowrap", "nowrap");
134 $table->cellpadding
= 5;
135 $table->cellspacing
= 0;
136 $table->width
= '500';
138 $table->data
[] = array("<strong>{$databasestr}</strong>", "<em><strong>{$CFG->prefix}".SEARCH_DATABASE_TABLE
.'</strong></em>');
140 /// add extra fields if we're admin
142 if (has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM
))) {
143 //don't want to confuse users if the two totals don't match (hint: they should)
144 $table->data
[] = array($documentsinindexstr, $indexinfo->indexcount
);
146 //*cough* they should match if deletions were actually removed from the index,
147 //as it turns out, they're only marked as deleted and not returned in search results
148 $table->data
[] = array($deletionsinindexstr, (int)$indexinfo->indexcount
- (int)$indexinfo->dbcount
);
151 $table->data
[] = array($documentsindatabasestr, $indexinfo->dbcount
);
153 foreach($indexinfo->types
as $key => $value) {
154 $table->data
[] = array(get_string('documentsfor', 'search') . " '".get_string('modulenameplural', $key)."'", $value);
157 print_heading($databasestatestr);