Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/fulltextsearch.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2018-08-18 13:31:52 +0300
committerMaxence Lange <maxence@artificial-owl.com>2018-08-18 13:31:52 +0300
commit783268a166670b6645f194fecb0476feab911246 (patch)
treeaf0a071d1f6d4929877b61ecc7f36b2eaa95a200 /lib
parent520896400e9158230a9094030fd49c2a422d0781 (diff)
managing errors
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Command/Index.php310
-rw-r--r--lib/Db/CoreRequestBuilder.php14
-rw-r--r--lib/Db/IndexesRequest.php63
-rw-r--r--lib/Db/IndexesRequestBuilder.php7
-rw-r--r--lib/Model/Index.php61
-rw-r--r--lib/Service/IndexService.php122
6 files changed, 509 insertions, 68 deletions
diff --git a/lib/Command/Index.php b/lib/Command/Index.php
index b49f7e1..3c05e58 100644
--- a/lib/Command/Index.php
+++ b/lib/Command/Index.php
@@ -27,9 +27,11 @@
namespace OCA\FullTextSearch\Command;
use Exception;
+use OCA\FullTextSearch\Exceptions\TickDoesNotExistException;
use OCA\FullTextSearch\IFullTextSearchProvider;
use OCA\FullTextSearch\Model\ExtendedBase;
use OCA\FullTextSearch\Model\IndexOptions;
+use OCA\FullTextSearch\Model\Index as ModelIndex;
use OCA\FullTextSearch\Model\Runner;
use OCA\FullTextSearch\Service\CliService;
use OCA\FullTextSearch\Service\IndexService;
@@ -38,6 +40,7 @@ use OCA\FullTextSearch\Service\PlatformService;
use OCA\FullTextSearch\Service\ProviderService;
use OCA\FullTextSearch\Service\RunningService;
use OCP\IUserManager;
+use Symfony\Component\Console\Formatter\OutputFormatterStyle;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@@ -63,18 +66,26 @@ class Index extends ExtendedBase {
const PANEL_STATUS = 'status';
const PANEL_STATUS_LINE_HEADER = '┌─ Status ────';
- const PANEL_STATUS_LINE_DOCUMENTS = '│ Progress: %documentLeft:6s%/%documentTotal%';
+ const PANEL_STATUS_LINE_DOCUMENTS = '│ Progress: %documentLeft:6s%/%documentTotal% %progressStatus%';
// const PANEL_STATUS_LINE_DOCUMENTS_LEFT = '│ Document left:';
- const PANEL_STATUS_LINE_ERRORS = '│ Errors:';
+ const PANEL_STATUS_LINE_ERRORS = '│ Error: <comment>%errorCurrent:6s%</comment>/<comment>%errorTotal%</comment>';
+ const PANEL_STATUS_LINE_ERROR_MESSAGE = '│ Message: <comment>%errorMessage%</comment>';
+ const PANEL_STATUS_LINE_ERROR_EXCEPTION = '│ Exception: <comment>%errorException%</comment>';
+ const PANEL_STATUS_LINE_ERROR_INDEX = '│ Index: <comment>%errorIndex%</comment>';
+
+
const PANEL_STATUS_LINE_FOOTER = '└──';
const PANEL_LINE_EMPTY = '│ ';
const PANEL_COMMANDS_ROOT = 'root';
- const PANEL_COMMANDS_ROOT_LINE = '## q:quit ## p:pause';
+ const PANEL_COMMANDS_ROOT_LINE = '## <char>q</char>:quit ## <char>p</char>:pause ';
const PANEL_COMMANDS_PAUSED = 'paused';
- const PANEL_COMMANDS_PAUSED_LINE = '## q:quit ## u:unpause ## n:next';
-
+ const PANEL_COMMANDS_PAUSED_LINE = '## <char>q</char>:quit ## <char>u</char>:unpause ## <char>n</char>:next step';
+ const PANEL_COMMANDS_DONE = 'done';
+ const PANEL_COMMANDS_DONE_LINE = '## <char>q</char>:quit';
+ const PANEL_COMMANDS_ERRORS = 'errors';
+ const PANEL_COMMANDS_ERRORS_LINE = '## <char>f</char>:first error ## <char>h</char>/<char>j</char>:prec/next error ## <char>d</char>:delete error ## <char>l</char>:last error';
/** @var IUserManager */
private $userManager;
@@ -101,6 +112,12 @@ class Index extends ExtendedBase {
/** @var Runner */
private $runner;
+ /** @var array */
+ private $errors = [];
+
+ /** @var bool */
+ private $navigateLastError = true;
+
/**
* Index constructor.
@@ -161,19 +178,24 @@ class Index extends ExtendedBase {
*/
protected function execute(InputInterface $input, OutputInterface $output) {
+ /** do not get stuck while waiting interactive input */
readline_callback_handler_install(
'', function() {
}
);
-
stream_set_blocking(STDIN, false);
+ $outputStyle = new OutputFormatterStyle('white', 'black', ['bold']);
+ $output->getFormatter()
+ ->setStyle('char', $outputStyle);
+
$options = $this->generateIndexOptions($input);
$this->runner = new Runner($this->runningService, 'commandIndex', ['nextStep' => 'n']);
$this->runner->onKeyPress([$this, 'onKeyPressed']);
$this->runner->onNewAction([$this, 'onNewAction']);
- $this->runner->pause($options->getOption('pause', false));
+ $this->runner->onNewIndexError([$this, 'onNewIndexError']);
+ $this->runner->pause($options->getOption('paused', false));
$this->indexService->setRunner($this->runner);
$this->cliService->setRunner($this->runner);
@@ -185,7 +207,14 @@ class Index extends ExtendedBase {
$this->runner->sourceIsCommandLine($this, $output);
$this->runner->start();
+ if ($options->getOption('errors') === 'reset') {
+ $this->indexService->resetErrorsAll();
+ }
+
+ $this->testPlatform();
$this->cliService->runDisplay($output);
+ $this->generateIndexErrors();
+ $this->displayError();
$providers = $this->providerService->getProviders();
foreach ($providers as $provider) {
@@ -204,8 +233,22 @@ class Index extends ExtendedBase {
throw $e;
}
- $output->writeLn('done.');
+ $this->runner->setInfo('progressStatus', 'done');
$this->runner->stop();
+
+// while (true) {
+// $this->runner->updateAction('_indexOver', true);
+// $pressed = strtolower($this->updateAction(''));
+// if ($pressed === $this->keys['nextStep']) {
+// $this->pauseRunning(false);
+// break;
+// }
+// usleep(300000);
+// }
+
+
+// $output->writeLn('');
+
}
@@ -215,21 +258,38 @@ class Index extends ExtendedBase {
public function onKeyPressed($key) {
$key = strtolower($key);
if ($key === 'q') {
+ try {
+ $this->runner->stop();
+ } catch (TickDoesNotExistException $e) {
+ /** we do nohtin' */
+ }
exit();
}
$current = $this->cliService->currentPanel('commands');
- if ($current === self::PANEL_COMMANDS_ROOT) {
- if ($key === 'p') {
- $this->cliService->switchPanel('commands', self::PANEL_COMMANDS_PAUSED);
- $this->runner->pause(true);
- }
+ if ($current === self::PANEL_COMMANDS_ROOT && $key === 'p') {
+ $this->cliService->switchPanel('commands', self::PANEL_COMMANDS_PAUSED);
+ $this->runner->pause(true);
}
- if ($current === self::PANEL_COMMANDS_PAUSED) {
- if ($key === 'u') {
- $this->cliService->switchPanel('commands', self::PANEL_COMMANDS_ROOT);
- $this->runner->pause(false);
- }
+ if ($current === self::PANEL_COMMANDS_PAUSED && $key === 'u') {
+ $this->cliService->switchPanel('commands', self::PANEL_COMMANDS_ROOT);
+ $this->runner->pause(false);
+ }
+
+ if ($key === 'f') {
+ $this->displayError(-99);
+ }
+ if ($key === 'h') {
+ $this->displayError(-1);
+ }
+ if ($key === 'j') {
+ $this->displayError(1);
+ }
+ if ($key === 'l') {
+ $this->displayError(99);
+ }
+ if ($key === 'd') {
+ $this->deleteError();
}
}
@@ -251,6 +311,24 @@ class Index extends ExtendedBase {
/**
+ * @param array $error
+ */
+ public function onNewIndexError($error) {
+ $this->errors[] = $error;
+ $this->displayError();
+ }
+
+
+ /**
+ * @throws Exception
+ */
+ private function testPlatform() {
+ $platform = $this->platformService->getPlatform();
+ $platform->testPlatform();
+ }
+
+
+ /**
* @param IFullTextSearchProvider $provider
* @param IndexOptions $options
*
@@ -367,9 +445,9 @@ class Index extends ExtendedBase {
self::PANEL_STATUS_LINE_HEADER,
self::PANEL_STATUS_LINE_DOCUMENTS,
self::PANEL_STATUS_LINE_ERRORS,
- self::PANEL_LINE_EMPTY,
- self::PANEL_LINE_EMPTY,
- self::PANEL_LINE_EMPTY,
+ self::PANEL_STATUS_LINE_ERROR_MESSAGE,
+ self::PANEL_STATUS_LINE_ERROR_EXCEPTION,
+ self::PANEL_STATUS_LINE_ERROR_INDEX,
self::PANEL_STATUS_LINE_FOOTER,
]
);
@@ -386,12 +464,19 @@ class Index extends ExtendedBase {
]
);
+ $this->cliService->createPanel(
+ self::PANEL_COMMANDS_ERRORS, [
+ self::PANEL_COMMANDS_ERRORS_LINE
+ ]
+ );
$this->cliService->initDisplay();
$this->cliService->displayPanel('run', self::PANEL_RUN);
$this->cliService->displayPanel('topPanel', self::PANEL_INDEX);
$this->cliService->displayPanel('bottomPanel', self::PANEL_STATUS);
+ $this->cliService->displayPanel('errors', self::PANEL_COMMANDS_ERRORS);
+
if ($this->runner->isPaused()) {
$this->cliService->displayPanel('commands', self::PANEL_COMMANDS_PAUSED);
} else {
@@ -400,22 +485,181 @@ class Index extends ExtendedBase {
$this->runner->setInfoArray(
[
- 'userId' => '',
- 'providerName' => '',
- '_memory' => '',
- 'documentId' => '',
- 'action' => '',
- 'info' => '',
- 'title' => '',
- '_paused' => '',
- 'content' => '',
- 'resultColored' => '',
- 'documentLeft' => '',
- 'documentTotal' => ''
+ 'userId' => '',
+ 'providerName' => '',
+ '_memory' => '',
+ 'documentId' => '',
+ 'action' => '',
+ 'info' => '',
+ 'title' => '',
+ '_paused' => '',
+ 'content' => '',
+ 'resultColored' => '',
+ 'documentLeft' => '',
+ 'documentTotal' => '',
+ 'progressStatus' => '',
+ 'errorCurrent' => '0',
+ 'errorTotal' => '0',
+ 'errorMessage' => '',
+ 'errorException' => '',
+ 'errorIndex' => ''
]
);
}
+
+ /**
+ * @param int $pos
+ */
+ private function displayError($pos = 0) {
+ $total = sizeof($this->errors);
+
+ if ($total === 0) {
+ $this->runner->setInfoArray(
+ [
+ 'errorCurrent' => 0,
+ 'errorTotal' => 0,
+ ]
+ );
+
+ return;
+ }
+
+ $current = key($this->errors) + 1;
+ $error = $this->getNavigationError($pos, ($current === 1), ($current === $total));
+ $current = key($this->errors) + 1;
+
+ if ($error === false) {
+ return;
+ }
+
+ /** @var ModelIndex $index */
+ $index = $error['index'];
+ $errorIndex = '';
+ if ($index !== null) {
+ $errorIndex = $index->getProviderId() . ':' . $index->getDocumentId();
+ }
+
+ $this->runner->setInfoArray(
+ [
+ 'errorCurrent' => $current,
+ 'errorTotal' => $total,
+ 'errorMessage' => MiscService::get('message', $error, ''),
+ 'errorException' => MiscService::get('exception', $error, ''),
+ 'errorIndex' => $errorIndex
+ ]
+ );
+ }
+
+
+ /**
+ * @param int $pos
+ * @param bool $isFirst
+ * @param bool $isLast
+ *
+ * @return bool|array
+ */
+ private function getNavigationError($pos, $isFirst, $isLast) {
+
+ if ($pos === 0) {
+ if ($this->navigateLastError === true) {
+ return end($this->errors);
+ } else {
+ return current($this->errors);
+ }
+ }
+
+ $this->navigateLastError = false;
+ if ($pos === -99) {
+ return reset($this->errors);
+ }
+
+ if ($pos === -1 && !$isFirst) {
+ return prev($this->errors);
+ }
+
+ if ($pos === 1 && !$isLast) {
+ return next($this->errors);
+ }
+
+ if ($pos === 99) {
+ $this->navigateLastError = true;
+
+ return end($this->errors);
+ }
+
+ return false;
+ }
+
+
+ /**
+ *
+ */
+ private function generateIndexErrors() {
+ $indexes = $this->indexService->getErrorIndexes();
+
+ foreach ($indexes as $index) {
+ foreach ($index->getErrors() as $error) {
+ $this->errors[] = [
+ 'index' => $index,
+ 'message' => $error['message'],
+ 'exception' => $error['exception'],
+ 'severity' => $error['sev']
+ ];
+ }
+
+ }
+
+
+ }
+
+
+ /**
+ *
+ */
+ private function deleteError() {
+ $current = current($this->errors);
+ if ($current === false) {
+ return;
+ }
+
+ $this->runner->setInfoArray(
+ [
+ 'errorMessage' => '',
+ 'errorException' => '',
+ 'errorIndex' => ''
+ ]
+ );
+
+ $pos = key($this->errors);
+
+ /** @var ModelIndex $index */
+ $index = $current['index'];
+ $this->indexService->resetErrorFromIndex($index);
+
+ $errors = [];
+ foreach ($this->errors as $error) {
+ /** @var ModelIndex $errorIndex */
+ $errorIndex = $error['index'];
+ if ($index->getProviderId() === $errorIndex->getProviderId()
+ && $index->getDocumentId() === $errorIndex->getDocumentId()) {
+ continue;
+ }
+
+ $errors[] = $error;
+ }
+
+ $this->errors = $errors;
+ while (key($this->errors) < $pos) {
+ if (next($this->errors) === false) {
+ end($this->errors);
+ break;
+ }
+ }
+
+ $this->displayError();
+ }
+
}
diff --git a/lib/Db/CoreRequestBuilder.php b/lib/Db/CoreRequestBuilder.php
index 24574e2..84892fc 100644
--- a/lib/Db/CoreRequestBuilder.php
+++ b/lib/Db/CoreRequestBuilder.php
@@ -120,6 +120,18 @@ class CoreRequestBuilder {
/**
+ * Limit to the documentId
+ *
+ * @param IQueryBuilder $qb
+ * @param string $documentId
+ */
+ protected function limitToErr(IQueryBuilder &$qb) {
+ $expr = $qb->expr();
+ $qb->andWhere($expr->gte('err', $qb->createNamedParameter(1)));
+ }
+
+
+ /**
* Limit to documentIds
*
* @param IQueryBuilder $qb
@@ -167,7 +179,7 @@ class CoreRequestBuilder {
}
$orX = $expr->orX();
- foreach($values as $value) {
+ foreach ($values as $value) {
$orX->add($expr->eq($field, $qb->createNamedParameter($value)));
}
diff --git a/lib/Db/IndexesRequest.php b/lib/Db/IndexesRequest.php
index b2e9574..4bb4925 100644
--- a/lib/Db/IndexesRequest.php
+++ b/lib/Db/IndexesRequest.php
@@ -49,8 +49,8 @@ class IndexesRequest extends IndexesRequestBuilder {
->setValue('provider_id', $qb->createNamedParameter($index->getProviderId()))
->setValue('document_id', $qb->createNamedParameter($index->getDocumentId()))
->setValue('source', $qb->createNamedParameter($index->getSource()))
- ->setValue('err', $qb->createNamedParameter($index->getError()))
- ->setValue('message', $qb->createNamedParameter($index->getMessage()))
+ ->setValue('err', $qb->createNamedParameter($index->getErrorCount()))
+ ->setValue('message', $qb->createNamedParameter(json_encode($index->getErrors())))
->setValue('status', $qb->createNamedParameter($index->getStatus()))
->setValue('options', $qb->createNamedParameter(json_encode($index->getOptions())))
->setValue('indexed', $qb->createNamedParameter($index->getLastIndex()));
@@ -69,6 +69,63 @@ class IndexesRequest extends IndexesRequestBuilder {
*
* @return bool
*/
+ public function resetError(Index $index) {
+
+ try {
+ $this->getIndex($index->getProviderId(), $index->getDocumentId());
+ } catch (IndexDoesNotExistException $e) {
+ return false;
+ }
+
+ $qb = $this->getIndexesUpdateSql();
+ $qb->set('message', $qb->createNamedParameter(json_encode([])));
+ $qb->set('err', $qb->createNamedParameter(0));
+
+ $this->limitToProviderId($qb, $index->getProviderId());
+ $this->limitToDocumentId($qb, $index->getDocumentId());
+
+ $qb->execute();
+
+ return true;
+ }
+
+
+ /**
+ *
+ */
+ public function resetAllErrors() {
+ $qb = $this->getIndexesUpdateSql();
+ $qb->set('message', $qb->createNamedParameter(json_encode([])));
+ $qb->set('err', $qb->createNamedParameter(0));
+
+ $qb->execute();
+ }
+
+
+ /**
+ * @return ExtendedIndex[]
+ */
+ public function getErrorIndexes() {
+
+ $qb = $this->getIndexesSelectSql();
+ $this->limitToErr($qb);
+
+ $indexes = [];
+ $cursor = $qb->execute();
+ while ($data = $cursor->fetch()) {
+ $indexes[] = $this->parseIndexesSelectSql($data);
+ }
+ $cursor->closeCursor();
+
+ return $indexes;
+ }
+
+
+ /**
+ * @param Index $index
+ *
+ * @return bool
+ */
public function update(Index $index) {
try {
@@ -90,7 +147,7 @@ class IndexesRequest extends IndexesRequestBuilder {
$qb->set('indexed', $qb->createNamedParameter($index->getLastIndex()));
}
- $qb->set('message', $qb->createNamedParameter($index->getMessage()));
+ $qb->set('message', $qb->createNamedParameter(json_encode($index->getErrors())));
$this->limitToProviderId($qb, $index->getProviderId());
$this->limitToDocumentId($qb, $index->getDocumentId());
diff --git a/lib/Db/IndexesRequestBuilder.php b/lib/Db/IndexesRequestBuilder.php
index 647bb17..3f68e16 100644
--- a/lib/Db/IndexesRequestBuilder.php
+++ b/lib/Db/IndexesRequestBuilder.php
@@ -87,8 +87,7 @@ class IndexesRequestBuilder extends CoreRequestBuilder {
/** @noinspection PhpMethodParametersCountMismatchInspection */
$qb->select(
'li.owner_id', 'li.provider_id', 'li.document_id', 'li.source', 'li.status',
- 'li.options', 'li.err',
- 'li.message', 'li.indexed'
+ 'li.options', 'li.err', 'li.message', 'li.indexed'
)
->from(self::TABLE_INDEXES, 'li');
@@ -121,8 +120,8 @@ class IndexesRequestBuilder extends CoreRequestBuilder {
$index->setStatus($data['status'])
->setSource($data['source'])
->setOptions(json_decode($data['options'], true))
- ->setError($data['err'])
- ->setMessage($data['message'])
+ ->setErrorCount($data['err'])
+ ->setErrors(json_decode($data['message'], true))
->setOwnerId($data['owner_id'])
->setLastIndex($data['indexed']);
diff --git a/lib/Model/Index.php b/lib/Model/Index.php
index e5efa1a..d78e559 100644
--- a/lib/Model/Index.php
+++ b/lib/Model/Index.php
@@ -1,6 +1,6 @@
<?php
/**
- * FullTextSearch - Full text search framework for Nextcloud
+ * FullTextSearch - Full text search framework for extcloud
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
@@ -43,6 +43,11 @@ class Index implements \JsonSerializable {
const ERROR_FAILED2 = 2;
const ERROR_FAILED3 = 4;
+ const ERROR_SEV_1 = 1;
+ const ERROR_SEV_2 = 2;
+ const ERROR_SEV_3 = 3;
+ const ERROR_SEV_4 = 4;
+
/** @var string */
private $providerId;
@@ -65,8 +70,8 @@ class Index implements \JsonSerializable {
/** @var int */
private $err = 0;
- /** @var string */
- private $message;
+ /** @var array */
+ private $errors = [];
/** @var int */
private $lastIndex = 0;
@@ -226,7 +231,7 @@ class Index implements \JsonSerializable {
*
* @return $this
*/
- public function setError($err) {
+ public function setErrorCount($err) {
$this->err = $err;
return $this;
@@ -235,40 +240,62 @@ class Index implements \JsonSerializable {
/**
* @return int
*/
- public function getError() {
+ public function getErrorCount() {
return $this->err;
}
/**
- * @return $this
+ * @return array
*/
- public function incrementError() {
- $this->err++;
-
- return $this;
+ public function getLastError() {
+ return array_values(array_slice($this->errors, -1))[0];
}
/**
- * @return string
+ *
*/
- public function getMessage() {
- return $this->message;
+ public function resetErrors() {
+ $this->setErrors([]);
+ $this->setErrorCount(0);
}
/**
- * @param string $message
+ * @return array
+ */
+ public function getErrors() {
+ return $this->errors;
+ }
+
+ /**
+ * @param array $messages
*
* @return Index
*/
- public function setMessage($message) {
- $this->message = substr($message, 0, 3800);
+ public function setErrors($messages) {
+ $this->errors = $messages;
return $this;
}
/**
+ * @param string $message
+ * @param string $exception
+ * @param int $sev
+ */
+ public function addError($message, $exception = '', $sev = self::ERROR_SEV_3) {
+ $this->errors[] = [
+ 'message' => substr($message, 0, 1800),
+ 'exception' => $exception,
+ 'severity' => $sev
+ ];
+
+ $this->err++;
+ }
+
+
+ /**
* @param int $lastIndex
*
* @return $this
@@ -301,6 +328,8 @@ class Index implements \JsonSerializable {
'source' => $this->getSource(),
'documentId' => $this->getDocumentId(),
'lastIndex' => $this->getLastIndex(),
+ 'errors' => $this->getErrors(),
+ 'errorCount' => $this->getErrorCount(),
'status' => (int)$this->getStatus(),
'options' => $this->getOptions()
];
diff --git a/lib/Service/IndexService.php b/lib/Service/IndexService.php
index c81bc77..63bcee0 100644
--- a/lib/Service/IndexService.php
+++ b/lib/Service/IndexService.php
@@ -63,6 +63,10 @@ class IndexService {
/** @var Runner */
private $runner = null;
+ /** @var array */
+ private $queuedDeleteIndex = [];
+
+
/**
* IndexService constructor.
*
@@ -112,12 +116,12 @@ class IndexService {
* @param string $info
* @param string $value
*/
- private function updateRunnerInfo($info, $value) {
+ private function updateRunnerInfo($info, $value, $color = '') {
if ($this->runner === null) {
return;
}
- $this->runner->setInfo($info, $value);
+ $this->runner->setInfo($info, $value, $color);
}
/**
@@ -166,7 +170,7 @@ class IndexService {
//$maxSize = sizeof($documents);
$toIndex = $this->updateDocumentsWithCurrIndex($provider, $documents, $options);
- $this->indexChunks($platform, $provider, $toIndex);
+ $this->indexChunks($platform, $provider, $toIndex, $options);
// $this->updateRunnerInfoArray(
// [
@@ -186,7 +190,7 @@ class IndexService {
* @throws TickDoesNotExistException
*/
private function updateDocumentsWithCurrIndex(
- IFullTextSearchProvider $provider, array $documents, $options
+ IFullTextSearchProvider $provider, array $documents, IndexOptions $options
) {
$currIndex = $this->getProviderIndexFromProvider($provider);
@@ -201,6 +205,10 @@ class IndexService {
$index->setLastIndex();
}
+ if ($options->getOption('errors', '') !== 'ignore' && $index->getErrorCount() > 0) {
+ continue;
+ }
+
if ($options->getOption('force', false) === true) {
$index->setStatus(Index::INDEX_FULL);
}
@@ -254,24 +262,30 @@ class IndexService {
* @param IFullTextSearchPlatform $platform
* @param IFullTextSearchProvider $provider
* @param IndexDocument[] $documents
+ * @param IndexOptions $options
*
+ * @throws InterruptException
+ * @throws TickDoesNotExistException
* @throws Exception
*/
private function indexChunks(
- IFullTextSearchPlatform $platform, IFullTextSearchProvider $provider, $documents
+ IFullTextSearchPlatform $platform, IFullTextSearchProvider $provider, $documents,
+ IndexOptions $options
) {
- $chunkSize = $this->configService->getAppValue(ConfigService::CHUNK_INDEX);
+ $chunkSize = $options->getOption(
+ 'chunk', $this->configService->getAppValue(ConfigService::CHUNK_INDEX)
+ );
$max = sizeof($documents);
for ($i = 0; $i < $max; $i++) {
$this->updateRunnerAction('indexChunk', true);
try {
+ $this->updateRunnerInfoArray(['documentLeft' => sizeof($documents)]);
+
$chunk = array_splice($documents, 0, $chunkSize);
$this->indexChunk($platform, $provider, $chunk);
- $this->updateRunnerInfoArray(['documentLeft' => sizeof($documents)]);
-
/** @var IndexDocument $doc */
foreach ($chunk as $doc) {
$doc->__destruct(); // because.
@@ -296,6 +310,7 @@ class IndexService {
*
* @throws NoResultException
* @throws DatabaseException
+ * @throws Exception
*/
private function indexChunk(
IFullTextSearchPlatform $platform, IFullTextSearchProvider $provider, $chunk
@@ -306,7 +321,16 @@ class IndexService {
$documents = $provider->fillIndexDocuments($chunk);
$toIndex = $this->filterDocumentsToIndex($documents);
- $indexes = $platform->indexDocuments($provider, $toIndex);
+
+ $indexes = [];
+ foreach ($toIndex as $document) {
+ try {
+ $index = $this->indexDocument($platform, $provider, $document);
+ $indexes[] = $index;
+ } catch (\Exception $e) {
+ throw $e;
+ }
+ }
$this->updateIndexes($indexes);
}
@@ -315,7 +339,7 @@ class IndexService {
/**
* @param IndexDocument[] $documents
*
- * @return array
+ * @return IndexDocument[]
*/
private function filterDocumentsToIndex($documents) {
$toIndex = [];
@@ -337,6 +361,41 @@ class IndexService {
/**
* @param IFullTextSearchPlatform $platform
* @param IFullTextSearchProvider $provider
+ * @param IndexDocument $document
+ *
+ * @return
+ * @throws Exception
+ */
+ public function indexDocument(
+ IFullTextSearchPlatform $platform, IFullTextSearchProvider $provider, $document
+ ) {
+ $this->updateRunnerAction('indexDocument', true);
+ $this->updateRunnerInfoArray(
+ [
+ 'documentId' => $document->getId(),
+ 'title' => $document->getTitle(),
+ 'content' => $document->getContentSize()
+ ]
+ );
+
+ $index = null;
+ $document->getIndex()
+ ->resetErrors();
+ try {
+ $index = $platform->indexDocument($provider, $document);
+ } catch (Exception $e) {
+ if ($this->runner->isStrict()) {
+ throw $e;
+ }
+ }
+
+ return $index;
+ }
+
+
+ /**
+ * @param IFullTextSearchPlatform $platform
+ * @param IFullTextSearchProvider $provider
* @param Index $index
*
* @internal param int|string $documentId
@@ -372,11 +431,11 @@ class IndexService {
* @throws DatabaseException
*/
public function updateIndexes($indexes) {
-
try {
foreach ($indexes as $index) {
$this->updateIndex($index);
}
+ $this->resetErrorFromQueue();
} catch (Exception $e) {
throw new DatabaseException($e->getMessage());
}
@@ -390,6 +449,7 @@ class IndexService {
*/
private function updateIndex(Index $index) {
+ $this->updateIndexError($index);
if ($index->isStatus(Index::INDEX_REMOVE)) {
if ($index->isStatus(Index::INDEX_DONE)) {
@@ -413,6 +473,11 @@ class IndexService {
}
+ private function updateIndexError(Index $index) {
+
+ }
+
+
/**
* @param string $providerId
* @param array $documentIds
@@ -443,6 +508,41 @@ class IndexService {
/**
+ * @param Index $index
+ */
+ public function resetErrorFromIndex(Index $index) {
+ if (!$this->indexesRequest->resetError($index)) {
+ $this->queuedDeleteIndex[] = $index;
+ }
+ }
+
+
+ /**
+ *
+ */
+ private function resetErrorFromQueue() {
+ foreach ($this->queuedDeleteIndex as $index) {
+ $this->indexesRequest->resetError($index);
+ }
+ }
+
+ /**
+ *
+ */
+ public function resetErrorsAll() {
+ $this->indexesRequest->resetAllErrors();
+ }
+
+
+ /**
+ * @return ExtendedIndex[]
+ */
+ public function getErrorIndexes() {
+ return $this->indexesRequest->getErrorIndexes();
+ }
+
+
+ /**
* @param string $providerId
* @param array $documentId
*