From 020f25052c39235977c2b82276bc0cb69f565f19 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Fri, 24 Feb 2017 12:13:51 +0100 Subject: [PATCH] index each document by calling ajax function --- out/out.Indexer.php | 1 + views/bootstrap/class.Indexer.php | 143 ++++++++++++++++++++++++++++-- 2 files changed, 135 insertions(+), 9 deletions(-) diff --git a/out/out.Indexer.php b/out/out.Indexer.php index 95aae671e..cd8a323d1 100644 --- a/out/out.Indexer.php +++ b/out/out.Indexer.php @@ -69,6 +69,7 @@ if($view) { $view->setParam('index', $index); $view->setParam('indexconf', $indexconf); $view->setParam('recreate', (isset($_GET['create']) && $_GET['create']==1)); + $view->setParam('forceupdate', (isset($_GET['forceupdate']) && $_GET['forceupdate']==1)); $view->setParam('folder', $folder); $view->setParam('converters', $settings->_converters['fulltext']); $view->setParam('timeout', $settings->_cmdTimeout); diff --git a/views/bootstrap/class.Indexer.php b/views/bootstrap/class.Indexer.php index 6eb3d2db0..4f08405f8 100644 --- a/views/bootstrap/class.Indexer.php +++ b/views/bootstrap/class.Indexer.php @@ -31,25 +31,121 @@ require_once("class.Bootstrap.php"); */ class SeedDMS_View_Indexer extends SeedDMS_Bootstrap_Style { - function tree($dms, $index, $indexconf, $folder, $indent='') { /* {{{ */ + function js() { /* {{{ */ + $dms = $this->params['dms']; + $user = $this->params['user']; + + header('Content-Type: application/javascript'); +?> +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 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 + ')'); + if(queue_count >= MAX_REQUESTS) { + setTimeout(function() { check_queue() }, CALL_WAIT); + return; + } + if(funcArray.length == 0) { + return; + } + docid = funcArray.pop(); + $('#status_'+docid).html('Processsing ...'); + $.ajax({url: '../op/op.Ajax.php', + type: 'GET', + dataType: "json", + data: {command: 'indexdocument', id: docid}, + beforeSend: function() { + queue_count++; // Add request to the counter + }, + error: function(xhr, textstatus) { + noty({ + text: textstatus, + type: 'error', + dismissQueue: true, + layout: 'topRight', + theme: 'defaultTheme', + timeout: 1500, + }); + }, + success: function(data) { + // console.log('success ' + data.data); + if(data.success) { + $('#status_'+data.data).html('done'); + } else { + $('#status_'+data.data).html('error'); + noty({ + text: data.message, + type: (data.success) ? 'success' : 'error', + dismissQueue: true, + layout: 'topRight', + theme: 'defaultTheme', + timeout: 1500, + }); + } + }, + complete: function(xhr, textstatus) { + queue_count--; // Substract request to the counter + $('.queue-bar').css('width', (queue_count*100/MAX_REQUESTS)+'%'); + $('.total-bar').css('width', (100 - (funcArray.length+queue_count)*100/docstoindex)+'%'); + $('.total-bar').text(Math.round(100 - (funcArray.length+queue_count)*100/docstoindex)+' %'); + if(funcArray.length+queue_count == 0) + $('.total-bar').addClass('bar-success'); + } + }); + setTimeout(function() { check_queue() }, CALL_WAIT); +} + +$(document).ready( function() { + $('.tree-toggle').click(function () { + $(this).parent().children('ul.tree').toggle(200); + }); + + $('.indexme').each(function(index) { + var element = $(this); + var docid = element.data('docid'); + element.html('Pending'); + funcArray.push(docid); + }); + docstoindex = funcArray.length; + check_queue(); // First call to start polling. It will call itself each 100ms +}); +params['forceupdate']; + set_time_limit(30); - echo $indent."D ".htmlspecialchars($folder->getName())."\n"; +// echo $indent."D ".htmlspecialchars($folder->getName())."\n"; + echo '\n"; } /* }}} */ function show() { /* {{{ */ @@ -83,7 +186,7 @@ class SeedDMS_View_Indexer extends SeedDMS_Bootstrap_Style { $user = $this->params['user']; $index = $this->params['index']; $indexconf = $this->params['indexconf']; - $recreate = $this->params['recreate']; + $forceupdate = $this->params['forceupdate']; $folder = $this->params['folder']; $this->converters = $this->params['converters']; $this->timeout = $this->params['timeout']; @@ -93,10 +196,32 @@ class SeedDMS_View_Indexer extends SeedDMS_Bootstrap_Style { $this->contentStart(); $this->pageNavigation(getMLText("admin_tools"), "admin_tools"); $this->contentHeading(getMLText("update_fulltext_index")); - - echo "
";
+?>
+
+		
+
+
+
+
+
Overall progress
+
+
+
+
+
+
Indexing tasks in queue
+
+tree($dms, $index, $indexconf, $folder); - echo "
"; + echo ""; $index->commit(); $index->optimize();