diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2018-08-27 15:18:09 +0300 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2018-08-27 15:18:09 +0300 |
commit | 9ce4114732c11ea27a8ea6536854cd4cabceb7d5 (patch) | |
tree | 90d05557076fa6c0cdb787d82ba27a41e92087c7 /lib | |
parent | c701bc2440db875e46fd57f2a6a52f37eb8b04d7 (diff) |
no more chunk
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/IFullTextSearchProvider.php | 10 | ||||
-rw-r--r-- | lib/Provider/TestProvider.php | 11 | ||||
-rw-r--r-- | lib/Service/ConfigService.php | 2 | ||||
-rw-r--r-- | lib/Service/IndexService.php | 127 | ||||
-rw-r--r-- | lib/Service/SettingsService.php | 4 |
5 files changed, 79 insertions, 75 deletions
diff --git a/lib/IFullTextSearchProvider.php b/lib/IFullTextSearchProvider.php index 6ff76ea..7d73229 100644 --- a/lib/IFullTextSearchProvider.php +++ b/lib/IFullTextSearchProvider.php @@ -112,7 +112,7 @@ interface IFullTextSearchProvider { /** * fill a chunk of documents with more content, prior to index. - * + * @deprecated * @param IndexDocument[] $chunk * * @return IndexDocument[] @@ -121,6 +121,14 @@ interface IFullTextSearchProvider { /** + * fill document with more content, prior to index. + * + * @param IndexDocument $document + */ +// public function fillIndexDocument($document); + + + /** * @param IndexDocument $document * * @return bool diff --git a/lib/Provider/TestProvider.php b/lib/Provider/TestProvider.php index d4a47a1..3880893 100644 --- a/lib/Provider/TestProvider.php +++ b/lib/Provider/TestProvider.php @@ -164,6 +164,7 @@ class TestProvider implements IFullTextSearchProvider { $result[] = $this->testService->generateIndexDocumentContentLicense($this->indexOptions); $result[] = $this->testService->generateIndexDocumentSimple($this->indexOptions); + // $result[] = $this->testService->generateIndexDocuments(TestService::DOCUMENT_TEST_INDEX3); return $result; @@ -176,6 +177,7 @@ class TestProvider implements IFullTextSearchProvider { * * @param IndexDocument[] $chunk * + * @deprecated * @return IndexDocument[] */ public function fillIndexDocuments($chunk) { @@ -184,6 +186,15 @@ class TestProvider implements IFullTextSearchProvider { /** + * generate documents prior to the indexing. + * + * @param IndexDocument $document + */ + public function fillIndexDocument(IndexDocument $document) { + } + + + /** * @param IndexDocument $document * * @return bool diff --git a/lib/Service/ConfigService.php b/lib/Service/ConfigService.php index aa89352..cac5dd3 100644 --- a/lib/Service/ConfigService.php +++ b/lib/Service/ConfigService.php @@ -36,14 +36,12 @@ class ConfigService { const APP_NAVIGATION = 'app_navigation'; const SEARCH_PLATFORM = 'search_platform'; - const CHUNK_INDEX = 'index_chunk'; const PROVIDER_INDEXED = 'provider_indexed'; const CRON_LAST_ERR_RESET = 'cron_err_reset'; /** @var array */ public $defaults = [ self::SEARCH_PLATFORM => '', - self::CHUNK_INDEX => '20', self::APP_NAVIGATION => '0', self::PROVIDER_INDEXED => '', self::CRON_LAST_ERR_RESET => '0' diff --git a/lib/Service/IndexService.php b/lib/Service/IndexService.php index 2c069e3..6428084 100644 --- a/lib/Service/IndexService.php +++ b/lib/Service/IndexService.php @@ -269,94 +269,69 @@ class IndexService { * @throws TickDoesNotExistException * @throws Exception */ - private function indexChunks( + private function indexDocuments( IFullTextSearchPlatform $platform, IFullTextSearchProvider $provider, $documents, IndexOptions $options ) { - $chunkSize = $options->getOption( - 'chunk', $this->configService->getAppValue(ConfigService::CHUNK_INDEX) - ); - - $max = sizeof($documents); - for ($i = 0; $i < $max; $i++) { - $this->updateRunnerAction('indexChunk', true); + while ($document = array_shift($documents)) { try { - $this->updateRunnerInfoArray(['documentLeft' => sizeof($documents)]); - - $chunk = array_splice($documents, 0, $chunkSize); - $this->indexChunk($platform, $provider, $chunk); - - /** @var IndexDocument $doc */ - foreach ($chunk as $doc) { - $doc->__destruct(); // because. - } - } catch (NoResultException $e) { - $this->updateRunnerInfoArray(['documentLeft' => 0]); - - return; - } catch (Exception $e) { - throw $e; + $this->updateRunnerInfoArray( + [ + 'documentCurrent' => ($this->currentTotalDocuments - sizeof($documents) - 1) + ] + ); + $this->updateRunnerAction('fillDocument', true); + $this->updateRunnerInfoArray( + [ + 'documentId' => $document->getId(), + 'title' => '', + 'content' => '', + 'status' => '', + 'statusColored' => '' + ] + ); + + $provider->fillIndexDocument($document); + $this->updateRunnerInfoArray( + [ + 'title' => $document->getTitle(), + 'content' => $document->getContentSize() + ] + ); + $this->filterDocumentBeforeIndex($document); + + } catch (NotIndexableDocumentException $e) { + continue; } - } - $this->updateRunnerAction('indexChunk', true); - } + $index = $this->indexDocument($platform, $provider, $document); + $this->updateIndex($index); + $this->duplicateInfoAsLast(); - /** - * @param IFullTextSearchPlatform $platform - * @param IFullTextSearchProvider $provider - * @param IndexDocument[] $chunk - * - * @throws NoResultException - * @throws DatabaseException - * @throws Exception - */ - private function indexChunk( - IFullTextSearchPlatform $platform, IFullTextSearchProvider $provider, $chunk - ) { - if (sizeof($chunk) === 0) { - throw new NoResultException(); - } - - $documents = $provider->fillIndexDocuments($chunk); - $toIndex = $this->filterDocumentsToIndex($documents); - - $indexes = []; - foreach ($toIndex as $document) { - try { - $index = $this->indexDocument($platform, $provider, $document); - $indexes[] = $index; - } catch (\Exception $e) { - throw $e; - } + $document->__destruct(); + unset($document); } - - $this->updateIndexes($indexes); } /** - * @param IndexDocument[] $documents + * @param IndexDocument $document * - * @return IndexDocument[] + * @throws NotIndexableDocumentException */ - private function filterDocumentsToIndex($documents) { - $toIndex = []; - foreach ($documents as $document) { - // TODO - rework the index/not_index - $index = $document->getIndex(); - $access = $document->getAccess(); + private function filterDocumentBeforeIndex(IndexDocument $document) { + // TODO - rework the index/not_index + $index = $document->getIndex(); + $access = $document->getAccess(); // INDEX_IGNORE is not used anymore, as we use addError() - if ($access !== null && !$index->isStatus(Index::INDEX_IGNORE)) { - $index->setOwnerId($access->getOwnerId()); - $toIndex[] = $document; - } + if ($access === null || $index->isStatus(Index::INDEX_IGNORE)) { + throw new NotIndexableDocumentException(); } - return $toIndex; + $index->setOwnerId($access->getOwnerId()); } @@ -405,6 +380,13 @@ class IndexService { IFullTextSearchPlatform $platform, IFullTextSearchProvider $provider, Index $index ) { $document = null; + $this->updateRunnerInfoArray( + [ + 'providerName' => $provider->getName(), + 'userId' => $index->getOwnerId(), + ] + ); + if (!$index->isStatus(Index::INDEX_REMOVE)) { try { $document = $provider->updateDocument($index); @@ -420,6 +402,15 @@ class IndexService { return; } + $this->updateRunnerAction('indexDocument', true); + $this->updateRunnerInfoArray( + [ + 'documentId' => $document->getId(), + 'title' => $document->getTitle(), + 'content' => $document->getContentSize() + ] + ); + $document->getIndex() ->resetErrors(); $index = $platform->indexDocument($provider, $document); diff --git a/lib/Service/SettingsService.php b/lib/Service/SettingsService.php index d035c7a..f32f38e 100644 --- a/lib/Service/SettingsService.php +++ b/lib/Service/SettingsService.php @@ -73,10 +73,6 @@ class SettingsService { * @return bool */ public function checkConfig($data) { - if (!is_numeric($data['index_chunk'])) { - return false; - } - return true; } |