Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

sync with HEAD/1.8 compatible

  • Loading branch information...
commit d3d9d95f425bde66ae877bd2b6112ba6e4b5d5c0 1 parent ee95c70
authored April 07, 2008
2  search/LISEZMOI.txt
... ...
@@ -1,5 +1,5 @@
1 1
 Cette distribution partielle contient une refonte du moteur de 
2  
-recherche globalde Moodle.
  2
+recherche globale de Moodle.
3 3
 
4 4
 Le moteur de recherche est capable d'indexer et de rechercher 
5 5
 des informations dans un grand nombre de contenus stockés
1  search/READMETOO.txt
@@ -67,6 +67,7 @@ In the actual state, the engine indexes the following information:
67 67
 - wiki pages
68 68
 - techproject descriptions
69 69
 - char sessions
  70
+- lesson pages
70 71
 
71 72
 Extensions
72 73
 ##########
248  search/add.php
... ...
@@ -1,9 +1,13 @@
1 1
 <?php
2 2
 /**
3 3
 * Global Search Engine for Moodle
4  
-* Michael Champanis (mchampan) [cynnical@gmail.com]
5  
-* review 1.8+ : Valery Fremaux [valery.fremaux@club-internet.fr] 
6  
-* 2007/08/02
  4
+*
  5
+* @package search
  6
+* @category core
  7
+* @subpackage search_engine
  8
+* @author Michael Champanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
  9
+* @date 2008/03/31
  10
+* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
7 11
 *
8 12
 * Asynchronous adder for new indexable contents
9 13
 *
@@ -11,134 +15,144 @@
11 15
 * multiple arity to handle multiple document types modules
12 16
 */
13 17
 
  18
+/**
  19
+* includes and requires 
  20
+*/
14 21
 require_once('../config.php');
15 22
 require_once("$CFG->dirroot/search/lib.php");
16 23
 
17  
-require_login();
18  
-
19  
-if (empty($CFG->enableglobalsearch)) {
20  
-    print_error('globalsearchdisabled', 'search');
21  
-}
22  
-
23  
-if (!isadmin()) {
24  
-    print_error('beadmin', 'search', "$CFG->wwwroot/login/index.php");
25  
-} 
26  
-
27  
-//check for php5 (lib.php)
28  
-if (!search_check_php5()) {
29  
-    $phpversion = phpversion();
30  
-    mtrace("Sorry, global search requires PHP 5.0.0 or later (currently using version $phpversion)");
31  
-    exit(0);
32  
-} 
33  
-
34  
-require_once("$CFG->dirroot/search/indexlib.php");
35  
-
36  
-$index = new Zend_Search_Lucene(SEARCH_INDEX_PATH);
37  
-$dbcontrol = new IndexDBControl();
38  
-$addition_count = 0;
39  
-$startindextime = time();
40  
-
41  
-$indexdate = $CFG->search_indexer_run_date;
42  
-
43  
-mtrace('Starting index update (additions)...');
44  
-mtrace('Index size before: '.$CFG->search_index_size."\n");
  24
+/// checks global search activation
  25
+    
  26
+    require_login();
  27
+    
  28
+    if (empty($CFG->enableglobalsearch)) {
  29
+        error(get_string('globalsearchdisabled', 'search'));
  30
+    }
  31
+    
  32
+    if (!isadmin()) {
  33
+        error(get_string('beadmin', 'search'), "$CFG->wwwroot/login/index.php");
  34
+    } 
  35
+    
  36
+/// check for php5 (lib.php)
45 37
 
