Exemplo n.º 1
0
 /**
  * Starts an Opus console.     
  */
 public function run()
 {
     global $argv, $argc;
     if (true === in_array('--help', $argv) || true === in_array('-h', $argv)) {
         $this->printHelpMessage($argv);
         exit;
     }
     $this->evaluateArguments($argc, $argv);
     $this->forceSyncMode();
     $docIds = Opus_Document::getAllPublishedIds($this->start, $this->end);
     $indexer = new Opus_SolrSearch_Index_Indexer($this->deleteAllDocs);
     //$indexer = new Opus_SolrSearch_Index_Indexer();
     echo date('Y-m-d H:i:s') . " Start indexing of " . count($docIds) . " documents.\n";
     $numOfDocs = 0;
     $runtime = microtime(true);
     foreach ($docIds as $docId) {
         $time_start = microtime(true);
         $doc = new Opus_Document($docId);
         // dirty hack: disable implicit reindexing of documents in case of cache misses
         $doc->unregisterPlugin('Opus_Document_Plugin_Index');
         $indexer->addDocumentToEntryIndex($doc);
         $time_delta = microtime(true) - $time_start;
         if ($time_delta > 30) {
             echo date('Y-m-d H:i:s') . " WARNING: Indexing document {$docId} took {$time_delta} seconds.\n";
         }
         $numOfDocs++;
         if ($numOfDocs % 10 == 0) {
             $mem_now = round(memory_get_usage() / 1024 / 1024);
             $mem_peak = round(memory_get_peak_usage() / 1024 / 1024);
             $delta_t = microtime(true) - $runtime;
             $doc_per_second = round($delta_t) == 0 ? 'inf' : round($numOfDocs / $delta_t, 2);
             $seconds_per_doc = round($delta_t / $numOfDocs, 2);
             echo date('Y-m-d H:i:s') . " Stats after {$numOfDocs} documents -- memory {$mem_now} MB, peak memory {$mem_peak} (MB), {$doc_per_second} docs/second, {$seconds_per_doc} seconds/doc\n";
         }
     }
     $runtime = microtime(true) - $runtime;
     echo "\n" . date('Y-m-d H:i:s') . " Finished indexing.\n";
     $indexer->commit();
     echo "\n\nErrors appeared in " . $indexer->getErrorFileCount() . " of " . $indexer->getTotalFileCount() . " files." . " Details were written to opus-console.log";
     $this->resetMode();
     return $runtime;
 }