++$update_count;
                        //delete old document
                        $doc = $index->find("+docid:{$update->id} +doctype:{$mod->name} +itemtype:{$update->itemtype}");
                        //get the record, should only be one
                        foreach ($doc as $thisdoc) {
                            mtrace("  Delete: {$thisdoc->title} (database id = {$thisdoc->dbid}, index id = {$thisdoc->id}, moodle instance id = {$thisdoc->docid})");
                            $dbcontrol->delDocument($thisdoc);
                            $index->delete($thisdoc->id);
                        }
                        //add new modified document back into index
                        if (!($add = $get_document_function($update->id, $update->itemtype))) {
                            // ignore on errors
                            continue;
                        }
                        //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})");
                        $index->addDocument($add);
                    }
                } else {
                    mtrace("No types to update.\n");
                }
                mtrace("Finished {$mod->name}.\n");
            }
        }
    }
}
//commit changes
$index->commit();
Beispiel #2
0
 if (function_exists($index_function) && function_exists($iter_function)) {
     mtrace("Processing module function {$index_function} ...");
     $sources = $iter_function();
     if ($sources) {
         foreach ($sources as $i) {
             $documents = $index_function($i);
             //begin transaction
             if ($documents) {
                 foreach ($documents as $document) {
                     $counter++;
                     // temporary fix until MDL-24822 is resolved
                     if ($document->group_id == -1 and $mod->name = 'forum') {
                         $document->group_id = 0;
                     }
                     //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