add support for indexing folders

This commit is contained in:
Uwe Steinmann 2020-12-12 16:29:56 +01:00
parent e36a41eeae
commit efed9f2b9c
4 changed files with 136 additions and 37 deletions

View File

@ -914,19 +914,28 @@ switch($command) {
break; /* }}} */
case 'indexdocument': /* {{{ */
case 'indexfolder': /* {{{ */
if($user && $user->isAdmin()) {
if($fulltextservice) {
$document = $dms->getDocument($_REQUEST['id']);
if($document) {
if($command == 'indexdocument') {
$hook = 'indexDocument';
$object = $dms->getDocument($_REQUEST['id']);
$prefix = 'D';
} else {
$hook = 'indexFolder';
$object = $dms->getFolder($_REQUEST['id']);
$prefix = 'F';
}
if($object) {
if($index = $fulltextservice->Indexer()) {
$idoc = $fulltextservice->IndexedDocument($document, true);
$idoc = $fulltextservice->IndexedDocument($object, true);
$error = $idoc->getErrorMsg();
if(!$error) {
$ires = null;
if(isset($GLOBALS['SEEDDMS_HOOKS']['indexDocument'])) {
foreach($GLOBALS['SEEDDMS_HOOKS']['indexDocument'] as $hookObj) {
if (method_exists($hookObj, 'preIndexDocument')) {
$ires = $hookObj->preIndexDocument(null, $document, $idoc);
if(isset($GLOBALS['SEEDDMS_HOOKS'][$hook])) {
foreach($GLOBALS['SEEDDMS_HOOKS'][$hook] as $hookObj) {
if (method_exists($hookObj, 'pre'.ucfirst($hook))) {
$ires = $hookObj->preIndexDocument(null, $object, $idoc);
}
}
}
@ -934,17 +943,17 @@ switch($command) {
$ires = $index->addDocument($idoc);
header('Content-Type: application/json');
if(false === $ires) {
echo json_encode(array('success'=>false, 'message'=>getMLText('error_document_indexed'), 'data'=>$document->getID()));
echo json_encode(array('success'=>false, 'message'=>getMLText('error_document_indexed'), 'data'=>$prefix.$object->getID()));
} else {
echo json_encode(array('success'=>true, 'message'=>getMLText('splash_document_indexed'), 'data'=>$document->getID(), 'cmd'=>$idoc->getCmd()));
echo json_encode(array('success'=>true, 'message'=>getMLText('splash_document_indexed'), 'data'=>$prefix.$object->getID(), 'cmd'=>$idoc->getCmd()));
}
} else {
header('Content-Type: application/json');
echo json_encode(array('success'=>false, 'message'=>$error, 'data'=>$document->getID(), 'mimetype'=>$idoc->getMimeType(), 'cmd'=>$idoc->getCmd()));
echo json_encode(array('success'=>false, 'message'=>$error, 'data'=>$object->getID(), 'mimetype'=>$idoc->getMimeType(), 'cmd'=>$idoc->getCmd()));
}
} else {
header('Content-Type: application/json');
echo json_encode(array('success'=>false, 'message'=>getMLText('error_occured'), 'data'=>$document->getID()));
echo json_encode(array('success'=>false, 'message'=>getMLText('error_occured'), 'data'=>$prefix.$object->getID()));
}
} else {
header('Content-Type: application/json');

View File

@ -195,22 +195,31 @@ if(isset($_GET["fullsearch"]) && $_GET["fullsearch"] && $settings->_enableFullSe
} else {
$entries = array();
$facets = $searchresult['facets'];
$dcount = $searchresult['count']; //0;
$dcount = 0;
$fcount = 0;
if($searchresult) {
foreach($searchresult['hits'] as $hit) {
if($tmp = $dms->getDocument($hit['document_id'])) {
if($tmp->getAccessMode($user) >= M_READ) {
$tmp->verifyLastestContentExpriry();
$entries[] = $tmp;
// $dcount++;
if($hit['document_id'][0] == 'D') {
if($tmp = $dms->getDocument(substr($hit['document_id'], 1))) {
// if($tmp->getAccessMode($user) >= M_READ) {
$tmp->verifyLastestContentExpriry();
$entries[] = $tmp;
$dcount++;
// }
}
} elseif($hit['document_id'][0] == 'F') {
if($tmp = $dms->getFolder(substr($hit['document_id'], 1))) {
// if($tmp->getAccessMode($user) >= M_READ) {
$entries[] = $tmp;
$fcount++;
// }
}
}
}
}
if($pageNumber != 'all' && $dcount > $limit) {
$totalPages = (int) ($dcount/$limit);
if($dcount%$limit)
if($pageNumber != 'all' && $searchresult['count'] > $limit) {
$totalPages = (int) ($searchresult['count']/$limit);
if($searchresult['count']%$limit)
$totalPages++;
// if($limit > 0)
// $entries = array_slice($entries, ($pageNumber-1)*$limit, $limit);

View File

@ -59,19 +59,65 @@ include($myincpath."/inc/inc.Init.php");
include($myincpath."/inc/inc.Extension.php");
include($myincpath."/inc/inc.DBInit.php");
function tree($dms, $fulltextservice, $folder, $indent='') { /* {{{ */
function tree($dms, $fulltextservice, $folder, $indent='', $numdocs) { /* {{{ */
global $settings, $themes;
echo $themes->black($indent."D ".$folder->getName()).PHP_EOL;
$subfolders = $folder->getSubFolders();
foreach($subfolders as $subfolder) {
tree($dms, $fulltextservice, $subfolder, $indent.' ');
}
$documents = $folder->getDocuments();
$index = $fulltextservice->Indexer();
$lucenesearch = $fulltextservice->Search();
// echo $themes->black($indent."D ".$folder->getName()).PHP_EOL;
echo $themes->black($indent."D ".$folder->getId().":".$folder->getName()." ");
if(($numdocs == 0) || !($hit = $lucenesearch->getFolder($folder->getId()))) {
try {
$idoc = $fulltextservice->IndexedDocument($folder, true);
if(isset($GLOBALS['SEEDDMS_HOOKS']['indexFolder'])) {
foreach($GLOBALS['SEEDDMS_HOOKS']['indexFolder'] as $hookObj) {
if (method_exists($hookObj, 'preIndexFolder')) {
$hookObj->preIndexDocument(null, $folder, $idoc);
}
}
}
$index->addDocument($idoc);
echo $themes->green(" (Folder added)").PHP_EOL;
} catch(Exception $e) {
echo $themes->error(" (Timeout)").PHP_EOL;
}
} else {
try {
$created = (int) $hit->getDocument()->getFieldValue('created');
} catch (Exception $e) {
$created = 0;
}
if($created >= $folder->getDate()) {
echo $themes->italic(" (Folder unchanged)").PHP_EOL;
} else {
$index->delete($hit->id);
try {
$idoc = $fulltextservice->IndexedDocument($folder, true);
if(isset($GLOBALS['SEEDDMS_HOOKS']['indexDocument'])) {
foreach($GLOBALS['SEEDDMS_HOOKS']['indexDocument'] as $hookObj) {
if (method_exists($hookObj, 'preIndexDocument')) {
$hookObj->preIndexDocument(null, $folder, $idoc);
}
}
}
$index->addDocument($idoc);
echo $themes->green(" (Folder updated)").PHP_EOL;
} catch(Exception $e) {
echo $themes->error(" (Timeout)").PHP_EOL;
}
}
}
$subfolders = $folder->getSubFolders();
foreach($subfolders as $subfolder) {
tree($dms, $fulltextservice, $subfolder, $indent.' ', $numdocs);
}
$documents = $folder->getDocuments();
foreach($documents as $document) {
echo $themes->black($indent." ".$document->getId().":".$document->getName()." ");
if(!($hit = $lucenesearch->getDocument($document->getId()))) {
if(($numdocs == 0) || !($hit = $lucenesearch->getDocument($document->getId()))) {
try {
$idoc = $fulltextservice->IndexedDocument($document, true);
if(isset($GLOBALS['SEEDDMS_HOOKS']['indexDocument'])) {
@ -124,8 +170,12 @@ if(!$index) {
exit(1);
}
$numdocs = $fulltextservice->Indexer()->count();
$folder = $dms->getFolder($settings->_rootFolderID);
tree($dms, $fulltextservice, $folder);
/* if numdocs is 0, then there is no need to check if a document/folder is already
* indexed. That speeds up the indexing.
*/
tree($dms, $fulltextservice, $folder,'', $numdocs);
$index->commit();
$index->optimize();

View File

@ -32,18 +32,43 @@ class SeedDMS_View_Indexer_Process_Folder { /* {{{ */
public function __construct($fulltextservice, $forceupdate) { /* {{{ */
$this->fulltextservice = $fulltextservice;
$this->forceupdate = $forceupdate;
$this->numdocs = $this->fulltextservice->Indexer()->count();
} /* }}} */
public function process($folder) { /* {{{ */
$lucenesearch = $this->fulltextservice->Search();
echo "<div class=\"folder\">".$folder->getId().":".htmlspecialchars($folder->getFolderPathPlain());
/* If the document wasn't indexed before then just add it */
if(($this->numdocs == 0) || !($hit = $lucenesearch->getFolder($folder->getId()))) {
echo " <span id=\"status_F".$folder->getID()."\" class=\"indexme indexstatus\" data-docid=\"F".$folder->getID()."\">".getMLText('index_waiting')."</span>";
} else {
/* Check if the attribute created is set or has a value older
* than the lastet content. Documents without such an attribute
* where added when a new document was added to the dms. In such
* a case the document content wasn't indexed.
*/
try {
$created = (int) $hit->getDocument()->getFieldValue('created');
} catch (/* Zend_Search_Lucene_ */Exception $e) {
$created = 0;
}
if($created >= $folder->getDate() && !$this->forceupdate) {
echo "<span id=\"status_F".$folder->getID()."\" class=\"indexstatus\" data-docid=\"F".$folder->getID()."\">".getMLText('index_document_unchanged')."</span>";
} else {
$this->fulltextservice->Indexer()->delete($hit->id);
echo " <span id=\"status_F".$folder->getID()."\" class=\"indexme indexstatus\" data-docid=\"F".$folder->getID()."\">".getMLText('index_waiting')."</span>";
}
}
echo "</div>";
$documents = $folder->getDocuments();
if($documents) {
$lucenesearch = $this->fulltextservice->Search();
echo "<div class=\"folder\">".$folder->getFolderPathPlain()."</div>";
// echo "<div class=\"folder\">".htmlspecialchars($folder->getFolderPathPlain())."</div>";
foreach($documents as $document) {
echo "<div class=\"document\">".$document->getId().":".htmlspecialchars($document->getName());
/* If the document wasn't indexed before then just add it */
if(!($hit = $lucenesearch->getDocument($document->getId()))) {
echo " <span id=\"status_".$document->getID()."\" class=\"indexme indexstatus\" data-docid=\"".$document->getID()."\">".getMLText('index_waiting')."</span>";
if(($this->numdocs == 0) || !($hit = $lucenesearch->getDocument($document->getId()))) {
echo " <span id=\"status_D".$document->getID()."\" class=\"indexme indexstatus\" data-docid=\"D".$document->getID()."\">".getMLText('index_waiting')."</span>";
} else {
/* Check if the attribute created is set or has a value older
* than the lastet content. Documents without such an attribute
@ -57,10 +82,10 @@ class SeedDMS_View_Indexer_Process_Folder { /* {{{ */
}
$content = $document->getLatestContent();
if($created >= $content->getDate() && !$this->forceupdate) {
echo "<span id=\"status_".$document->getID()."\" class=\"indexstatus\" data-docid=\"".$document->getID()."\">".getMLText('index_document_unchanged')."</span>";
echo "<span id=\"status_D".$document->getID()."\" class=\"indexstatus\" data-docid=\"D".$document->getID()."\">".getMLText('index_document_unchanged')."</span>";
} else {
$this->fulltextservice->Indexer()->delete($hit->id);
echo " <span id=\"status_".$document->getID()."\" class=\"indexme indexstatus\" data-docid=\"".$document->getID()."\">".getMLText('index_waiting')."</span>";
echo " <span id=\"status_D".$document->getID()."\" class=\"indexme indexstatus\" data-docid=\"D".$document->getID()."\">".getMLText('index_waiting')."</span>";
}
}
echo "</div>";
@ -105,12 +130,18 @@ function check_queue() {
if(funcArray.length == 0) {
return;
}
var command = '';
docid = funcArray.pop();
$('#status_'+docid).html('Processsing ...');
if(docid[0] == 'F') {
command = 'indexfolder';
} else {
command = 'indexdocument';
}
$.ajax({url: '../op/op.Ajax.php',
type: 'GET',
dataType: "json",
data: {command: 'indexdocument', id: docid},
data: {command: command, id: docid.substring(1)},
beforeSend: function() {
queue_count++; // Add request to the counter
$('.queue-bar').css('width', (queue_count*100/MAX_REQUESTS)+'%');
@ -153,7 +184,7 @@ function check_queue() {
if(funcArray.length+queue_count == 0)
$('.total-bar').addClass('bar-success');
}
});
});
setTimeout(function() { check_queue() }, CALL_WAIT);
}