MDL-9265:
[moodle-linuxchix.git] / search / stats.php
blob5e391b164f671a6f238c44b2ef05fe95d39496b3
1 <?php
2 /* Prints some basic statistics about the current index.
4 * Does some diagnostics if you are logged in as an administrator.
5 * */
7 require_once('../config.php');
8 require_once("$CFG->dirroot/search/lib.php");
10 if ($CFG->forcelogin) {
11 require_login();
14 if (empty($CFG->enableglobalsearch)) {
15 error('Global searching is not enabled.');
18 //check for php5, but don't die yet
19 if ($check = search_check_php5()) {
20 require_once("$CFG->dirroot/search/indexlib.php");
22 $indexinfo = new IndexInfo();
23 } //if
25 if (!$site = get_site()) {
26 redirect("index.php");
27 } //if
29 $strsearch = "Search"; //get_string();
30 $strquery = "Search statistics"; //get_string();
32 print_header("$site->shortname: $strsearch: $strquery", "$site->fullname",
33 "<a href=\"index.php\">$strsearch</a> -> $strquery");
35 //keep things pretty, even if php5 isn't available
36 if (!$check) {
37 print_heading(search_check_php5(true));
38 print_footer();
39 exit(0);
40 } //if
42 print_simple_box_start('center', '100%', '', 20);
43 print_heading($strquery);
45 print_simple_box_start('center', '', '', 20);
47 //this table is only for admins, shows index directory size and location
48 if (isadmin()) {
49 $admin_table->tablealign = "center";
50 $admin_table->align = array ("right", "left");
51 $admin_table->wrap = array ("nowrap", "nowrap");
52 $admin_table->cellpadding = 5;
53 $admin_table->cellspacing = 0;
54 $admin_table->width = '500';
56 $admin_table->data[] = array('<strong>Data directory</strong>', '<em><strong>'.$indexinfo->path.'</strong></em>');
57 $admin_table->data[] = array('Files in index directory', $indexinfo->filecount);
58 $admin_table->data[] = array('Total size', $indexinfo->size);
60 if ($indexinfo->time > 0) {
61 $admin_table->data[] = array('Created on', date('r', $indexinfo->time));
62 } else {
63 $admin_table->data[] = array('Created on', '-');
64 } //else
66 if (!$indexinfo->valid($errors)) {
67 $admin_table->data[] = array('<strong>Errors</strong>', '&nbsp;');
69 foreach ($errors as $key=>$value) {
70 $admin_table->data[] = array($key.' ... ', $value);
71 } //foreach
73 $admin_table->data[] = array('<strong>Solutions</strong>', '&nbsp;');
75 if (isset($errors['dir'])) {
76 $admin_table->data[] = array('Check dir', 'Ensure the data directory exists and is writable.');
77 } //if
79 if (isset($errors['db'])) {
80 $admin_table->data[] = array('Check DB', 'Check your database for any problems.');
81 } //if
83 $admin_table->data[] = array('Run indexer test', '<a href=\'tests/index.php\'>tests/index.php</a>');
84 $admin_table->data[] = array('Run indexer', '<a href=\'indexersplash.php\'>indexersplash.php</a>');
85 } //if
86 } //if
88 //this is the standard summary table for normal users, shows document counts
89 $table->tablealign = "center";
90 $table->align = array ("right", "left");
91 $table->wrap = array ("nowrap", "nowrap");
92 $table->cellpadding = 5;
93 $table->cellspacing = 0;
94 $table->width = '500';
96 $table->data[] = array('<strong>Database</strong>', '<em><strong>search_documents<strong></em>');
98 //add extra fields if we're admin
99 if (isadmin()) {
100 //don't want to confuse users if the two totals don't match (hint: they should)
101 $table->data[] = array('Documents in index', $indexinfo->indexcount);
103 //*cough* they should match if deletions were actually removed from the index,
104 //as it turns out, they're only marked as deleted and not returned in search results
105 $table->data[] = array('Deletions in index', (int)$indexinfo->indexcount - (int)$indexinfo->dbcount);
106 } //if
108 $table->data[] = array('Documents in database', $indexinfo->dbcount);
110 foreach($indexinfo->types as $key => $value) {
111 $table->data[] = array("'$key' documents", $value);
112 } //foreach
114 if (isadmin()) {
115 print_table($admin_table);
116 print_spacer(20);
117 } //if
119 print_table($table);
121 print_simple_box_end();
122 print_simple_box_end();
123 print_footer();