From 73b957281f6561a7180545525788742932a99ad7 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Tue, 29 Sep 2020 16:37:50 +0200 Subject: [PATCH 001/210] start version 5.1.21 --- CHANGELOG | 4 ++++ SeedDMS_Core/Core/inc.ClassDMS.php | 2 +- inc/inc.Version.php | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 21bc53d18..a115afa4c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +-------------------------------------------------------------------------------- + Changes in version 5.1.21 +-------------------------------------------------------------------------------- + -------------------------------------------------------------------------------- Changes in version 5.1.20 -------------------------------------------------------------------------------- diff --git a/SeedDMS_Core/Core/inc.ClassDMS.php b/SeedDMS_Core/Core/inc.ClassDMS.php index bde9fb114..88ee61414 100644 --- a/SeedDMS_Core/Core/inc.ClassDMS.php +++ b/SeedDMS_Core/Core/inc.ClassDMS.php @@ -396,7 +396,7 @@ class SeedDMS_Core_DMS { $this->lasterror = ''; $this->version = '@package_version@'; if($this->version[0] == '@') - $this->version = '5.1.20'; + $this->version = '5.1.21'; } /* }}} */ /** diff --git a/inc/inc.Version.php b/inc/inc.Version.php index 6e4476b08..765c0a617 100644 --- a/inc/inc.Version.php +++ b/inc/inc.Version.php @@ -20,7 +20,7 @@ class SeedDMS_Version { /* {{{ */ - const _number = "5.1.20"; + const _number = "5.1.21"; const _string = "SeedDMS"; function __construct() { From 3a183a452a078cafe7116973fdd1361bf5283c31 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Tue, 8 Sep 2020 17:06:26 +0200 Subject: [PATCH 002/210] put fulltext index into service --- inc/inc.ClassFulltextService.php | 84 ++++++++++++++++++++++++++++++++ inc/inc.Settings.php | 7 +++ 2 files changed, 91 insertions(+) create mode 100644 inc/inc.ClassFulltextService.php diff --git a/inc/inc.ClassFulltextService.php b/inc/inc.ClassFulltextService.php new file mode 100644 index 000000000..613dcc284 --- /dev/null +++ b/inc/inc.ClassFulltextService.php @@ -0,0 +1,84 @@ + + * @copyright Copyright (C) 2016 Uwe Steinmann + * @version Release: @package_version@ + */ + +/** + * Implementation of fulltext service + * + * @category DMS + * @package SeedDMS + * @author Uwe Steinmann + * @copyright Copyright (C) 2016 Uwe Steinmann + * @version Release: @package_version@ + */ +class SeedDMS_FulltextService { + /** + * List of services for searching fulltext + */ + protected $services; + + /** + * List of converters + */ + protected $converters; + + /** + * Max file size for imediate indexing + */ + protected $maxsize; + + public function __construct() { + $this->services = array(); + $this->converters = array(); + $this->maxsize = 0; + $this->indexdir = ''; + $this->index = null; + } + + public function addService($name, $service) { + $this->services[$name] = $service; + } + + public function setConverters($converters) { + $this->converters = $converters; + } + + public function setMaxSize($maxsize) { + $this->maxsize = $maxsize; + } + + public function setIndexDir($indexdir) { + $this->indexdir = $indexdir; + } + + public function IndexedDocument($document) { + $indexcontent = $document->getLatestContent()->getFileSize() < $this->maxsize; + return new $this->services[0]['IndexedDocument']($document->getDMS(), $document, $this->converters, $indexcontent); + } + + public function Indexer($recreate) { + if($this->indexdir) { + if($recreate) + $this->index = $this->services[0]['Indexer']::create($this->indexdir); + else + $this->index = $this->services[0]['Indexer']::open($this->indexdir); + return $this->index; + } else + return null; + } + + public function Indexer($recreate) { + return new $this->services[0]['Search'](); + } +} + + diff --git a/inc/inc.Settings.php b/inc/inc.Settings.php index 659b202d3..4f7e7dd5c 100644 --- a/inc/inc.Settings.php +++ b/inc/inc.Settings.php @@ -52,6 +52,9 @@ if (get_magic_quotes_gpc()) { unset($process); } +require_once("inc.ClassFulltextService.php"); +$fulltextservice = new SeedDMS_FulltextService(); + $indexconf = null; if($settings->_enableFullSearch) { if($settings->_fullSearchEngine == 'sqlitefts') { @@ -60,6 +63,7 @@ if($settings->_enableFullSearch) { 'Search' => 'SeedDMS_SQLiteFTS_Search', 'IndexedDocument' => 'SeedDMS_SQLiteFTS_IndexedDocument' ); + $fulltextservice->addService('sqlitefts', $indexconf); require_once('SeedDMS/SQLiteFTS.php'); } else { @@ -68,12 +72,15 @@ if($settings->_enableFullSearch) { 'Search' => 'SeedDMS_Lucene_Search', 'IndexedDocument' => 'SeedDMS_Lucene_IndexedDocument' ); + $fulltextservice->addService('lucene', $indexconf); if(!empty($settings->_luceneClassDir)) require_once($settings->_luceneClassDir.'/Lucene.php'); else require_once('SeedDMS/Lucene.php'); } + $fulltextservice->setConverters(isset($settings->_converters['fulltext']) ? $settings->_converters['fulltext'] : null); + $fulltextservice->setMaxSize($settings->_maxSizeForFullText); } $settings->_indexconf = $indexconf; From 4bdb3c7061556c55e13f95e84c92a2206661f9c7 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Wed, 9 Sep 2020 19:49:15 +0200 Subject: [PATCH 003/210] put fulltext search into central service --- SeedDMS_SQLiteFTS/SQLiteFTS/Indexer.php | 2 +- controllers/class.AddDocument.php | 7 +- controllers/class.RemoveDocument.php | 7 +- controllers/class.RemoveFolder.php | 14 ++-- controllers/class.UpdateDocument.php | 9 +- inc/inc.ClassFulltextService.php | 22 +++-- inc/inc.DBInit.php | 2 + inc/inc.Settings.php | 32 -------- op/op.AddDocument.php | 10 +-- op/op.Ajax.php | 30 ++----- op/op.RemoveDocument.php | 11 +-- op/op.RemoveFolder.php | 10 +-- op/op.RemoveVersion.php | 31 +++---- op/op.UpdateDocument.php | 10 +-- op/op.UpdateDocument2.php | 8 +- out/out.IndexInfo.php | 2 +- out/out.Indexer.php | 13 ++- out/out.Search.php | 4 +- utils/indexer.php | 38 ++------- views/bootstrap/class.Indexer.php | 105 +++--------------------- views/bootstrap/class.Settings.php | 10 ++- 21 files changed, 94 insertions(+), 283 deletions(-) diff --git a/SeedDMS_SQLiteFTS/SQLiteFTS/Indexer.php b/SeedDMS_SQLiteFTS/SQLiteFTS/Indexer.php index f4791f5f2..749782300 100644 --- a/SeedDMS_SQLiteFTS/SQLiteFTS/Indexer.php +++ b/SeedDMS_SQLiteFTS/SQLiteFTS/Indexer.php @@ -96,7 +96,7 @@ class SeedDMS_SQLiteFTS_Indexer { if(!$this->_conn) return false; - $sql = "INSERT INTO docs (docid, title, comment, keywords, category, owner, content, mimetype, origfilename, created, users) VALUES(".$doc->getFieldValue('document_id').", ".$this->_conn->quote($doc->getFieldValue('title')).", ".$this->_conn->quote($doc->getFieldValue('comment')).", ".$this->_conn->quote($doc->getFieldValue('keywords')).", ".$this->_conn->quote($doc->getFieldValue('category')).", ".$this->_conn->quote($doc->getFieldValue('owner')).", ".$this->_conn->quote($doc->getFieldValue('content')).", ".$this->_conn->quote($doc->getFieldValue('mimetype')).", ".$this->_conn->quote($doc->getFieldValue('origfilename')).", ".$doc->getFieldValue('created').", ".$this->_conn->quote($doc->getFieldValue('users'))/*time()*/.")"; + $sql = "INSERT INTO docs (docid, title, comment, keywords, category, owner, content, mimetype, origfilename, created, users) VALUES(".$doc->getFieldValue('document_id').", ".$this->_conn->quote($doc->getFieldValue('title')).", ".$this->_conn->quote($doc->getFieldValue('comment')).", ".$this->_conn->quote($doc->getFieldValue('keywords')).", ".$this->_conn->quote($doc->getFieldValue('category')).", ".$this->_conn->quote($doc->getFieldValue('owner')).", ".$this->_conn->quote($doc->getFieldValue('content')).", ".$this->_conn->quote($doc->getFieldValue('mimetype')).", ".$this->_conn->quote($doc->getFieldValue('origfilename')).", ".(int)$doc->getFieldValue('created').", ".$this->_conn->quote($doc->getFieldValue('users'))/*time()*/.")"; $res = $this->_conn->exec($sql); if($res === false) { return false; diff --git a/controllers/class.AddDocument.php b/controllers/class.AddDocument.php index 69259ca9e..0986a2961 100644 --- a/controllers/class.AddDocument.php +++ b/controllers/class.AddDocument.php @@ -26,8 +26,7 @@ class SeedDMS_Controller_AddDocument extends SeedDMS_Controller_Common { $dms = $this->params['dms']; $user = $this->params['user']; $settings = $this->params['settings']; - $index = $this->params['index']; - $indexconf = $this->params['indexconf']; + $fulltextservice = $this->params['fulltextservice']; $folder = $this->params['folder']; /* Call preAddDocument early, because it might need to modify some @@ -140,8 +139,8 @@ class SeedDMS_Controller_AddDocument extends SeedDMS_Controller_Common { return false; } - if($index && $document) { - $idoc = new $indexconf['IndexedDocument']($dms, $document, isset($settings->_converters['fulltext']) ? $settings->_converters['fulltext'] : null, !($filesize < $settings->_maxSizeForFullText)); + if($fulltextservice && ($index = $fulltextservice->Indexer()) && $document) { + $idoc = $fulltextservice->IndexedDocument($document); if(false !== $this->callHook('preIndexDocument', $document, $idoc)) { $index->addDocument($idoc); $index->commit(); diff --git a/controllers/class.RemoveDocument.php b/controllers/class.RemoveDocument.php index d4b1950f7..1b78314d9 100644 --- a/controllers/class.RemoveDocument.php +++ b/controllers/class.RemoveDocument.php @@ -27,8 +27,7 @@ class SeedDMS_Controller_RemoveDocument extends SeedDMS_Controller_Common { $user = $this->params['user']; $settings = $this->params['settings']; $document = $this->params['document']; - $index = $this->params['index']; - $indexconf = $this->params['indexconf']; + $fulltextservice = $this->params['fulltextservice']; $folder = $document->getFolder(); @@ -58,8 +57,8 @@ class SeedDMS_Controller_RemoveDocument extends SeedDMS_Controller_Common { } /* Remove the document from the fulltext index */ - if($index) { - $lucenesearch = new $indexconf['Search']($index); + if($fulltextservice && ($index = $fulltextservice->Indexer())) { + $lucenesearch = $fulltextservice->Search(); if($hit = $lucenesearch->getDocument($documentid)) { $index->delete($hit->id); $index->commit(); diff --git a/controllers/class.RemoveFolder.php b/controllers/class.RemoveFolder.php index b12c10eae..8ccac220a 100644 --- a/controllers/class.RemoveFolder.php +++ b/controllers/class.RemoveFolder.php @@ -27,8 +27,7 @@ class SeedDMS_Controller_RemoveFolder extends SeedDMS_Controller_Common { $user = $this->params['user']; $settings = $this->params['settings']; $folder = $this->params['folder']; - $index = $this->params['index']; - $indexconf = $this->params['indexconf']; + $fulltextservice = $this->params['fulltextservice']; /* Get the document id and name before removing the document */ $foldername = $folder->getName(); @@ -45,18 +44,17 @@ class SeedDMS_Controller_RemoveFolder extends SeedDMS_Controller_Common { /* Register a callback which removes each document from the fulltext index * The callback must return null other the removal will be canceled. */ - function removeFromIndex($arr, $document) { - $index = $arr[0]; - $indexconf = $arr[1]; - $lucenesearch = new $indexconf['Search']($index); + function removeFromIndex($fulltextservice, $document) { + $lucenesearch = $fulltextservice->Search(); if($hit = $lucenesearch->getDocument($document->getID())) { + $index = $fulltextservice->Indexer(); $index->delete($hit->id); $index->commit(); } return null; } - if($index) - $dms->setCallback('onPreRemoveDocument', 'removeFromIndex', array($index, $indexconf)); + if($fulltextservice && ($index = $fulltextservice->Indexer())) + $dms->setCallback('onPreRemoveDocument', 'removeFromIndex', array($fulltextservice)); function removePreviews($arr, $document) { $previewer = $arr[0]; diff --git a/controllers/class.UpdateDocument.php b/controllers/class.UpdateDocument.php index 6c7b97838..c1e2b7e57 100644 --- a/controllers/class.UpdateDocument.php +++ b/controllers/class.UpdateDocument.php @@ -40,8 +40,7 @@ class SeedDMS_Controller_UpdateDocument extends SeedDMS_Controller_Common { $user = $this->params['user']; $document = $this->params['document']; $settings = $this->params['settings']; - $index = $this->params['index']; - $indexconf = $this->params['indexconf']; + $fulltextservice = $this->params['fulltextservice']; $folder = $this->params['folder']; $userfiletmp = $this->getParam('userfiletmp'); $userfilename = $this->getParam('userfilename'); @@ -77,12 +76,12 @@ class SeedDMS_Controller_UpdateDocument extends SeedDMS_Controller_Common { return false; } - if($index && $content) { - $lucenesearch = new $indexconf['Search']($index); + if($fulltextservice && ($index = $fulltextservice->Indexer()) && $content) { + $lucenesearch = $fulltextservice->Search(); if($hit = $lucenesearch->getDocument((int) $document->getId())) { $index->delete($hit->id); } - $idoc = new $indexconf['IndexedDocument']($dms, $document, isset($settings->_converters['fulltext']) ? $settings->_converters['fulltext'] : null, !($filesize < $settings->_maxSizeForFullText)); + $idoc = $fulltextservice->IndexedDocument($document); if(false !== $this->callHook('preIndexDocument', $document, $idoc)) { $index->addDocument($idoc); $index->commit(); diff --git a/inc/inc.ClassFulltextService.php b/inc/inc.ClassFulltextService.php index 613dcc284..79153dfab 100644 --- a/inc/inc.ClassFulltextService.php +++ b/inc/inc.ClassFulltextService.php @@ -42,10 +42,11 @@ class SeedDMS_FulltextService { $this->maxsize = 0; $this->indexdir = ''; $this->index = null; + $this->cmdtimeout = 5; } public function addService($name, $service) { - $this->services[$name] = $service; + $this->services[] = $service; } public function setConverters($converters) { @@ -60,12 +61,19 @@ class SeedDMS_FulltextService { $this->indexdir = $indexdir; } - public function IndexedDocument($document) { - $indexcontent = $document->getLatestContent()->getFileSize() < $this->maxsize; - return new $this->services[0]['IndexedDocument']($document->getDMS(), $document, $this->converters, $indexcontent); + public function setCmdTimeout($timeout) { + $this->cmdtimeout = $timeout; } - public function Indexer($recreate) { + public function IndexedDocument($document, $forceupdate=false) { + $nocontent = ($document->getLatestContent()->getFileSize() > $this->maxsize) && !$forceupdate; + return new $this->services[0]['IndexedDocument']($document->getDMS(), $document, $this->converters, $nocontent, $this->cmdtimeout); + } + + public function Indexer($recreate=false) { + if($this->index) + return $this->index; + if($this->indexdir) { if($recreate) $this->index = $this->services[0]['Indexer']::create($this->indexdir); @@ -76,8 +84,8 @@ class SeedDMS_FulltextService { return null; } - public function Indexer($recreate) { - return new $this->services[0]['Search'](); + public function Search() { + return new $this->services[0]['Search']($this->index); } } diff --git a/inc/inc.DBInit.php b/inc/inc.DBInit.php index 1b8d31ab4..4dad2c87d 100644 --- a/inc/inc.DBInit.php +++ b/inc/inc.DBInit.php @@ -64,3 +64,5 @@ if(isset($GLOBALS['SEEDDMS_HOOKS']['initDMS'])) { } } } + +require_once('inc.FulltextInit.php'); diff --git a/inc/inc.Settings.php b/inc/inc.Settings.php index 4f7e7dd5c..c3705d77e 100644 --- a/inc/inc.Settings.php +++ b/inc/inc.Settings.php @@ -52,38 +52,6 @@ if (get_magic_quotes_gpc()) { unset($process); } -require_once("inc.ClassFulltextService.php"); -$fulltextservice = new SeedDMS_FulltextService(); - -$indexconf = null; -if($settings->_enableFullSearch) { - if($settings->_fullSearchEngine == 'sqlitefts') { - $indexconf = array( - 'Indexer' => 'SeedDMS_SQLiteFTS_Indexer', - 'Search' => 'SeedDMS_SQLiteFTS_Search', - 'IndexedDocument' => 'SeedDMS_SQLiteFTS_IndexedDocument' - ); - $fulltextservice->addService('sqlitefts', $indexconf); - - require_once('SeedDMS/SQLiteFTS.php'); - } else { - $indexconf = array( - 'Indexer' => 'SeedDMS_Lucene_Indexer', - 'Search' => 'SeedDMS_Lucene_Search', - 'IndexedDocument' => 'SeedDMS_Lucene_IndexedDocument' - ); - $fulltextservice->addService('lucene', $indexconf); - - if(!empty($settings->_luceneClassDir)) - require_once($settings->_luceneClassDir.'/Lucene.php'); - else - require_once('SeedDMS/Lucene.php'); - } - $fulltextservice->setConverters(isset($settings->_converters['fulltext']) ? $settings->_converters['fulltext'] : null); - $fulltextservice->setMaxSize($settings->_maxSizeForFullText); -} -$settings->_indexconf = $indexconf; - /* Add root Dir. Needed because the view classes are included * relative to it. */ diff --git a/op/op.AddDocument.php b/op/op.AddDocument.php index 704052eea..7a559f826 100644 --- a/op/op.AddDocument.php +++ b/op/op.AddDocument.php @@ -303,13 +303,6 @@ if(isset($_POST[$prefix.'-fine-uploader-uuids']) && $_POST[$prefix.'-fine-upload } } -if($settings->_enableFullSearch) { - $index = $indexconf['Indexer']::open($settings->_luceneDir); - $indexconf['Indexer']::init($settings->_stopWordsFile); -} else { - $index = null; -} - /* Check if additional notification shall be added */ $notusers = array(); if(!empty($_POST['notification_users'])) { @@ -371,8 +364,7 @@ for ($file_num=0;$file_numsetParam('documentsource', $docsource); $controller->setParam('folder', $folder); - $controller->setParam('index', $index); - $controller->setParam('indexconf', $indexconf); + $controller->setParam('fulltextservice', $fulltextservice); $controller->setParam('name', $name); $controller->setParam('comment', $comment); $controller->setParam('expires', $expires); diff --git a/op/op.Ajax.php b/op/op.Ajax.php index 4f30ab91b..6c965d60b 100644 --- a/op/op.Ajax.php +++ b/op/op.Ajax.php @@ -513,18 +513,9 @@ switch($command) { ); $docname = $document->getName(); - if($settings->_enableFullSearch) { - $index = $indexconf['Indexer']::open($settings->_luceneDir); - $indexconf['Indexer']::init($settings->_stopWordsFile); - } else { - $index = null; - $indexconf = null; - } - $controller = Controller::factory('RemoveDocument', array('dms'=>$dms, 'user'=>$user)); $controller->setParam('document', $document); - $controller->setParam('index', $index); - $controller->setParam('indexconf', $indexconf); + $controller->setParam('fulltextservice', $fulltextservice); if($controller->run()) { if ($notifier){ $subject = "document_deleted_email_subject"; @@ -779,19 +770,10 @@ switch($command) { $cats = array(); - if($settings->_enableFullSearch) { - $index = $indexconf['Indexer']::open($settings->_luceneDir); - $indexconf['Indexer']::init($settings->_stopWordsFile); - } else { - $index = null; - $indexconf = null; - } - $controller = Controller::factory('AddDocument', array('dms'=>$dms, 'user'=>$user)); $controller->setParam('documentsource', 'upload'); $controller->setParam('folder', $folder); - $controller->setParam('index', $index); - $controller->setParam('indexconf', $indexconf); + $controller->setParam('fulltextservice', $fulltextservice); $controller->setParam('name', $name); $controller->setParam('comment', ''); $controller->setParam('expires', $expires); @@ -933,13 +915,11 @@ switch($command) { case 'indexdocument': /* {{{ */ if($user && $user->isAdmin()) { - if($settings->_enableFullSearch) { + if($fulltextservice) { $document = $dms->getDocument($_REQUEST['id']); if($document) { - $index = $indexconf['Indexer']::open($settings->_luceneDir); - if($index) { - $indexconf['Indexer']::init($settings->_stopWordsFile); - $idoc = new $indexconf['IndexedDocument']($dms, $document, isset($settings->_converters['fulltext']) ? $settings->_converters['fulltext'] : null, false, $settings->_cmdTimeout); + if($index = $fulltextservice->Indexer()) { + $idoc = $fulltextservice->IndexedDocument($document, true); $error = $idoc->getErrorMsg(); if(!$error) { $ires = null; diff --git a/op/op.RemoveDocument.php b/op/op.RemoveDocument.php index bfd19b701..24fd3c614 100644 --- a/op/op.RemoveDocument.php +++ b/op/op.RemoveDocument.php @@ -60,14 +60,6 @@ if($document->isLocked()) { } } -if($settings->_enableFullSearch) { - $index = $indexconf['Indexer']::open($settings->_luceneDir); - $indexconf['Indexer']::init($settings->_stopWordsFile); -} else { - $index = null; - $indexconf = null; -} - $folder = $document->getFolder(); /* Remove all preview images. */ @@ -87,8 +79,7 @@ $nl = array( $docname = $document->getName(); $controller->setParam('document', $document); -$controller->setParam('index', $index); -$controller->setParam('indexconf', $indexconf); +$controller->setParam('fulltextservice', $fulltextservice); if(!$controller->run()) { if ($controller->getErrorMsg() != '') $errormsg = $controller->getErrorMsg(); diff --git a/op/op.RemoveFolder.php b/op/op.RemoveFolder.php index 5ca82a13a..53c630b03 100644 --- a/op/op.RemoveFolder.php +++ b/op/op.RemoveFolder.php @@ -54,13 +54,6 @@ if ($folder->getAccessMode($user, 'removeFolder') < M_ALL) { UI::exitError(getMLText("folder_title", array("foldername" => $folder->getName())),getMLText("access_denied")); } -if($settings->_enableFullSearch) { - $index = $indexconf['Indexer']::open($settings->_luceneDir); - $indexconf['Indexer']::init($settings->_stopWordsFile); -} else { - $index = null; -} - /* function removePreviews($arr, $document) { $previewer = $arr[0]; @@ -86,8 +79,7 @@ $nl = array( ); $controller->setParam('folder', $folder); -$controller->setParam('index', $index); -$controller->setParam('indexconf', $indexconf); +$controller->setParam('fulltextservice', $fulltextservice); if(!$controller->run()) { UI::exitError(getMLText("folder_title", array("foldername" => htmlspecialchars($foldername))),getMLText("error_remove_folder")); } diff --git a/op/op.RemoveVersion.php b/op/op.RemoveVersion.php index 0dd0e2287..8f7eede93 100644 --- a/op/op.RemoveVersion.php +++ b/op/op.RemoveVersion.php @@ -74,14 +74,11 @@ if (count($document->getContent())==1) { } else { $nexturl = "../out/out.ViewFolder.php?folderid=".$folder->getId(); /* Remove the document from the fulltext index */ - if($settings->_enableFullSearch) { - $index = $indexconf['Indexer']::open($settings->_luceneDir); - if($index) { - $lucenesearch = new $indexconf['Search']($index); - if($hit = $lucenesearch->getDocument($documentid)) { - $index->delete($hit->id); - $index->commit(); - } + if($fulltextservice && ($index = $fulltextservice->Index())) { + $lucenesearch = $fulltextservice->Search(); + if($hit = $lucenesearch->getDocument($documentid)) { + $index->delete($hit->id); + $index->commit(); } } @@ -142,18 +139,14 @@ else { else $nexturl = "../out/out.ViewDocument.php?documentid=".$documentid."¤ttab=previous"; /* Remove the document from the fulltext index and reindex latest version */ - if($settings->_enableFullSearch) { - $index = $indexconf['Indexer']::open($settings->_luceneDir); - if($index) { - $lucenesearch = new $indexconf['Search']($index); - if($hit = $lucenesearch->getDocument($document->getID())) { - $index->delete($hit->id); - } - $version = $document->getLatestContent(); - $indexconf['Indexer']::init($settings->_stopWordsFile); - $index->addDocument(new $indexconf['IndexedDocument']($dms, $document, isset($settings->_converters['fulltext']) ? $settings->_converters['fulltext'] : null, !($version->getFileSize() < $settings->_maxSizeForFullText))); - $index->commit(); + if($fulltextservice && ($index = $fulltextservice->Indexer())) { + $lucenesearch = $fulltextservice->Search(); + if($hit = $lucenesearch->getDocument($document->getID())) { + $index->delete($hit->id); } + $version = $document->getLatestContent(); + $index->addDocument($fulltextservice->IndexedDocument($document)); + $index->commit(); } // Notify affected users. diff --git a/op/op.UpdateDocument.php b/op/op.UpdateDocument.php index 2e8a377a7..91da9f50e 100644 --- a/op/op.UpdateDocument.php +++ b/op/op.UpdateDocument.php @@ -133,13 +133,6 @@ if (isset($_FILES['userfile']) && $_FILES['userfile']['error'] == 0) { $fileType = ".".pathinfo($userfilename, PATHINFO_EXTENSION); -if($settings->_enableFullSearch) { - $index = $indexconf['Indexer']::open($settings->_luceneDir); - $indexconf['Indexer']::init($settings->_stopWordsFile); -} else { - $index = null; -} - if(isset($_POST["comment"])) $comment = $_POST["comment"]; else @@ -291,8 +284,7 @@ default: $controller->setParam('folder', $folder); $controller->setParam('document', $document); - $controller->setParam('index', $index); - $controller->setParam('indexconf', $indexconf); + $controller->setParam('fulltextservice', $fulltextservice); $controller->setParam('comment', $comment); if($oldexpires != $expires) $controller->setParam('expires', $expires); diff --git a/op/op.UpdateDocument2.php b/op/op.UpdateDocument2.php index 342160127..609125075 100644 --- a/op/op.UpdateDocument2.php +++ b/op/op.UpdateDocument2.php @@ -159,15 +159,13 @@ if( move_uploaded_file( $source_file_path, $target_file_path ) ) { if (is_bool($contentResult) && !$contentResult) { echo getMLText("error_occured"); } else { - if($settings->_enableFullSearch) { - $index = $indexconf['Indexer']::open($settings->_luceneDir); + if($fulltextservice && ($index = $fulltextservice->Indexer())) { if($index) { - $lucenesearch = new $indexconf['Search']($index); + $lucenesearch = $fulltextservice->Search(); if($hit = $lucenesearch->getDocument((int) $document->getId())) { $index->delete($hit->id); } - $indexconf['Indexer']::init($settings->_stopWordsFile); - $index->addDocument(new $indexconf['IndexedDocument']($dms, $document, isset($settings->_converters['fulltext']) ? $settings->_converters['fulltext'] : null, !($filesize < $settings->_maxSizeForFullText))); + $index->addDocument($fulltextservice->IndexedDocument($document)); $index->commit(); } } diff --git a/out/out.IndexInfo.php b/out/out.IndexInfo.php index c0f026b05..b2d0d4bc6 100644 --- a/out/out.IndexInfo.php +++ b/out/out.IndexInfo.php @@ -40,7 +40,7 @@ if(!$settings->_enableFullSearch) { UI::exitError(getMLText("admin_tools"),getMLText("fulltextsearch_disabled")); } -$index = $indexconf['Indexer']::open($settings->_luceneDir); +$index = $fulltextservice->Indexer(); if(!$index) { UI::exitError(getMLText("admin_tools"),getMLText("no_fulltextindex")); } diff --git a/out/out.Indexer.php b/out/out.Indexer.php index d4521bc81..aeb445973 100644 --- a/out/out.Indexer.php +++ b/out/out.Indexer.php @@ -42,27 +42,25 @@ if(!$settings->_enableFullSearch) { $index = null; if(!isset($_GET['action']) || $_GET['action'] == 'show') { - if($indexconf) { + if($fulltextservice) { if(isset($_GET['create']) && $_GET['create'] == 1) { if(isset($_GET['confirm']) && $_GET['confirm'] == 1) { - $index = $indexconf['Indexer']::create($settings->_luceneDir); + $index = $fulltextservice->Indexer(true); if(!$index) { UI::exitError(getMLText("admin_tools"),getMLText("no_fulltextindex")); } - $indexconf['Indexer']::init($settings->_stopWordsFile); } else { header('Location: out.CreateIndex.php'); exit; } } else { - $index = $indexconf['Indexer']::open($settings->_luceneDir); + $index = $fulltextservice->Indexer(false); if(!$index) { - $index = $indexconf['Indexer']::create($settings->_luceneDir); + $index = $fulltextservice->Indexer(true); if(!$index) { UI::exitError(getMLText("admin_tools"),getMLText("no_fulltextindex")); } } - $indexconf['Indexer']::init($settings->_stopWordsFile); } } } @@ -76,8 +74,7 @@ else { $folder = $dms->getFolder($folderid); if($view) { - $view->setParam('index', $index); - $view->setParam('indexconf', $indexconf); + $view->setParam('fulltextservice', $fulltextservice); $view->setParam('recreate', (isset($_GET['create']) && $_GET['create']==1)); $view->setParam('forceupdate', (isset($_GET['forceupdate']) && $_GET['forceupdate']==1)); $view->setParam('folder', $folder); diff --git a/out/out.Search.php b/out/out.Search.php index 74d47fb35..fa8f450c8 100644 --- a/out/out.Search.php +++ b/out/out.Search.php @@ -126,8 +126,8 @@ if(isset($_GET["fullsearch"]) && $_GET["fullsearch"] && $settings->_enableFullSe $searchTime = 0; } else { $startTime = getTime(); - $index = $indexconf['Indexer']::open($settings->_luceneDir); - $lucenesearch = new $indexconf['Search']($index); + $index = $fulltextservice->Indexer(); + $lucenesearch = $fulltextservice->Search(); $hits = $lucenesearch->search($query, $owner ? $owner->getLogin() : '', '', $categorynames, array(), $user->isAdmin() ? [] : [$user->getLogin()]); if($hits === false) { $session->setSplashMsg(array('type'=>'error', 'msg'=>getMLText('splash_invalid_searchterm'))); diff --git a/utils/indexer.php b/utils/indexer.php index f0f2daf1b..9463310c6 100644 --- a/utils/indexer.php +++ b/utils/indexer.php @@ -59,38 +59,21 @@ include($myincpath."/inc/inc.Init.php"); include($myincpath."/inc/inc.Extension.php"); include($myincpath."/inc/inc.DBInit.php"); -if($settings->_fullSearchEngine == 'sqlitefts') { - $indexconf = array( - 'Indexer' => 'SeedDMS_SQLiteFTS_Indexer', - 'Search' => 'SeedDMS_SQLiteFTS_Search', - 'IndexedDocument' => 'SeedDMS_SQLiteFTS_IndexedDocument' - ); - - require_once('SeedDMS/SQLiteFTS.php'); -} else { - $indexconf = array( - 'Indexer' => 'SeedDMS_Lucene_Indexer', - 'Search' => 'SeedDMS_Lucene_Search', - 'IndexedDocument' => 'SeedDMS_Lucene_IndexedDocument' - ); - - require_once('SeedDMS/Lucene.php'); -} - -function tree($dms, $index, $indexconf, $folder, $indent='') { /* {{{ */ +function tree($dms, $fulltextservice, $folder, $indent='') { /* {{{ */ global $settings, $themes; echo $themes->black($indent."D ".$folder->getName()).PHP_EOL; $subfolders = $folder->getSubFolders(); foreach($subfolders as $subfolder) { - tree($dms, $index, $indexconf, $subfolder, $indent.' '); + tree($dms, $fulltextservice, $subfolder, $indent.' '); } $documents = $folder->getDocuments(); foreach($documents as $document) { echo $themes->black($indent." ".$document->getId().":".$document->getName()." "); - $lucenesearch = new $indexconf['Search']($index); + $index = $fulltextservice->Indexer(); + $lucenesearch = $fulltextservice->Search(); if(!($hit = $lucenesearch->getDocument($document->getId()))) { try { - $idoc = new $indexconf['IndexedDocument']($dms, $document, isset($settings->_converters['fulltext']) ? $settings->_converters['fulltext'] : null, false, $settings->_cmdTimeout); + $idoc = $fulltextservice->IndexedDocument($document, true); if(isset($GLOBALS['SEEDDMS_HOOKS']['indexDocument'])) { foreach($GLOBALS['SEEDDMS_HOOKS']['indexDocument'] as $hookObj) { if (method_exists($hookObj, 'preIndexDocument')) { @@ -115,7 +98,7 @@ function tree($dms, $index, $indexconf, $folder, $indent='') { /* {{{ */ } else { $index->delete($hit->id); try { - $idoc = new $indexconf['IndexedDocument']($dms, $document, isset($settings->_converters['fulltext']) ? $settings->_converters['fulltext'] : null, false, $settings->_cmdTimeout); + $idoc = $fulltextservice->IndexedDocument($document, true); if(isset($GLOBALS['SEEDDMS_HOOKS']['indexDocument'])) { foreach($GLOBALS['SEEDDMS_HOOKS']['indexDocument'] as $hookObj) { if (method_exists($hookObj, 'preIndexDocument')) { @@ -135,19 +118,14 @@ function tree($dms, $index, $indexconf, $folder, $indent='') { /* {{{ */ $themes = new \AlecRabbit\ConsoleColour\Themes(); -if($recreate) - $index = $indexconf['Indexer']::create($settings->_luceneDir); -else - $index = $indexconf['Indexer']::open($settings->_luceneDir); +$index = $fulltextservice->Indexer($recreate); if(!$index) { echo $themes->error("Could not create index.").PHP_EOL; exit(1); } -$indexconf['Indexer']::init($settings->_stopWordsFile); - $folder = $dms->getFolder($settings->_rootFolderID); -tree($dms, $index, $indexconf, $folder); +tree($dms, $fulltextservice, $folder); $index->commit(); $index->optimize(); diff --git a/views/bootstrap/class.Indexer.php b/views/bootstrap/class.Indexer.php index e0934f963..7dbeaf4a5 100644 --- a/views/bootstrap/class.Indexer.php +++ b/views/bootstrap/class.Indexer.php @@ -29,11 +29,8 @@ class SeedDMS_View_Indexer_Process_Folder { /* {{{ */ protected $index; - protected $indexconf; - - public function __construct($index, $indexconf, $forceupdate) { /* {{{ */ - $this->index = $index; - $this->indexconf = $indexconf; + public function __construct($fulltextservice, $forceupdate) { /* {{{ */ + $this->fulltextservice = $fulltextservice; $this->forceupdate = $forceupdate; } /* }}} */ @@ -44,17 +41,9 @@ class SeedDMS_View_Indexer_Process_Folder { /* {{{ */ foreach($documents as $document) { echo "
".$document->getId().":".htmlspecialchars($document->getName()); /* If the document wasn't indexed before then just add it */ - $lucenesearch = new $this->indexconf['Search']($this->index); + $lucenesearch = $this->fulltextservice->Search(); if(!($hit = $lucenesearch->getDocument($document->getId()))) { echo " getID()."\" class=\"indexme indexstatus\" data-docid=\"".$document->getID()."\">".getMLText('index_waiting').""; - /* - try { - $index->addDocument(new $indexconf['IndexedDocument']($dms, $document, $this->converters ? $this->converters : null, false, $this->timeout)); - echo "(document added)"; - } catch(Exception $e) { - echo $indent."(adding document failed '".$e->getMessage()."')"; - } - */ } else { /* Check if the attribute created is set or has a value older * than the lastet content. Documents without such an attribute @@ -70,16 +59,8 @@ class SeedDMS_View_Indexer_Process_Folder { /* {{{ */ if($created >= $content->getDate() && !$this->forceupdate) { echo "getID()."\" class=\"indexstatus\" data-docid=\"".$document->getID()."\">".getMLText('index_document_unchanged').""; } else { - $this->index->delete($hit->id); + $this->fulltextservice->Indexer()->delete($hit->id); echo " getID()."\" class=\"indexme indexstatus\" data-docid=\"".$document->getID()."\">".getMLText('index_waiting').""; - /* - try { - $index->addDocument(new $indexconf['IndexedDocument']($dms, $document, $this->converters ? $this->converters : null, false, $this->timeout)); - echo $indent."(document updated)"; - } catch(Exception $e) { - echo $indent."(updating document failed)"; - } - */ } } echo "
"; @@ -110,13 +91,13 @@ class SeedDMS_View_Indexer extends SeedDMS_Bootstrap_Style { var queue_count = 0; // Number of functions being called var funcArray = []; // Array of functions waiting var MAX_REQUESTS = 5; // Max requests -var CALL_WAIT = 100; // 100ms +var CALL_WAIT = 20; // 100ms var docstoindex = 0; // total number of docs to index function check_queue() { // Check if count doesn't exceeds or if there aren't any functions to call - console.log('Queue has ' + funcArray.length + '/' + docstoindex + ' items'); - console.log('Currently processing ' + queue_count + ' requests (' + $.active + ')'); +// console.log('Queue has ' + funcArray.length + '/' + docstoindex + ' items'); +// console.log('Currently processing ' + queue_count + ' requests (' + $.active + ')'); if(queue_count >= MAX_REQUESTS) { setTimeout(function() { check_queue() }, CALL_WAIT); return; @@ -193,74 +174,10 @@ $(document).ready( function() { params['forceupdate']; - - set_time_limit(30); -// echo $indent."D ".htmlspecialchars($folder->getName())."\n"; - echo '\n"; - } /* }}} */ - function show() { /* {{{ */ $dms = $this->params['dms']; $user = $this->params['user']; - $index = $this->params['index']; - $indexconf = $this->params['indexconf']; + $fulltextservice = $this->params['fulltextservice']; $forceupdate = $this->params['forceupdate']; $folder = $this->params['folder']; $this->converters = $this->params['converters']; @@ -271,7 +188,8 @@ $(document).ready( function() { $this->contentStart(); $this->pageNavigation(getMLText("admin_tools"), "admin_tools"); $this->contentHeading(getMLText("update_fulltext_index")); - if($index) { + if($fulltextservice) { + $index = $fulltextservice->Indexer(); ?>