46  
-//get all modules
47  
-if ($mods = get_records_select('modules')) {
  38
+    if (!search_check_php5()) {
  39
+        $phpversion = phpversion();
  40
+        mtrace("Sorry, global search requires PHP 5.0.0 or later (currently using version ".phpversion().")");
  41
+        exit(0);
  42
+    } 
  43
+    
  44
+    require_once("$CFG->dirroot/search/indexlib.php");
  45
+    
  46
+    $index = new Zend_Search_Lucene(SEARCH_INDEX_PATH);
  47
+    $dbcontrol = new IndexDBControl();
  48
+    $addition_count = 0;
  49
+    $startindextime = time();
  50
+    
  51
+    $indexdate = $CFG->search_indexer_run_date;
  52
+    
  53
+    mtrace('Starting index update (additions)...');
  54
+    mtrace('Index size before: '.$CFG->search_index_size."\n");
  55
+    
  56
+/// get all modules
  57
+    if ($mods = get_records_select('modules')) {
  58
+    
  59
+/// append virtual modules onto array
48 60
 
49  
-//append virtual modules onto array
50  
-$mods = array_merge($mods, search_get_additional_modules());
51  
-    foreach ($mods as $mod) {
52  
-        //build include file and function names
53  
-        $class_file = $CFG->dirroot.'/search/documents/'.$mod->name.'_document.php';
54  
-        $db_names_function = $mod->name.'_db_names';
55  
-        $get_document_function = $mod->name.'_single_document';
56  
-        $get_newrecords_function = $mod->name.'_new_records';
57  
-        $additions = array();
58  
-        
59  
-        if (file_exists($class_file)) {
60  
-            require_once($class_file);
  61
+    $mods = array_merge($mods, search_get_additional_modules());
  62
+        foreach ($mods as $mod) {
  63
+            //build include file and function names
  64
+            $class_file = $CFG->dirroot.'/search/documents/'.$mod->name.'_document.php';
  65
+            $db_names_function = $mod->name.'_db_names';
  66
+            $get_document_function = $mod->name.'_single_document';
  67
+            $get_newrecords_function = $mod->name.'_new_records';
  68
+            $additions = array();
61 69
             
62  
-            //if both required functions exist
63  
-            if (function_exists($db_names_function) and function_exists($get_document_function)) {
64  
-                mtrace("Checking $mod->name module for additions.");
65  
-                $valuesArray = $db_names_function();
66  
-                if ($valuesArray){
67  
-                    foreach($valuesArray as $values){
68  
-                        $where = (isset($values[5])) ? 'AND ('.$values[5].')' : '';
69  
-                        $itemtypes = ($values[4] != '*') ? " AND itemtype = '{$values[4]}' " : '' ;
70  
-                        
71  
-                        //select records in MODULE table, but not in SEARCH_DATABASE_TABLE
72  
-                        $table = SEARCH_DATABASE_TABLE;
73  
-                        $query = "
74  
-                            SELECT 
75  
-                                docid,
76  
-                                itemtype 
77  
-                            FROM 
78  
-                                {$CFG->prefix}{$table}
79  
-                            WHERE 
80  
-                                doctype = '{$mod->name}'
81  
-                                $itemtypes
82  
-                        ";
83  
-                        $docIds = get_records_sql_menu($query);
84  
-                        $docIdList = ($docIds) ? implode("','", array_keys($docIds)) : '' ;
85  
-                        
86  
-                        $query =  "
87  
-                            SELECT id, 
88  
-                                {$values[0]} as docid 
89  
-                            FROM 
90  
-                                {$CFG->prefix}{$values[1]} 
91  
-                            WHERE 
92  
-                                id NOT IN ('{$docIdList}') and 
93  
-                                {$values[2]} > {$indexdate}
94  
-                                $where
95  
-                        ";
96  
-                        $records = get_records_sql($query);
97  
-                        
98  
-                        // foreach record, build a module specific search document using the get_document function
99  
-                        if (is_array($records)) {
100  
-                            foreach($records as $record) {
101  
-                                $add = $get_document_function($record->docid, $values[4]);
102  
-                                // some documents may not be indexable
103  
-                                if ($add)
104  
-                                    $additions[] = $add;
  70
+            if (file_exists($class_file)) {
  71
+                require_once($class_file);
  72
+                
  73
+                //if both required functions exist
  74
+                if (function_exists($db_names_function) and function_exists($get_document_function)) {
  75
+                    mtrace("Checking $mod->name module for additions.");
  76
+                    $valuesArray = $db_names_function();
  77
+                    if ($valuesArray){
  78
+                        foreach($valuesArray as $values){
  79
+                            $where = (isset($values[5])) ? 'AND ('.$values[5].')' : '';
  80
+                            $itemtypes = ($values[4] != '*' && $values[4] != 'any') ? " AND itemtype = '{$values[4]}' " : '' ;
  81
+                            
  82
+                            //select records in MODULE table, but not in SEARCH_DATABASE_TABLE
  83
+                            $table = SEARCH_DATABASE_TABLE;
  84
+                            $query = "
  85
+                                SELECT 
  86
+                                    docid,
  87
+                                    itemtype 
  88
+                                FROM 
  89
+                                    {$CFG->prefix}{$table}
  90
+                                WHERE 
  91
+                                    doctype = '{$mod->name}'
  92
+                                    $itemtypes
  93
+                            ";
  94
+                            $docIds = get_records_sql_menu($query);
  95
+                            $docIdList = ($docIds) ? implode("','", array_keys($docIds)) : '' ;
  96
+                            
  97
+                            $query =  "
  98
+                                SELECT id, 
  99
+                                    {$values[0]} as docid 
  100
+                                FROM 
  101
+                                    {$CFG->prefix}{$values[1]} 
  102
+                                WHERE 
  103
+                                    id NOT IN ('{$docIdList}') and 
  104
+                                    {$values[2]} > {$indexdate}
  105
+                                    $where
  106
+                            ";
  107
+                            $records = get_records_sql($query);
  108
+                            
  109
+                            // foreach record, build a module specific search document using the get_document function
  110
+                            if (is_array($records)) {
  111
+                                foreach($records as $record) {
  112
+                                    $add = $get_document_function($record->docid, $values[4]);
  113
+                                    // some documents may not be indexable
  114
+                                    if ($add)
  115
+                                        $additions[] = $add;
  116
+                                } 
105 117
                             } 
106 118
                         } 
107  
-                    } 
108  
-                    
109  
-                    // foreach document, add it to the index and database table
110  
-                    foreach ($additions as $add) {
111  
-                        ++$addition_count;
112 119
                         
113  
-                        // object to insert into db
114  
-                        $dbid = $dbcontrol->addDocument($add);
115  
-                        
116  
-                        // synchronise db with index
117  
-                        $add->addField(Zend_Search_Lucene_Field::Keyword('dbid', $dbid));
118  
-                        
119  
-                        mtrace("  Add: $add->title (database id = $add->dbid, moodle instance id = $add->docid)");
120  
-                        
121  
-                        $index->addDocument($add);
122  
-                    } 
123  
-                }
124  
-                else{
125  
-                    mtrace("No types to add.\n");
126  
-                }
127  
-                mtrace("Finished $mod->name.\n");
  120
+                        // foreach document, add it to the index and database table
  121
+                        foreach ($additions as $add) {
  122
+                            ++$addition_count;
  123
+                            
  124
+                            // object to insert into db
  125
+                            $dbid = $dbcontrol->addDocument($add);
  126
+                            
  127
+                            // synchronise db with index
  128
+                            $add->addField(Zend_Search_Lucene_Field::Keyword('dbid', $dbid));
  129
+                            
  130
+                            mtrace("  Add: $add->title (database id = $add->dbid, moodle instance id = $add->docid)");
  131
+                            
  132
+                            $index->addDocument($add);
  133
+                        } 
  134
+                    }
  135
+                    else{
  136
+                        mtrace("No types to add.\n");
  137
+                    }
  138
+                    mtrace("Finished $mod->name.\n");
  139
+                } 
128 140
             } 
129 141
         } 
130 142
     } 
131  
-} 
  143
+    
  144
+/// commit changes
132 145
 
133  
-// commit changes
134  
-$index->commit();
  146
+    $index->commit();
  147
+    
  148
+/// update index date and size
135 149
 
136  
-// update index date and size
137  
-set_config("search_indexer_run_date", $startindextime);
138  
-set_config("search_index_size", (int)$CFG->search_index_size + (int)$addition_count);
  150
+    set_config("search_indexer_run_date", $startindextime);
  151
+    set_config("search_index_size", (int)$CFG->search_index_size + (int)$addition_count);
  152
+    
  153
+/// print some additional info
139 154
 
140  
-// print some additional info
141  
-mtrace("Added $addition_count documents.");
142  
-mtrace('Index size after: '.$index->count());
  155
+    mtrace("Added $addition_count documents.");
  156
+    mtrace('Index size after: '.$index->count());
143 157
 
144 158
 ?>
1  search/cron_php5.php
@@ -4,6 +4,7 @@
4 4
 * This is a special externalized code for cron handling in PHP5.
5 5
 * Should never be called by a php 4.3.0 implementation. 
6 6
 */
  7
+
7 8
 try{
8 9
     // overrides php limits
9 10
     $maxtimelimit = ini_get('max_execution_time');
212  search/delete.php
... ...
@@ -1,9 +1,13 @@
1 1
 <?php
2 2
 /**
3 3
 * Global Search Engine for Moodle
4  
-* Michael Champanis (mchampan) [cynnical@gmail.com]
5  
-* review 1.8+ : Valery Fremaux [valery.fremaux@club-internet.fr] 
6  
-* 2007/08/02
  4
+*
  5
+* @package search
  6
+* @category core
  7
+* @subpackage search_engine
  8
+* @author Michael Champanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
  9
+* @date 2008/03/31
  10
+* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
7 11
 *
8 12
 * Asynchronous index cleaner
9 13
 *
@@ -11,122 +15,128 @@
11 15
 * multiple arity to handle multiple document types modules
12 16
 */
13 17
 
  18
+/**
  19
+* includes and requires
  20
+*/
14 21
 require_once('../config.php');
15 22
 require_once("$CFG->dirroot/search/lib.php");
16 23
 
17  
-require_login();
18  
-
19  
-if (empty($CFG->enableglobalsearch)) {
20  
-    print_error('globalsearchdisabled', 'search');
21  
-}
22  
-
23  
-if (!isadmin()) {
24  
-    print_error('beadmin', 'search', "$CFG->wwwroot/login/index.php");
25  
-} //if
26  
-
27  
-//check for php5 (lib.php)
28  
-if (!search_check_php5()) {
29  
-    $phpversion = phpversion();
30  
-    mtrace("Sorry, global search requires PHP 5.0.0 or later (currently using version $phpversion)");
31  
-    exit(0);
32  
-}
33  
-
34  
-require_once("$CFG->dirroot/search/indexlib.php");
35  
-
36  
-$index = new Zend_Search_Lucene(SEARCH_INDEX_PATH);
37  
-$dbcontrol = new IndexDBControl();
38  
-$deletion_count = 0;
39  
-$startcleantime = time();
40 24
 
41  
-mtrace('Starting clean-up of removed records...');
42  
-mtrace('Index size before: '.$CFG->search_index_size."\n");
43  
-
44  
-if ($mods = get_records_select('modules')) {
45  
-    $mods = array_merge($mods, search_get_additional_modules());
  25
+    require_login();
  26
+    
  27
+    if (empty($CFG->enableglobalsearch)) {
  28
+        error(get_string('globalsearchdisabled', 'search'));
  29
+    }
  30
+    
  31
+    if (!isadmin()) {
  32
+        error(get_string('beadmin', 'search'), "$CFG->wwwroot/login/index.php");
  33
+    } //if
  34
+    
  35
+    //check for php5 (lib.php)
  36
+    if (!search_check_php5()) {
  37
+        $phpversion = phpversion();
  38
+        mtrace("Sorry, global search requires PHP 5.0.0 or later (currently using version ".phpversion().")");
  39
+        exit(0);
  40
+    }
  41
+    
  42
+    require_once("$CFG->dirroot/search/indexlib.php");
46 43
     
47  
-    foreach ($mods as $mod) {
48  
-        //build function names
49  
-        $class_file = $CFG->dirroot.'/search/documents/'.$mod->name.'_document.php';
50  
-        $delete_function = $mod->name.'_delete';
51  
-        $db_names_function = $mod->name.'_db_names';
52  
-        $deletions = array();
  44
+    $index = new Zend_Search_Lucene(SEARCH_INDEX_PATH);
  45
+    $dbcontrol = new IndexDBControl();
  46
+    $deletion_count = 0;
  47
+    $startcleantime = time();
  48
+    
  49
+    mtrace('Starting clean-up of removed records...');
  50
+    mtrace('Index size before: '.$CFG->search_index_size."\n");
  51
+    
  52
+    if ($mods = get_records_select('modules')) {
  53
+        $mods = array_merge($mods, search_get_additional_modules());
53 54
         
54  
-        if (file_exists($class_file)) {
55  
-            require_once($class_file);
  55
+        foreach ($mods as $mod) {
  56
+            //build function names
  57
+            $class_file = $CFG->dirroot.'/search/documents/'.$mod->name.'_document.php';
  58
+            $delete_function = $mod->name.'_delete';
  59
+            $db_names_function = $mod->name.'_db_names';
  60
+            $deletions = array();
56 61
             
57  
-            //if both required functions exist
58  
-            if (function_exists($delete_function) and function_exists($db_names_function)) {
59  
-                mtrace("Checking $mod->name module for deletions.");
60  
-                $valuesArray = $db_names_function();
61  
-                if ($valuesArray){
62  
-                    foreach($valuesArray as $values){
63  
-                       $where = (isset($values[5])) ? 'WHERE '.$values[5] : '';
64  
-                       $itemtypes = ($values[4] != '*') ? " itemtype = '{$values[4]}' AND " : '' ;
65  
-                       $query = "
66  
-                            SELECT 
67  
-                                id,
68  
-                                {$values[0]}
69  
-                            FROM 
70  
-                                {$CFG->prefix}{$values[1]}
71  
-                                $where
72  
-                        ";
73  
-                        $docIds = get_records_sql($query);
74  
-                        $docIdList = ($docIds) ? implode("','", array_keys($docIds)) : '' ;
75  
-                        
76  
-                        $table = SEARCH_DATABASE_TABLE;
77  
-                        $query = "
78  
-                            SELECT 
79  
-                                id, 
80  
-                                docid 
81  
-                            FROM 
82  
-                                {$CFG->prefix}{$table}
83  
-                            WHERE 
84  
-                                doctype = '{$mod->name}' AND 
85  
-                                $itemtypes
86  
-                                docid not in ('{$docIdList}')
87  
-                        ";
88  
-                        $records = get_records_sql($query);
89  
-                        
90  
-                        // build an array of all the deleted records
91  
-                        if (is_array($records)) {
92  
-                            foreach($records as $record) {
93  
-                                $deletions[] = $delete_function($record->docid, $values[4]);
  62
+            if (file_exists($class_file)) {
  63
+                require_once($class_file);
  64
+                
  65
+                //if both required functions exist
  66
+                if (function_exists($delete_function) and function_exists($db_names_function)) {
  67
+                    mtrace("Checking $mod->name module for deletions.");
  68
+                    $valuesArray = $db_names_function();
  69
+                    if ($valuesArray){
  70
+                        foreach($valuesArray as $values){
  71
+                           $where = (isset($values[5])) ? 'WHERE '.$values[5] : '';
  72
+                           $itemtypes = ($values[4] != '*' && $values[4] != 'any') ? " itemtype = '{$values[4]}' AND " : '' ;
  73
+                           $query = "
  74
+                                SELECT 
  75
+                                    id,
  76
+                                    {$values[0]}
  77
+                                FROM 
  78
+                                    {$CFG->prefix}{$values[1]}
  79
+                                    $where
  80
+                            ";
  81
+                            $docIds = get_records_sql($query);
  82
+                            $docIdList = ($docIds) ? implode("','", array_keys($docIds)) : '' ;
  83
+                            
  84
+                            $table = SEARCH_DATABASE_TABLE;
  85
+                            $query = "
  86
+                                SELECT 
  87
+                                    id, 
  88
+                                    docid 
  89
+                                FROM 
  90
+                                    {$CFG->prefix}{$table}
  91
+                                WHERE 
  92
+                                    doctype = '{$mod->name}' AND 
  93
+                                    $itemtypes
  94
+                                    docid not in ('{$docIdList}')
  95
+                            ";
  96
+                            $records = get_records_sql($query);
  97
+                            
  98
+                            // build an array of all the deleted records
  99
+                            if (is_array($records)) {
  100
+                                foreach($records as $record) {
  101
+                                    $deletions[] = $delete_function($record->docid, $values[4]);
  102
+                                }
94 103
                             }
95 104
                         }
96  
-                    }
97  
-                    
98  
-                    foreach ($deletions as $delete) {
99  
-                        // find the specific document in the index, using it's docid and doctype as keys
100  
-                        $doc = $index->find("+docid:{$delete->id} +doctype:$mod->name +itemtype:{$delete->itemtype}");
101 105
                         
102  
-                        // get the record, should only be one
103  
-                        foreach ($doc as $thisdoc) {
104  
-                            ++$deletion_count;
105  
-                            mtrace("  Delete: $thisdoc->title (database id = $thisdoc->dbid, index id = $thisdoc->id, moodle instance id = $thisdoc->docid)");
  106
+                        foreach ($deletions as $delete) {
  107
+                            // find the specific document in the index, using it's docid and doctype as keys
  108
+                            $doc = $index->find("+docid:{$delete->id} +doctype:$mod->name +itemtype:{$delete->itemtype}");
106 109
                             
107  
-                            //remove it from index and database table
108  
-                            $dbcontrol->delDocument($thisdoc);
109  
-                            $index->delete($thisdoc->id);
  110
+                            // get the record, should only be one
  111
+                            foreach ($doc as $thisdoc) {
  112
+                                ++$deletion_count;
  113
+                                mtrace("  Delete: $thisdoc->title (database id = $thisdoc->dbid, index id = $thisdoc->id, moodle instance id = $thisdoc->docid)");
  114
+                                
  115
+                                //remove it from index and database table
  116
+                                $dbcontrol->delDocument($thisdoc);
  117
+                                $index->delete($thisdoc->id);
  118
+                            }
110 119
                         }
111 120
                     }
  121
+                    else{
  122
+                        mtrace("No types to delete.\n");
  123
+                    }
  124
+                    mtrace("Finished $mod->name.\n");
112 125
                 }
113  
-                else{
114  
-                    mtrace("No types to delete.\n");
115  
-                }
116  
-                mtrace("Finished $mod->name.\n");
117 126
             }
118 127
         }
119 128
     }
120  
-}
121  
-
122  
-//commit changes
123  
-$index->commit();
  129
+    
  130
+/// commit changes
124 131
 
125  
-//update index date and index size
126  
-set_config("search_indexer_cleanup_date", $startcleantime);
127  
-set_config("search_index_size", (int)$CFG->search_index_size - (int)$deletion_count);
  132
+    $index->commit();
  133
+    
  134
+/// update index date and index size
128 135
 
129  
-mtrace("Finished $deletion_count removals.");
130  
-mtrace('Index size after: '.$index->count());
  136
+    set_config("search_indexer_cleanup_date", $startcleantime);
  137
+    set_config("search_index_size", (int)$CFG->search_index_size - (int)$deletion_count);
  138
+    
  139
+    mtrace("Finished $deletion_count removals.");
  140
+    mtrace('Index size after: '.$index->count());
131 141
 
132 142
 ?>
13  search/index.php
... ...
@@ -1,9 +1,18 @@
1 1
 <?php
2  
-/* 
  2
+/**
  3
+* Global Search Engine for Moodle
  4
+*
  5
+* @package search
  6
+* @category core
  7
+* @subpackage search_engine
  8
+* @author Michael Champanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
  9
+* @date 2008/03/31
  10
+* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
  11
+*
3 12
 * Entry page for /search
4 13
 * Redirects to query.php, because that is the most likely place a
5 14
 * user intended to go to when typing moodle.site/search
6  
-**/
  15
+*/
7 16
 
8 17
 header("Location: query.php");
9 18
 ?>
327  search/indexer.php
... ...
@@ -1,9 +1,13 @@
1 1
 <?php
2 2
 /**
3 3
 * Global Search Engine for Moodle
4  
-* Michael Champanis (mchampan) [cynnical@gmail.com]
5  
-* review 1.8+ : Valery Fremaux [valery.fremaux@club-internet.fr] 
6  
-* 2007/08/02
  4
+*
  5
+* @package search
  6
+* @category core
  7
+* @subpackage search_engine
  8
+* @author Michael Champanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
  9
+* @date 2008/03/31
  10
+* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
7 11
 *
8 12
 * The indexer logic -
9 13
 *
@@ -26,178 +30,193 @@
26 30
 @ob_implicit_flush(true);
27 31
 @ob_end_flush();
28 32
 
  33
+/**
  34
+* includes and requires
  35
+*/
29 36
 require_once('../config.php');
30 37
 require_once("$CFG->dirroot/search/lib.php");
31 38
 
32  
-//only administrators can index the moodle installation, because access to all pages is required
33  
-require_login();
34  
-
35  
-if (empty($CFG->enableglobalsearch)) {
36  
-    print_error('globalsearchdisabled', 'search');
37  
-}
38  
-
39  
-if (!isadmin()) {
40  
-    print_error('beadmin', 'search', "$CFG->wwwroot/login/index.php");
41  
-} //if
42  
-
43  
-//confirmation flag to prevent accidental reindexing (indexersplash.php is the correct entry point)
44  
-$sure = strtolower(optional_param('areyousure', '', PARAM_ALPHA));
  39
+/// only administrators can index the moodle installation, because access to all pages is required
45 40
 
46  
-if ($sure != 'yes') {
47  
-    mtrace("<pre>Sorry, you need to confirm indexing via <a href='indexersplash.php'>indexersplash.php</a>"
48  
-          .". (<a href='index.php'>Back to query page</a>).</pre>");
49  
-
50  
-    exit(0);
51  
-} //if
  41
+    require_login();
  42
+    
  43
+    if (empty($CFG->enableglobalsearch)) {
  44
+        error(get_string('globalsearchdisabled', 'search'));
  45
+    }
  46
+    
  47
+    if (!isadmin()) {
  48
+        error(get_string('beadmin', 'search'), "$CFG->wwwroot/login/index.php");
  49
+    } 
  50
+    
  51
+/// confirmation flag to prevent accidental reindexing (indexersplash.php is the correct entry point)
52 52
 
53  
-//check for php5 (lib.php)
54  
-if (!search_check_php5()) {
55  
-    $phpversion = phpversion();
56  
-    mtrace("Sorry, global search requires PHP 5.0.0 or later (currently using version $phpversion)");
57  
-    exit(0);
58  
-} 
  53
+    $sure = strtolower(optional_param('areyousure', '', PARAM_ALPHA));
  54
+    
  55
+    if ($sure != 'yes') {
  56
+        mtrace("<pre>Sorry, you need to confirm indexing via <a href='indexersplash.php'>indexersplash.php</a>"
  57
+              .". (<a href='index.php'>Back to query page</a>).</pre>");
  58
+    
  59
+        exit(0);
  60
+    }
  61
+    
  62
+/// check for php5 (lib.php)
59 63
 
60  
-//php5 found, continue including php5-only files
61  
-//require_once("$CFG->dirroot/search/Zend/Search/Lucene.php");
62  
-require_once("$CFG->dirroot/search/indexlib.php");
  64
+    if (!search_check_php5()) {
  65
+        $phpversion = phpversion();
  66
+        mtrace("Sorry, global search requires PHP 5.0.0 or later (currently using version ".phpversion().")");
  67
+        exit(0);
  68
+    } 
  69
+    
  70
+    //php5 found, continue including php5-only files
  71
+    //require_once("$CFG->dirroot/search/Zend/Search/Lucene.php");
  72
+    require_once("$CFG->dirroot/search/indexlib.php");
  73
+    
  74
+    mtrace('<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8" /></head><body>');
  75
+    mtrace('<pre>Server Time: '.date('r',time())."\n");
  76
+    
  77
+    if (isset($CFG->search_indexer_busy) && $CFG->search_indexer_busy == '1') {
  78
+        //means indexing was not finished previously
  79
+        mtrace("Warning: Indexing was not successfully completed last time, restarting.\n");
  80
+    }
  81
+    
  82
+/// turn on busy flag
63 83
 
64  
-mtrace('<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8" /></head><body>');
65  
-mtrace('<pre>Server Time: '.date('r',time())."\n");
  84
+    set_config('search_indexer_busy', '1');
  85
+    
  86
+    //paths
  87
+    $index_path = SEARCH_INDEX_PATH;
  88
+    $index_db_file = "{$CFG->dirroot}/search/db/$CFG->dbtype.sql";
  89
+    $dbcontrol = new IndexDBControl();
  90
+    
  91
+/// setup directory in data root
  92
+
  93
+    if (!file_exists($index_path)) {
  94
+        mtrace("Data directory ($index_path) does not exist, attempting to create.");
  95
+        if (!mkdir($index_path)) {
  96
+            search_pexit("Error creating data directory at: $index_path. Please correct.");
  97
+        }  else {
  98
+            mtrace("Directory successfully created.");
  99
+        } 
  100
+    } else {
  101
+        mtrace("Using $index_path as data directory.");
  102
+    } 
  103
+    
  104
+    $index = new Zend_Search_Lucene($index_path, true);
  105
+    
  106
+    /*
  107
+    OBSOLETE REGENERATION - DB installs with search block by now
  108
+    if (!$dbcontrol->checkDB()) {
  109
+        search_pexit("Database error. Please check settings/files.");
  110
+    }
  111
+    */
66 112
 
67  
-if (isset($CFG->search_indexer_busy) && $CFG->search_indexer_busy == '1') {
68  
-    //means indexing was not finished previously
69  
-    mtrace("Warning: Indexing was not successfully completed last time, restarting.\n");
70  
-}
  113
+/// New regeneration
71 114
 
72  
-//turn on busy flag
73  
-set_config('search_indexer_busy', '1');
  115
+    mtrace('Deleting old index entries.');
  116
+    delete_records(SEARCH_DATABASE_TABLE);
  117
+    
  118
+/// begin timer
74 119
 
75  
-//paths
76  
-$index_path = SEARCH_INDEX_PATH;
77  
-$index_db_file = "{$CFG->dirroot}/search/db/$CFG->dbtype.sql";
78  
-$dbcontrol = new IndexDBControl();
  120
+    search_stopwatch();
  121
+    mtrace("Starting activity modules\n");
  122
+    
  123
+    //the presence of the required search functions -
  124
+    // * mod_iterator
  125
+    // * mod_get_content_for_index
  126
+    //are the sole basis for including a module in the index at the moment.
  127
+    $searchables = array();
  128
+    
  129
+/// collects modules
79 130
 
80  
-//setup directory in data root
81  
-if (!file_exists($index_path)) {
82  
-    mtrace("Data directory ($index_path) does not exist, attempting to create.");
83  
-    if (!mkdir($index_path)) {
84  
-        search_pexit("Error creating data directory at: $index_path. Please correct.");
85  
-    } 
86  
-    else {
87  
-        mtrace("Directory successfully created.");
88  
-    } 
89  
-} 
90  
-else {
91  
-    mtrace("Using $index_path as data directory.");
92  
-} 
93  
-
94  
-$index = new Zend_Search_Lucene($index_path, true);
95  
-
96  
-/*
97  
-OBSOLETE REGENERATION - DB installs with search block by now
98  
-if (!$dbcontrol->checkDB()) {
99  
-    search_pexit("Database error. Please check settings/files.");
100  
-}
101  
-*/
102  
-// New regeneration
103  
-mtrace('Deleting old index entries.');
104  
-delete_records(SEARCH_DATABASE_TABLE);
105  
-
106  
-//begin timer
107  
-search_stopwatch();
108  
-mtrace("Starting activity modules\n");
109  
-
110  
-//the presence of the required search functions -
111  
-// * mod_iterator
112  
-// * mod_get_content_for_index
113  
-//are the sole basis for including a module in the index at the moment.
114  
-$searchables = array();
115  
-
116  
-// collects modules
117  
-if ($mods = get_records('modules', '', '', '', 'id,name')) {
118  
-    $searchables = array_merge($searchables, $mods);
119  
-}
120  
-mtrace(count($searchables).' modules found.');
121  
-  
122  
-// collects blocks as indexable information may be found in blocks either
123  
-if ($blocks = get_records('block', '', '', '', 'id,name')) {
124  
-    // prepend the "block_" prefix to discriminate document type plugins
125  
-    foreach(array_keys($blocks) as $aBlockId){
126  
-        $blocks[$aBlockId]->name = 'block_'.$blocks[$aBlockId]->name;
  131
+    if ($mods = get_records('modules', '', '', '', 'id,name')) {
  132
+        $searchables = array_merge($searchables, $mods);
127 133
     }
128  
-    $searchables = array_merge($searchables, $blocks);
129  
-    mtrace(count($blocks).' blocks found.');
130  
-}
131  
-  
132  
-//add virtual modules onto the back of the array
133  
-$searchables = array_merge($searchables, search_get_additional_modules());
134  
-if ($searchables){
135  
-    foreach ($searchables as $mod) {
136  
-        $class_file = $CFG->dirroot.'/search/documents/'.$mod->name.'_document.php';
137  
-     
138  
-        if (file_exists($class_file)) {
139  
-            include_once($class_file);
140  
-
141  
-            //build function names
142  
-            $iter_function = $mod->name.'_iterator';
143  
-            $index_function = $mod->name.'_get_content_for_index';
144  
-            $counter = 0;
145  
-            if (function_exists($index_function) && function_exists($iter_function)) {
146  
-                mtrace("Processing module function $index_function ...");
147  
-                $sources = $iter_function();
148  
-                if ($sources){
149  
-                    foreach ($sources as $i) {
150  
-                        $documents = $index_function($i);
151  
-              
152  
-                        //begin transaction
153  
-                        if ($documents){
154  
-                            foreach($documents as $document) {
155  
-                                $counter++;
156  
-                                
157  
-                                //object to insert into db
158  
-                                $dbid = $dbcontrol->addDocument($document);
159  
-                                
160  
-                                //synchronise db with index
161  
-                                $document->addField(Zend_Search_Lucene_Field::Keyword('dbid', $dbid));
162  
-                                
163  
-                                //add document to index
164  
-                                $index->addDocument($document);
165  
-                                
166  
-                                //commit every x new documents, and print a status message
167  
-                                if (($counter % 2000) == 0) {
168  
-                                    $index->commit();
169  
-                                    mtrace(".. $counter");
170  
-                                } 
  134
+    mtrace(count($searchables).' modules found.');
  135
+      
  136
+    // collects blocks as indexable information may be found in blocks either
  137
+    if ($blocks = get_records('block', '', '', '', 'id,name')) {
  138
+        // prepend the "block_" prefix to discriminate document type plugins
  139
+        foreach(array_keys($blocks) as $aBlockId){
  140
+            $blocks[$aBlockId]->name = 'block_'.$blocks[$aBlockId]->name;
  141
+        }
  142
+        $searchables = array_merge($searchables, $blocks);
  143
+        mtrace(count($blocks).' blocks found.');
  144
+    }
  145
+      
  146
+/// add virtual modules onto the back of the array
  147
+
  148
+    $searchables = array_merge($searchables, search_get_additional_modules());
  149
+    if ($searchables){
  150
+        foreach ($searchables as $mod) {
  151
+            $class_file = $CFG->dirroot.'/search/documents/'.$mod->name.'_document.php';
  152
+         
  153
+            if (file_exists($class_file)) {
  154
+                include_once($class_file);
  155
+    
  156
+                //build function names
  157
+                $iter_function = $mod->name.'_iterator';
  158
+                $index_function = $mod->name.'_get_content_for_index';
  159
+                $counter = 0;
  160
+                if (function_exists($index_function) && function_exists($iter_function)) {
  161
+                    mtrace("Processing module function $index_function ...");
  162
+                    $sources = $iter_function();
  163
+                    if ($sources){
  164
+                        foreach ($sources as $i) {
  165
+                            $documents = $index_function($i);
  166
+                  
  167
+                            //begin transaction
  168
+                            if ($documents){
  169
+                                foreach($documents as $document) {
  170
+                                    $counter++;
  171
+                                    
  172
+                                    //object to insert into db
  173
+                                    $dbid = $dbcontrol->addDocument($document);
  174
+                                    
  175
+                                    //synchronise db with index
  176
+                                    $document->addField(Zend_Search_Lucene_Field::Keyword('dbid', $dbid));
  177
+                                    
  178
+                                    //add document to index
  179
+                                    $index->addDocument($document);
  180
+                                    
  181
+                                    //commit every x new documents, and print a status message
  182
+                                    if (($counter % 2000) == 0) {
  183
+                                        $index->commit();
  184
+                                        mtrace(".. $counter");
  185
+                                    } 
  186
+                                }
171 187
                             }
  188
+                            //end transaction
172 189
                         }
173  
-                        //end transaction
174 190
                     }
  191
+            
  192
+                    //commit left over documents, and finish up
  193
+                    $index->commit();
  194
+          
  195
+                    mtrace("-- $counter documents indexed");
  196
+                    mtrace("done.\n");
175 197
                 }
176  
-        
177  
-                //commit left over documents, and finish up
178  
-                $index->commit();
179  
-      
180  
-                mtrace("-- $counter documents indexed");
181  
-                mtrace("done.\n");
182 198
             }
183 199
         }
184 200
     }
185  
-}
186  
-  
187  
-//finished modules
188  
-mtrace('Finished activity modules');
189  
-search_stopwatch();
  201
+      
  202
+/// finished modules
  203
+
  204
+    mtrace('Finished activity modules');
  205
+    search_stopwatch();
  206
+        
  207
+    mtrace(".<br/><a href='index.php'>Back to query page</a>.");
  208
+    mtrace('</pre>');
190 209
     
191  
-mtrace(".<br/><a href='index.php'>Back to query page</a>.");
192  
-mtrace('</pre>');
  210
+/// finished, turn busy flag off
193 211
 
194  
-//finished, turn busy flag off
195  
-set_config('search_indexer_busy', '0');
  212
+    set_config('search_indexer_busy', '0');
  213
+    
  214
+/// mark the time we last updated
196 215
 
197  
-//mark the time we last updated
198  
-set_config('search_indexer_run_date', time());
  216
+    set_config('search_indexer_run_date', time());
  217
+    
  218
+/// and the index size
199 219
 
200  
-//and the index size
201  
-set_config('search_index_size', (int)$index->count());
  220
+    set_config('search_index_size', (int)$index->count());
202 221
 
203  
-?>
  222
+?>
118  search/indexersplash.php
... ...
@@ -1,66 +1,80 @@
1 1
 <?php
2 2
 /**
3 3
 * Global Search Engine for Moodle
4  
-* Michael Champanis (mchampan) [cynnical@gmail.com]
5  
-* review 1.8+ : Valery Fremaux [valery.fremaux@club-internet.fr] 
6  
-* 2007/08/02
  4
+*
  5
+* @package search
  6
+* @category core
  7
+* @subpackage search_engine
  8
+* @author Michael Champanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
  9
+* @date 2008/03/31
  10
+* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
7 11
 *
8 12
 * This file serves as a splash-screen (entry page) to the indexer script -
9 13
 * it is in place to prevent accidental reindexing which can lead to a loss
10 14
 * of time, amongst other things.
11  
-**/
  15
+*/
12 16
 
  17
+/**
  18
+* includes and requires
  19
+*/
13 20
 require_once('../config.php');
14 21
 require_once("$CFG->dirroot/search/lib.php");
15 22
 
16  
-require_login();
17  
-
18  
-if (empty($CFG->enableglobalsearch)) {
19  
-    print_error('globalsearchdisabled', 'search');
20  
-}
21  
-
22  
-if (!isadmin()) {
23  
-    print_error('beadmin', 'search', "$CFG->wwwroot/login/index.php");
24  
-} 
25  
-
26  
-//check for php5 (lib.php)
27  
-if (!search_check_php5()) {
28  
-    $phpversion = phpversion();
29  
-    mtrace("Sorry, global search requires PHP 5.0.0 or later (currently using version $phpversion)");
30  
-    exit(0);
31  
-}
  23
+/// check global search is enabled 
32 24
 
33  
-require_once("$CFG->dirroot/search/indexlib.php");
34  
-$indexinfo = new IndexInfo();
  25
+    require_login();
  26
+    
  27
+    if (empty($CFG->enableglobalsearch)) {
  28
+        error(get_string('globalsearchdisabled', 'search'));
  29
+    }
  30
+    
  31
+    if (!isadmin()) {
  32
+        error(get_string('beadmin', 'search'), "$CFG->wwwroot/login/index.php");
  33
+    } 
  34
+    
  35
+/// check for php5 (lib.php)
35 36
 
36  
-if ($indexinfo->valid()) {
37  
-    $strsearch = get_string('search', 'search');
38  
-    $strquery  = get_string('stats');
  37
+    if (!search_check_php5()) {
  38
+        $phpversion = phpversion();
  39
+        mtrace("Sorry, global search requires PHP 5.0.0 or later (currently using version ".phpversion().")");
  40
+        exit(0);
  41
+    }
  42
+    
  43
+    require_once("$CFG->dirroot/search/indexlib.php");
  44
+    $indexinfo = new IndexInfo();
39 45
     
40  
-    $navlinks[] = array('name' => $strsearch, 'link' => "index.php", 'type' => 'misc');
41  
-    $navlinks[] = array('name' => $strquery, 'link' => "stats.php", 'type' => 'misc');
42  
-    $navlinks[] = array('name' => get_string('runindexer','search'), 'link' => null, 'type' => 'misc');
43  
-    $navigation = build_navigation($navlinks);
44  
-    $site = get_site();
45  
-    print_header("$strsearch", "$site->fullname" , $navigation, "", "", true, "&nbsp;", navmenu($site));
46  
- 
47  
-    mtrace("<pre>The data directory ($indexinfo->path) contains $indexinfo->filecount files, and\n"
48  
-          ."there are ".$indexinfo->dbcount." records in the <em>block_search_documents</em> table.\n"
49  
-          ."\n"
50  
-          ."This indicates that you have already succesfully indexed this site. Follow the link\n"
51  
-          ."if you are sure that you want to continue indexing - this will replace any existing\n"
52  
-          ."index data (no Moodle data is affected).\n"
53  
-          ."\n"
54  
-          ."You are encouraged to use the 'Test indexing' script before continuing onto\n"
55  
-          ."indexing - this will check if the modules are set up correctly. Please correct\n"
56  
-          ."any errors before proceeding.\n"
57  
-          ."\n"
58  
-          ."<a href='tests/index.php'>Test indexing</a> or "
59  
-          ."<a href='indexer.php?areyousure=yes'>Continue indexing</a> or <a href='index.php'>Back to query page</a>."
60  
-          ."</pre>");
61  
-    print_footer();
62  
-} 
63  
-else {
64  
-    header('Location: indexer.php?areyousure=yes');
65  
-}
66  
-?>
  46
+    if ($indexinfo->valid()) {
  47
+        $strsearch = get_string('search', 'search');
  48
+        $strquery  = get_string('stats');
  49
+        
  50
+        $navlinks[] = array('name' => $strsearch, 'link' => "index.php", 'type' => 'misc');
  51
+        $navlinks[] = array('name' => $strquery, 'link' => "stats.php", 'type' => 'misc');
  52
+        $navlinks[] = array('name' => get_string('runindexer','search'), 'link' => null, 'type' => 'misc');
  53
+        if ($CFG->version <= 2007021541){ // 1.8 branch stable timestamp
  54
+            $navigation = '';
  55
+        } else {
  56
+            $navigation = build_navigation($navlinks);
  57
+        }
  58
+        $site = get_site();
  59
+        print_header("$strsearch", "$site->fullname" , $navigation, "", "", true, "&nbsp;", navmenu($site));
  60
+     
  61
+        mtrace("<pre>The data directory ($indexinfo->path) contains $indexinfo->filecount files, and\n"
  62
+              ."there are ".$indexinfo->dbcount." records in the <em>block_search_documents</em> table.\n"
  63
+              ."\n"
  64
+              ."This indicates that you have already succesfully indexed this site. Follow the link\n"
  65
+              ."if you are sure that you want to continue indexing - this will replace any existing\n"
  66
+              ."index data (no Moodle data is affected).\n"
  67
+              ."\n"
  68
+              ."You are encouraged to use the 'Test indexing' script before continuing onto\n"
  69
+              ."indexing - this will check if the modules are set up correctly. Please correct\n"
  70
+              ."any errors before proceeding.\n"
  71
+              ."\n"
  72
+              ."<a href='tests/index.php'>Test indexing</a> or "
  73
+              ."<a href='indexer.php?areyousure=yes'>Continue indexing</a> or <a href='index.php'>Back to query page</a>."
  74
+              ."</pre>");
  75
+        print_footer();
  76
+    } 
  77
+    else {
  78
+        header('Location: indexer.php?areyousure=yes');
  79
+    }
  80
+?>
71  search/indexlib.php
... ...
@@ -1,20 +1,32 @@
1 1
 <?php
2  
-/* 
3  
-* Author: Michael Champanis
  2
+/** 
  3
+* Global Search Engine for Moodle
4 4
 *
5  
-* Reviewed by: Valery Fremaux (2007)
  5
+* @package search
  6
+* @category core
  7
+* @subpackage search_engine
  8
+* @author Michael Champanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
  9
+* @date 2008/03/31
  10
+* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
6 11
 * 
7 12
 * Index info class
8 13
 *
9 14
 * Used to retrieve information about an index.
10 15
 * Has methods to check for valid database and data directory,
11 16
 * and the index itself.
12  
-**/
  17
+*/
13 18
 
  19
+/**
  20
+* includes and requires
  21
+*/
14 22
 require_once("$CFG->dirroot/search/lib.php");
15 23
 require_once("$CFG->dirroot/search/Zend/Search/Lucene.php");
16 24
 
  25
+/**
  26
+* main class for searchable information in the Lucene index 
  27
+*/
17 28
 class IndexInfo {
  29
+
18 30
     private $path,        //index data directory
19 31
             $size,        //size of directory (i.e. the whole index)
20 32
             $filecount,   //number of files
@@ -35,7 +47,7 @@ public function __construct($path = SEARCH_INDEX_PATH) {
35 47
             $validindex = true;
36 48
         } catch(Exception $e) {
37 49
             $validindex = false;
38  
-        } //catch
  50
+        } 
39 51
         
40 52
         //retrieve file system info about the index if it is valid
41 53
         if ($validindex) {
@@ -73,8 +85,7 @@ public function __construct($path = SEARCH_INDEX_PATH) {
73 85
                 $c = count_records(SEARCH_DATABASE_TABLE, 'doctype', $type);
74 86
                 $this->types[$type] = (int)$c;
75 87
             }
76  
-        } 
77  
-        else {
  88
+        } else {
78 89
             $this->dbcount = 0;
79 90
             $this->types = array();
80 91
         }
@@ -82,23 +93,21 @@ public function __construct($path = SEARCH_INDEX_PATH) {
82 93
         //check if the busy flag is set
83 94
         if (isset($CFG->search_indexer_busy) && $CFG->search_indexer_busy == '1') {
84 95
             $this->complete = false;
85  
-        } 
86  
-        else {
  96
+        } else {
87 97
             $this->complete = true;
88 98
         }
89 99
         
90 100
         //get the last run date for the indexer
91 101
         if ($this->valid() && $CFG->search_indexer_run_date) {
92 102
             $this->time = $CFG->search_indexer_run_date;
93  
-        } 
94  
-        else {
  103
+        } else {
95 104
           $this->time = 0;
96 105
         }
97  
-    } //__construct
  106
+    } 
98 107
     
99 108
     /**
100 109
     * returns false on error, and the error message via referenced variable $err
101  
-    *
  110
+    * @param array $err array of errors
102 111
     */
103 112
     public function valid(&$err = null) {
104 113
         $err = array();
@@ -120,7 +129,7 @@ public function valid(&$err = null) {
120 129
         }
121 130
         
122 131
         return $ret;
123  
-    } //valid
  132
+    }
124 133
     
125 134
     /**
126 135
     * is the index dir valid
@@ -129,11 +138,10 @@ public function valid(&$err = null) {
129 138
     public function is_valid_dir() {
130 139
         if ($this->filecount > 0) {
131 140
             return true;
132  
-        } 
133  
-        else {
  141
+        } else {
134 142
             return false;
135 143
         }
136  
-    } //is_valid_dir
  144
+    }
137 145
     
138 146
     /**
139 147
     * is the db table valid
@@ -142,34 +150,34 @@ public function is_valid_dir() {
142 150
     public function is_valid_db() {
143 151
         if ($this->dbcount > 0) {
144 152
             return true;
145  
-        } 
146  
-        else {
  153
+        } else {
147 154
             return false;
148 155
         }