Exemplo n.º 1
0
 /**
  * Get the queue of documents for indexing
  * Refactored from indexDocuments()
  */
 public function getDocumentsQueue($max = null)
 {
     global $default;
     // Cleanup the queue
     Indexer::clearoutDeleted();
     $date = date('Y-m-d H:i:s');
     // identify the indexers that must run
     // mysql specific limit!
     $sql = "SELECT\n        \t\t\tiff.document_id, mt.filetypes, mt.mimetypes, me.name as extractor, iff.what\n\t\t\t\tFROM\n\t\t\t\t\tindex_files iff\n\t\t\t\t\tINNER JOIN documents d ON iff.document_id=d.id\n\t\t\t\t\tINNER JOIN document_metadata_version dmv ON d.metadata_version_id=dmv.id\n\t\t\t\t\tINNER JOIN document_content_version dcv ON dmv.content_version_id=dcv.id\n\t\t\t\t\tINNER JOIN mime_types mt ON dcv.mime_id=mt.id\n\t\t\t\t\tLEFT JOIN mime_extractors me ON mt.extractor_id=me.id\n \t\t\t\tWHERE\n \t\t\t\t\t(iff.processdate IS NULL or iff.processdate < date_sub('{$date}', interval 1 day)) AND dmv.status_id=1\n\t\t\t\tORDER BY indexdate\n \t\t\t\t\tLIMIT {$max}";
     $result = DBUtil::getResultArray($sql);
     if (PEAR::isError($result)) {
         //unlink($indexLockFile);
         if ($this->debug) {
             $default->log->error('indexDocuments: stopping - db error');
         }
         return;
     }
     KTUtil::setSystemSetting('luceneIndexingDate', time());
     // bail if no work to do
     if (count($result) == 0) {
         //unlink($indexLockFile);
         if ($this->debug) {
             $default->log->debug('indexDocuments: stopping - no work to be done');
         }
         return;
     }
     // identify any documents that need indexing and mark them
     // so they are not taken in a followup run
     $ids = array();
     foreach ($result as $docinfo) {
         $ids[] = $docinfo['document_id'];
     }
     // mark the documents as being processed
     $ids = implode(',', $ids);
     $sql = "UPDATE index_files SET processdate='{$date}' WHERE document_id in ({$ids})";
     DBUtil::runQuery($sql);
     return $result;
 }