put fulltext search into central service

This commit is contained in:
Uwe Steinmann 2020-09-09 19:49:15 +02:00
parent 3a183a452a
commit 4bdb3c7061
21 changed files with 94 additions and 283 deletions

View File

@ -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;

View File

@ -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();

View File

@ -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();

View File

@ -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];

View File

@ -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();

View File

@ -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);
}
}

View File

@ -64,3 +64,5 @@ if(isset($GLOBALS['SEEDDMS_HOOKS']['initDMS'])) {
}
}
}
require_once('inc.FulltextInit.php');

View File

@ -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.
*/

View File

@ -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_num<count($_FILES["userfile"]["tmp_name"]);$file_num++){
$controller->setParam('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);

View File

@ -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;

View File

@ -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();

View File

@ -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"));
}

View File

@ -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."&currenttab=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.

View File

@ -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);

View File

@ -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();
}
}

View File

@ -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"));
}

View File

@ -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);

View File

@ -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')));

View File

@ -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();

View File

@ -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 "<div class=\"document\">".$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 " <span id=\"status_".$document->getID()."\" class=\"indexme indexstatus\" data-docid=\"".$document->getID()."\">".getMLText('index_waiting')."</span>";
/*
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 "<span id=\"status_".$document->getID()."\" class=\"indexstatus\" data-docid=\"".$document->getID()."\">".getMLText('index_document_unchanged')."</span>";
} else {
$this->index->delete($hit->id);
$this->fulltextservice->Indexer()->delete($hit->id);
echo " <span id=\"status_".$document->getID()."\" class=\"indexme indexstatus\" data-docid=\"".$document->getID()."\">".getMLText('index_waiting')."</span>";
/*
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 "</div>";
@ -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() {
<?php
} /* }}} */
protected function tree($dms, $index, $indexconf, $folder, $indent='') { /* {{{ */
$forceupdate = $this->params['forceupdate'];
set_time_limit(30);
// echo $indent."D ".htmlspecialchars($folder->getName())."\n";
echo '<ul class="nav nav-list"><li><label class="tree-toggle nav-header">'.htmlspecialchars($folder->getName()).'</label>'."\n";
$subfolders = $folder->getSubFolders();
foreach($subfolders as $subfolder) {
$this->tree($dms, $index, $indexconf, $subfolder, $indent.' ');
}
$documents = $folder->getDocuments();
if($documents) {
echo '<ul class="nav nav-list">'."\n";
foreach($documents as $document) {
// echo $indent." ".$document->getId().":".htmlspecialchars($document->getName());
echo "<li class=\"document\">".$document->getId().":".htmlspecialchars($document->getName());
/* If the document wasn't indexed before then just add it */
$lucenesearch = new $indexconf['Search']($index);
if(!($hit = $lucenesearch->getDocument($document->getId()))) {
echo " <span id=\"status_".$document->getID()."\" class=\"indexme indexstatus\" data-docid=\"".$document->getID()."\">".getMLText('index_waiting')."</span>";
/*
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
* 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;
}
$content = $document->getLatestContent();
if($created >= $content->getDate() && !$forceupdate) {
echo $indent."<span id=\"status_".$document->getID()."\" class=\"indexstatus\" data-docid=\"".$document->getID()."\">document unchanged</span>";
} else {
$index->delete($hit->id);
echo " <span id=\"status_".$document->getID()."\" class=\"indexme indexstatus\" data-docid=\"".$document->getID()."\">".getMLText('index_waiting')."</span>";
/*
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 "</li>";
echo "\n";
}
echo "</ul>\n";
}
echo "</li></ul>\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();
?>
<style type="text/css">
li {line-height: 20px;}
@ -299,10 +217,9 @@ div.folder {font-weight: bold; line-height: 20px; margin-top: 10px;}
<div class="bar-legend"><?php printMLText('indexing_tasks_in_queue'); ?></div>
</div>
<?php
$folderprocess = new SeedDMS_View_Indexer_Process_Folder($index, $indexconf, $forceupdate);
$folderprocess = new SeedDMS_View_Indexer_Process_Folder($fulltextservice, $forceupdate);
$tree = new SeedDMS_FolderTree($folder, array($folderprocess, 'process'));
call_user_func(array($folderprocess, 'process'), $folder);
// $this->tree($dms, $index, $indexconf, $folder);
echo "</div>";
$index->commit();

View File

@ -308,7 +308,15 @@ $this->showStartPaneContent('site', (!$currenttab || $currenttab == 'site'));
<?php $this->showConfigCheckbox('settings_enableUsersView', 'enableUsersView'); ?>
<?php $this->showConfigCheckbox('settings_enableFullSearch', 'enableFullSearch'); ?>
<?php $this->showConfigText('settings_maxSizeForFullText', 'maxSizeForFullText'); ?>
<?php $this->showConfigOption('settings_fullSearchEngine', 'fullSearchEngine', array('lucene'=>'settings_fullSearchEngine_vallucene', 'sqlitefts'=>'settings_fullSearchEngine_valsqlitefts'), false, true); ?>
<?php
$fullsearchengines = array(
'lucene'=>'settings_fullSearchEngine_vallucene',
'sqlitefts'=>'settings_fullSearchEngine_valsqlitefts'
);
if(($kkk = $this->callHook('getFullSearchEngine')) && is_array($kkk))
$fullsearchengines = array_merge($fullsearchengines, $kkk);
?>
<?php $this->showConfigOption('settings_fullSearchEngine', 'fullSearchEngine', $fullsearchengines, false, true); ?>
<?php $this->showConfigOption('settings_defaultSearchMethod', 'defaultSearchMethod', array('database'=>'settings_defaultSearchMethod_valdatabase', 'fulltext'=>'settings_defaultSearchMethod_valfulltext'), false, true); ?>
<?php $this->showConfigCheckbox('settings_showSingleSearchHit', 'showSingleSearchHit'); ?>
<?php $this->showConfigText('settings_stopWordsFile', 'stopWordsFile'); ?>