diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2018-01-13 14:08:52 +0300 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2018-01-13 14:08:52 +0300 |
commit | 75bb68ebdf3280c985efc7ded4fd4e0c2118fbb6 (patch) | |
tree | 24ea5b5e2e37a294a26c6515dd59ab83659d4b25 | |
parent | 93bf15aa2ba85183387b3056586211e1e1d64d5c (diff) |
index cleaning
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
-rw-r--r-- | lib/Api/v1/FullTextSearch.php | 1 | ||||
-rw-r--r-- | lib/Model/Index.php | 17 | ||||
-rw-r--r-- | lib/Model/ProviderIndexes.php | 18 | ||||
-rw-r--r-- | lib/Service/IndexService.php | 42 |
4 files changed, 52 insertions, 26 deletions
diff --git a/lib/Api/v1/FullTextSearch.php b/lib/Api/v1/FullTextSearch.php index 5f870b7..d97135a 100644 --- a/lib/Api/v1/FullTextSearch.php +++ b/lib/Api/v1/FullTextSearch.php @@ -97,6 +97,7 @@ class FullTextSearch { ->getIndex($providerId, $documentId); } + /** * @param $providerId * @param $documentId diff --git a/lib/Model/Index.php b/lib/Model/Index.php index f25da7e..9924871 100644 --- a/lib/Model/Index.php +++ b/lib/Model/Index.php @@ -30,11 +30,14 @@ class Index implements \JsonSerializable { const INDEX_OK = 1; const INDEX_IGNORE = 2; + const INDEX_META = 4; const INDEX_CONTENT = 8; const INDEX_FULL = 12; const INDEX_REMOVE = 16; - const INDEX_FAILED = 32; + + const INDEX_DONE = 32; + const INDEX_FAILED = 64; const ERROR_FAILED = 1; const ERROR_FAILED2 = 2; @@ -126,12 +129,22 @@ class Index implements \JsonSerializable { /** * @param int $status * - * @return int + * @return bool */ public function isStatus($status) { return ((int)$status & $this->getStatus()); } + /** + * @param int $status + */ + public function unsetStatus($status) { + if (!$this->isStatus($status)) { + return; + } + + $this->status -= $status; + } /** * @param int $err diff --git a/lib/Model/ProviderIndexes.php b/lib/Model/ProviderIndexes.php index 510666c..2915181 100644 --- a/lib/Model/ProviderIndexes.php +++ b/lib/Model/ProviderIndexes.php @@ -62,22 +62,4 @@ class ProviderIndexes { } - public function isDocumentIndexUpToDate(IndexDocument $document) { - $index = $this->getIndex($document->getId()); - if ($index === null) { - $index = new Index($document->getProviderId(), $document->getId()); - $index->setStatus(Index::INDEX_FULL); - $index->setLastIndex(); - } - - $document->setIndex($index); - - if ($index->getStatus() !== Index::INDEX_OK) { - return false; - } - - return ($index->getLastIndex() >= $document->getModifiedTime()); - } - - }
\ No newline at end of file diff --git a/lib/Service/IndexService.php b/lib/Service/IndexService.php index 69024c9..43ca4ae 100644 --- a/lib/Service/IndexService.php +++ b/lib/Service/IndexService.php @@ -121,27 +121,36 @@ class IndexService { //$maxSize = sizeof($documents); - $toIndex = $this->updateDocumentsWithCurrentIndex($provider, $documents); + $toIndex = $this->updateDocumentsWithCurrIndex($provider, $documents); $this->indexChunks($platform, $provider, $toIndex); } /** * @param IFullTextSearchProvider $provider - * @param IndexDocument[] $items + * @param IndexDocument[] $documents * * @return IndexDocument[] * @throws InterruptException * @throws TickDoesNotExistException */ - private function updateDocumentsWithCurrentIndex(IFullTextSearchProvider $provider, array $items) { + private function updateDocumentsWithCurrIndex(IFullTextSearchProvider $provider, array $documents) { $currIndex = $this->getProviderIndexFromProvider($provider); $result = []; - foreach ($items as $item) { + foreach ($documents as $document) { $this->updateRunner('compareWithCurrentIndex'); - if (!$currIndex->isDocumentIndexUpToDate($item)) { - $result[] = $item; + + $index = $currIndex->getIndex($document->getId()); + if ($index === null) { + $index = new Index($document->getProviderId(), $document->getId()); + $index->setStatus(Index::INDEX_FULL); + $index->setLastIndex(); + } + + $document->setIndex($index); + if (!$this->isDocumentUpToDate($provider, $document)) { + $result[] = $document; } } @@ -152,6 +161,27 @@ class IndexService { /** * @param IFullTextSearchProvider $provider + * @param IndexDocument $document + * + * @return bool + */ + private function isDocumentUpToDate(IFullTextSearchProvider $provider, IndexDocument $document) { + $index = $document->getIndex(); + + if (!$index->isStatus(Index::INDEX_OK)) { + return false; + } + + if ($index->isStatus(Index::INDEX_META) || $index->isStatus(Index::INDEX_CONTENT)) { + return false; + } + + return $provider->isDocumentUpToDate($document); + } + + + /** + * @param IFullTextSearchProvider $provider * * @return ProviderIndexes */ |