global search MDL-24892 fixes for updating the search index.
authorAparup Banerjee <nebgor@gmail.com>
Fri, 29 Oct 2010 09:41:42 +0000 (09:41 +0000)
committerAparup Banerjee <nebgor@gmail.com>
Fri, 29 Oct 2010 09:41:42 +0000 (09:41 +0000)
search/documents/assignment_document.php
search/documents/data_document.php
search/documents/wiki_document.php
search/indexer.php
search/update.php

index c8186db..9b5c365 100644 (file)
@@ -236,8 +236,8 @@ function assignment_single_document($id, $itemtype) {
             return null;
         }
     } elseif ($itemtype == 'submission') {
-        if ($submission = $DB->get_record('assignment_submissions', array('id' => $id))){
-            if (!$assignment = $DB->get_record('assignment', array('id' => $submission->assignment))){
+        if ($submission = $DB->get_record('assignment_submissions', array('id' => $id))) {
+            if (!$assignment = $DB->get_record('assignment', array('id' => $submission->assignment))) {
                 return null;
             }
         } else {
index 514fc0b..499a922 100644 (file)
@@ -274,7 +274,7 @@ function data_single_document($id, $itemtype) {
                 $content = @$content.' '.$aField;
             }
             unset($recordMetaData);
-            $recordMetaData = $DB->get_record('data_records', array('id' => $aRecordId));
+            $recordMetaData = $DB->get_record('data_records', array('id' => $id));
             $recordMetaData->title = $first;
             $recordMetaData->content = $content;
             return new DataSearchDocument(get_object_vars($recordMetaData), $record_course, $context->id);
index 96d84e3..486c0b3 100644 (file)
@@ -220,7 +220,7 @@ function wiki_single_document($id, $itemtype) {
     global $DB;
 
     $page = $DB->get_record('wiki_pages', array('id' => $id));
-    $entry = $DB->get_record('wiki_entries', array('id' => $page->wiki));
+    $entry = $DB->get_record('wiki_entries', array('id' => $page->subwikiid));
     $coursemodule = $DB->get_field('modules', 'id', array('name' => 'wiki'));
     $cm = $DB->get_record('course_modules', array('course' => $entry->course, 'module' => $coursemodule, 'instance' => $entry->wikiid));
     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
@@ -241,7 +241,7 @@ function wiki_delete($info, $itemtype) {
 //returns the var names needed to build a sql query for addition/deletions
 function wiki_db_names() {
     //[primary id], [table name], [time created field name], [time modified field name], [docsubtype], [additional where conditions for sql]
-    return array(array('id', 'wiki_pages', 'timecreated', 'lastmodified', 'standard'));
+    return array(array('id', 'wiki_pages', 'timecreated', 'timemodified', 'standard'));
 }
 
 /**
index 3eb9a08..53c8b4f 100644 (file)
@@ -210,7 +210,14 @@ require_once($CFG->dirroot.'/search/lib.php');
 /// mark the time we last updated
 
     set_config('search_indexer_run_date', time());
-    
+
+    //mark last update times for mods to now.
+    if ($mods = search_collect_searchables(false, true)){
+        foreach($mods as $mod) {
+            $indexdatestring = 'search_indexer_update_date_'.$mod->name;
+            set_config($indexdatestring, time());
+        }
+    }
 /// and the index size
 
     set_config('search_index_size', (int)$index->count());
index c00229d..c11f9c3 100644 (file)
@@ -56,8 +56,7 @@
     }
     $dbcontrol = new IndexDBControl();
     $update_count = 0;
-    $indexdate = 0 + @$CFG->search_indexer_update_date;
-    $startupdatedate = time();
+    $mainstartupdatedate = time();
 
 /// indexing changed resources
     
     if ($mods = search_collect_searchables(false, true)){
         
         foreach ($mods as $mod) {
+            $indexdate = 0;
+            $indexdatestring = 'search_indexer_update_date_'.$mod->name;
+            $startupdatedate = time();
+            if (isset($CFG->$indexdatestring)) {
+                $indexdate = $CFG->$indexdatestring;
+            }
+
             $class_file = $CFG->dirroot.'/search/documents/'.$mod->name.'_document.php';
             $get_document_function = $mod->name.'_single_document';
             $delete_function = $mod->name.'_delete';
@@ -81,8 +87,7 @@
                     $valuesArray = $db_names_function();
                     if ($valuesArray){
                         foreach($valuesArray as $values){
-                        
-                            $where = (!empty($values[5])) ? 'AND ('.$values[5].')' : '';
+                            $where = (isset($values[5]) and $values[5]!='') ? 'AND ('.$values[5].')' : '';
                             $itemtypes = ($values[4] != '*' && $values[4] != 'any') ? " AND itemtype = '{$values[4]}' " : '' ;
     
                             //TODO: check 'in' syntax with other RDBMS' (add and update.php as well)
                                     doctype = ?
                                     $itemtypes
                             ";
-                            $docIds = $DB->get_records_sql_menu($query, array($values[1]));
-                            
+                            $docIds = $DB->get_records_sql_menu($query, array($mod->name));
                             if (!empty($docIds)){
                                 list($usql, $params) = $DB->get_in_or_equal(array_keys($docIds));
                                 $query = "
                                 $updates[] = $delete_function($record->docid, $docIds[$record->docid]);
                             } 
                         }
-                        
+
                         foreach ($updates as $update) {
                             ++$update_count;
                             
                             //delete old document
+                            // change from default text only search to include numerals for this search.
+                            Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive());
                             $doc = $index->find("+docid:{$update->id} +doctype:{$mod->name} +itemtype:{$update->itemtype}");
                             
                             //get the record, should only be one
                             
                             //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)");
                     else{
                         mtrace("No types to update.\n");
                     }
+                    //commit changes
+                    $index->commit();
+
+                    //update index date
+                    set_config($indexdatestring, $startupdatedate);
+
                     mtrace("Finished $mod->name.\n");
                 } 
             } 
     
     //commit changes
     $index->commit();
-    
+
     //update index date
-    set_config('search_indexer_update_date', $startupdatedate);
-    
+    set_config('search_indexer_update_date', $mainstartupdatedate);
+
     mtrace("Finished $update_count updates");
 
 ?>
\ No newline at end of file