diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2017-12-26 15:02:40 +0300 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2017-12-26 15:02:40 +0300 |
commit | 480de70f60ae666a474ea623e01c9338f4d66038 (patch) | |
tree | b98eaa45273af3aa3b3497d0c121da72ed1b7ea2 /lib/Model | |
parent | ca7b3d05e6f592e144ebae6f696a76cefd04f83e (diff) |
nextant v2
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib/Model')
-rw-r--r-- | lib/Model/DocumentAccess.php | 193 | ||||
-rw-r--r-- | lib/Model/ExtendedBase.php | 73 | ||||
-rw-r--r-- | lib/Model/ExtendedIndex.php | 36 | ||||
-rw-r--r-- | lib/Model/ExtendedTick.php | 65 | ||||
-rw-r--r-- | lib/Model/Index.php | 190 | ||||
-rw-r--r-- | lib/Model/IndexDocument.php | 421 | ||||
-rw-r--r-- | lib/Model/ProviderIndexes.php | 84 | ||||
-rw-r--r-- | lib/Model/Runner.php | 188 | ||||
-rw-r--r-- | lib/Model/SearchResult.php | 128 | ||||
-rw-r--r-- | lib/Model/Tick.php | 191 |
10 files changed, 1569 insertions, 0 deletions
diff --git a/lib/Model/DocumentAccess.php b/lib/Model/DocumentAccess.php new file mode 100644 index 0000000..c2b542a --- /dev/null +++ b/lib/Model/DocumentAccess.php @@ -0,0 +1,193 @@ +<?php +/** + * FullNextSearch - Full Text Search your Nextcloud. + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Maxence Lange <maxence@artificial-owl.com> + * @copyright 2017 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * + */ + +namespace OCA\FullNextSearch\Model; + + +class DocumentAccess implements \JsonSerializable { + + /** @var string */ + private $ownerId; + + /** @var string */ + private $viewerId; + + /** @var array */ + private $users = []; + + /** @var array */ + private $groups = []; + + /** @var array */ + private $circles = []; + + /** @var array */ + private $links = []; + + /** + * DocumentAccess constructor. + * + * @param string $ownerId + */ + public function __construct($ownerId = '') { + $this->setOwnerId($ownerId); + } + + + /** + * @param $ownerId + * + * @return $this + */ + public function setOwnerId($ownerId) { + if ($ownerId === false) { + $ownerId = ''; + } + $this->ownerId = $ownerId; + + return $this; + } + + + /** + * @return string + */ + public function getOwnerId() { + return $this->ownerId; + } + + + /** + * @param string $viewerId + */ + public function setViewerId($viewerId) { + $this->viewerId = $viewerId; + } + + /** + * @return string + */ + public function getViewerId() { + return $this->viewerId; + } + + + /** + * @param array $users + */ + public function setUsers($users) { + $this->users = $users; + } + + /** + * @return array + */ + public function getUsers() { + return $this->users; + } + + /** + * @param array $users + */ + public function addUsers($users) { + $this->users = array_merge($this->users, $users); + } + + + /** + * @param array $groups + */ + public function setGroups($groups) { + $this->groups = $groups; + } + + /** + * @return array + */ + public function getGroups() { + return $this->groups; + } + + + /** + * @param array $groups + */ + public function addGroups($groups) { + $this->groups = array_merge($this->groups, $groups); + } + + + /** + * @param array $circles + */ + public function setCircles($circles) { + $this->circles = $circles; + } + + /** + * @return array + */ + public function getCircles() { + return $this->circles; + } + + /** + * @param array $circles + */ + public function addCircles($circles) { + $this->circles = array_merge($this->circles, $circles); + } + + /** + * @param array $links + */ + public function setLinks($links) { + $this->links = $links; + } + + /** + * @return array + */ + public function getLinks() { + return $this->links; + } + + + /** + * + */ + public function jsonSerialize() { + return [ + 'ownerId' => $this->getOwnerId(), + 'viewerId' => $this->getViewerId(), + 'users' => $this->getUsers(), + 'groups' => $this->getGroups(), + 'circles' => $this->getCircles(), + 'links' => $this->getLinks() + ]; + } +}
\ No newline at end of file diff --git a/lib/Model/ExtendedBase.php b/lib/Model/ExtendedBase.php new file mode 100644 index 0000000..6f7f3da --- /dev/null +++ b/lib/Model/ExtendedBase.php @@ -0,0 +1,73 @@ +<?php +/** + * FullNextSearch - Full Text Search your Nextcloud. + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Maxence Lange <maxence@artificial-owl.com> + * @copyright 2017 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * + */ + + +namespace OCA\FullNextSearch\Model; + +use OC\Core\Command\Base; +use OCA\FullNextSearch\Exceptions\InterruptException; +use Symfony\Component\Console\Output\OutputInterface; + + +class ExtendedBase extends Base { + + /** @var OutputInterface */ + private $output; + + public function __construct() { + parent::__construct(); + } + + + /** + * @return bool|void + * @throws InterruptException + */ + public function hasBeenInterrupted() { + if (parent::hasBeenInterrupted()) { + throw new InterruptException('Interrupted by user.'); + } + } + + + /** + * @param OutputInterface $output + * + * @deprecated + */ + public function setOutput(OutputInterface $output) { + $this->output = $output; + } + + /** + * @return OutputInterface + * @deprecated + */ + public function getOutput() { + return $this->output; + } +}
\ No newline at end of file diff --git a/lib/Model/ExtendedIndex.php b/lib/Model/ExtendedIndex.php new file mode 100644 index 0000000..9dea110 --- /dev/null +++ b/lib/Model/ExtendedIndex.php @@ -0,0 +1,36 @@ +<?php +/** + * FullNextSearch - Full Text Search your Nextcloud. + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Maxence Lange <maxence@artificial-owl.com> + * @copyright 2017 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * + */ + + +namespace OCA\FullNextSearch\Model; + + +class ExtendedIndex extends Index { + + + +}
\ No newline at end of file diff --git a/lib/Model/ExtendedTick.php b/lib/Model/ExtendedTick.php new file mode 100644 index 0000000..806bdf9 --- /dev/null +++ b/lib/Model/ExtendedTick.php @@ -0,0 +1,65 @@ +<?php +/** + * FullNextSearch - Full Text Search your Nextcloud. + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Maxence Lange <maxence@artificial-owl.com> + * @copyright 2017 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * + */ + + +namespace OCA\FullNextSearch\Model; + + +class ExtendedTick extends Tick { + + /** + * @param string $key + * @param string|int $value + * + * @return $this + */ + public function setInfo($key, $value) { + $this->data[$key] = $value; + + return $this; + } + + public function unsetInfo($key) { + unset($this->data[$key]); + } + + /** + * @param $key + * @param int|string $default + * + * @return int|string + */ + public function getInfo($key, $default = '') { + if (!array_key_exists($key, $this->data)) { + return $default; + } + + return $this->data[$key]; + + } + +}
\ No newline at end of file diff --git a/lib/Model/Index.php b/lib/Model/Index.php new file mode 100644 index 0000000..bcce175 --- /dev/null +++ b/lib/Model/Index.php @@ -0,0 +1,190 @@ +<?php +/** + * FullNextSearch - Full Text Search your Nextcloud. + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Maxence Lange <maxence@artificial-owl.com> + * @copyright 2017 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * + */ + +namespace OCA\FullNextSearch\Model; + +class Index implements \JsonSerializable { + + const STATUS_INDEX_IGNORE = 16; + const STATUS_INDEX_THIS = 1; + const STATUS_INDEX_DONE = 2; + const STATUS_REMOVE_DOCUMENT = 4; + const STATUS_DOCUMENT_REMOVED = 8; + + const ERROR_FAILED = 1; + const ERROR_FAILED2 = 2; + const ERROR_FAILED3 = 4; + + + /** @var string */ + private $providerId; + + /** @var string */ + private $documentId; + + /** @var string */ + private $ownerId = ''; + + /** @var int */ + private $status = 0; + + /** @var int */ + private $err = 0; + + /** @var string */ + private $lastIndex = '0'; + + + public function __construct($providerId, $documentId) { + $this->providerId = $providerId; + $this->documentId = $documentId; + } + + + /** + * @return string + */ + public function getProviderId() { + return $this->providerId; + } + + /** + * @return string + */ + public function getDocumentId() { + return $this->documentId; + } + + + /** + * @param string $ownerId + * + * @return $this + */ + public function setOwnerId($ownerId) { + $this->ownerId = $ownerId; + + return $this; + } + + /** + * @return string + */ + public function getOwnerId() { + return $this->ownerId; + } + + + /** + * @param int $status + * @param bool $reset + * + * @return $this + */ + public function setStatus($status, $reset = false) { + if ($reset === true) { + $this->status = $status; + } else if (!$this->isStatus($status)) { + $this->status += $status; + } + + return $this; + } + + /** + * @return int + */ + public function getStatus() { + return $this->status; + } + + /** + * @param int $status + * + * @return int + */ + public function isStatus($status) { + return ((int)$status & $this->getStatus()); + } + + + /** + * @param string $err + * + * @return $this + */ + public function setError($err) { + $this->err = $err; + + return $this; + } + + /** + * @return int + */ + public function getError() { + return $this->err; + } + + + /** + * @param string $lastIndex + * + * @return $this + */ + public function setLastIndex($lastIndex = '') { + if ($lastIndex === '') { + $lastIndex = time(); + } + + $this->lastIndex = $lastIndex; + + return $this; + } + + /** + * @return string + */ + public function getLastIndex() { + return $this->lastIndex; + } + + + /** + * @return array + */ + public function jsonSerialize() { + return [ + 'ownerId' => $this->getOwnerId(), + 'providerId' => $this->getProviderId(), + 'documentId' => $this->getDocumentId(), + 'lastIndex' => $this->getLastIndex(), + 'status' => (int)$this->getStatus() + ]; + } + +}
\ No newline at end of file diff --git a/lib/Model/IndexDocument.php b/lib/Model/IndexDocument.php new file mode 100644 index 0000000..a600887 --- /dev/null +++ b/lib/Model/IndexDocument.php @@ -0,0 +1,421 @@ +<?php +/** + * FullNextSearch - Full Text Search your Nextcloud. + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Maxence Lange <maxence@artificial-owl.com> + * @copyright 2017 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * + */ + +namespace OCA\FullNextSearch\Model; + +class IndexDocument implements \JsonSerializable { + + const NOT_ENCODED = 0; + const ENCODED_BASE64 = 1; + + /** @var string|int */ + private $id; + + /** @var string */ + private $providerId; + + /** @var DocumentAccess */ + private $access; + + /** @var Index */ + private $index; + + /** @var int */ + private $modifiedTime = 0; + + /** @var array */ + private $tags = []; + + /** @var string */ + private $title; + + /** @var string */ + private $content; + + /** @var string */ + private $link = ''; + + /** @var array */ + private $more = []; + + /** @var array */ + private $excerpts = []; + + /** @var string */ + private $score; + + /** @var array */ + private $info = []; + + /** @var int */ + private $contentEncoded; + + public function __construct($providerId, $id) { + $this->providerId = $providerId; + $this->id = $id; + } + + + /** + * @param string $id + * + * @return $this + */ + public function setId($id) { + $this->id = $id; + + return $this; + } + + /** + * @return string + */ + public function getId() { + return $this->id; + } + + + /** + * @param string $providerId + * + * @return $this + */ + public function setProviderId($providerId) { + $this->providerId = $providerId; + + return $this; + } + + /** + * @return string + */ + public function getProviderId() { + return $this->providerId; + } + + + /** + * @param Index $index + */ + public function setIndex(Index $index) { + $this->index = $index; + } + + /** + * @return Index + */ + public function getIndex() { + return $this->index; + } + + + /** + * @param int $modifiedTime + * + * @return $this + */ + public function setModifiedTime($modifiedTime) { + $this->modifiedTime = $modifiedTime; + + return $this; + } + + /** + * @return int + */ + public function getModifiedTime() { + return $this->modifiedTime; + } + + /** + * @param int $time + * + * @return bool + */ + public function isOlderThan($time) { + return ($this->modifiedTime < $time); + } + + + /** + * @param DocumentAccess $access + * + * @return $this + */ + public function setAccess(DocumentAccess $access) { + $this->access = $access; + + return $this; + } + + /** + * @return DocumentAccess + */ + public function getAccess() { + return $this->access; + } + + + /** + * @param array $tags + * + * @return $this + */ + public function setTags($tags) { + $this->tags = $tags; + + return $this; + } + + /** + * @return array + */ + public function getTags() { + return $this->tags; + } + + /** + * @param $tag + * + * @return $this + */ + public function addTag($tag) { + $this->tags[] = $tag; + + return $this; + } + + + /** + * @param string $title + * + * @return $this + */ + public function setTitle($title) { + $this->title = $title; + + return $this; + } + + /** + * @return string + */ + public function getTitle() { + return $this->title; + } + + + /** + * @param string $content + * @param int $encoded + * + * @return $this + */ + public function setContent($content, $encoded = 0) { + $this->content = $content; + $this->contentEncoded = $encoded; + + return $this; + } + + /** + * @return string + */ + public function getContent() { + return $this->content; + } + + + /** + * @return int + */ + public function isContentEncoded() { + return $this->contentEncoded; + } + + + /** + * @param string $link + * + * @return $this + */ + public function setLink($link) { + $this->link = $link; + + return $this; + } + + /** + * @return string + */ + public function getLink() { + return $this->link; + } + + + /** + * @param array $more + * + * @return $this + */ + public function setMore($more) { + $this->more = $more; + + return $this; + } + + /** + * @return array + */ + public function getMore() { + return $this->more; + } + + + /** + * @param array $excerpts + * + * @return $this + */ + public function setExcerpts($excerpts) { + $this->excerpts = $excerpts; + + return $this; + } + + /** + * @return array + */ + public function getExcerpts() { + return $this->excerpts; + } + + /** + * @param string $excerpt + */ + public function addExcerpt($excerpt) { + $this->excerpts[] = $excerpt; + } + + + /** + * @param string $score + * + * @return $this + */ + public function setScore($score) { + $this->score = $score; + + return $this; + } + + /** + * @return string + */ + public function getScore() { + return $this->score; + } + + + /** + * @param string $info + * @param mixed $value + * + * @return $this + */ + public function setInfo($info, $value) { + $this->info[$info] = $value; + + return $this; + } + + /** + * @param string $info + * @param mixed $default + * + * @return mixed + */ + public function getInfo($info, $default = '') { + if (!key_exists($info, $this->info)) { + return $default; + } + + return $this->info[$info]; + } + + + /** + * @return array + */ + public function getInfoAll() { + + $info = []; + foreach ($this->info as $k => $v) { + if (substr($k, 0, 1) === '_') { + continue; + } + + $info[$k] = $v; + } + + return $info; + } + + + public function __destruct() { + unset($this->id); + unset($this->providerId); + unset($this->access); + unset($this->modifiedTime); + unset($this->title); + unset($this->content); + unset($this->link); + unset($this->more); + unset($this->excerpts); + unset($this->score); + unset($this->info); + unset($this->contentEncoded); + } + + /** + * @return array + */ + public function jsonSerialize() { + return [ + 'id' => $this->getId(), + 'providerId' => $this->getProviderId(), + 'access' => $this->getAccess(), + 'modifiedTime' => $this->getModifiedTime(), + 'title' => $this->getTitle(), + 'link' => $this->getLink(), + 'more' => $this->getMore(), + 'excerpts' => $this->getExcerpts(), + 'score' => $this->getScore() + ]; + } + +}
\ No newline at end of file diff --git a/lib/Model/ProviderIndexes.php b/lib/Model/ProviderIndexes.php new file mode 100644 index 0000000..dc838c2 --- /dev/null +++ b/lib/Model/ProviderIndexes.php @@ -0,0 +1,84 @@ +<?php +/** + * FullNextSearch - Full Text Search your Nextcloud. + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Maxence Lange <maxence@artificial-owl.com> + * @copyright 2017 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * + */ + + +namespace OCA\FullNextSearch\Model; + +class ProviderIndexes { + + /** @var Index[] */ + private $indexes; + + + public function __construct($indexes) { + $this->indexes = $indexes; + } + + + /** + * @return Index[] + */ + public function getIndexes() { + return $this->indexes; + } + + + /** + * @param string $documentId + * + * @return null|Index + */ + public function getIndex($documentId) { + foreach ($this->indexes as $index) { + if ($index->getDocumentId() === (string)$documentId) { + return $index; + } + } + + return null; + } + + + public function isDocumentIndexUpToDate(IndexDocument $document) { + $index = $this->getIndex($document->getId()); + if ($index === null) { + $index = new Index($document->getProviderId(), $document->getId()); + $index->setStatus(Index::STATUS_INDEX_THIS); + $index->setLastIndex(); + } + + $document->setIndex($index); + + if ($index->getStatus() !== Index::STATUS_INDEX_DONE) { + return false; + } + + return ($index->getLastIndex() >= $document->getModifiedTime()); + } + + +}
\ No newline at end of file diff --git a/lib/Model/Runner.php b/lib/Model/Runner.php new file mode 100644 index 0000000..cf6c15b --- /dev/null +++ b/lib/Model/Runner.php @@ -0,0 +1,188 @@ +<?php +/** + * FullNextSearch - Full Text Search your Nextcloud. + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Maxence Lange <maxence@artificial-owl.com> + * @copyright 2017 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * + */ + + +namespace OCA\FullNextSearch\Model; + +use Exception; +use OCA\FullNextSearch\Exceptions\InterruptException; +use OCA\FullNextSearch\Exceptions\RunnerAlreadyUpException; +use OCA\FullNextSearch\Exceptions\TickDoesNotExistException; +use OCA\FullNextSearch\Exceptions\TickIsNotAliveException; +use OCA\FullNextSearch\Service\RunningService; +use Symfony\Component\Console\Output\OutputInterface; + + +class Runner { + + + const TICK_TTL = 300; + const TICK_MINIMUM = 2; + const INFO_UPDATE = 10; + + /** @var RunningService */ + private $runningService; + + /** @var string */ + private $source; + + /** @var int */ + private $tickId; + + /** @var ExtendedBase */ + private $commandBase = null; + + /** @var OutputInterface */ + private $outputInterface = null; + + /** @var int */ + private $oldTick = 0; + + /** @var string */ + private $oldAction = ''; + + /** @var int */ + private $ramTick = 0; + + /** + * Runner constructor. + * + * @param RunningService $runningService + * @param string $source + */ + public function __construct(RunningService $runningService, $source) { + $this->runningService = $runningService; + $this->source = $source; + } + + + /** + * @throws RunnerAlreadyUpException + * @throws Exception + */ + public function start() { + $this->tickId = $this->runningService->start($this->source); + } + + + /** + * @param $action + * + * @throws InterruptException + * @throws TickDoesNotExistException + */ + public function update($action) { + + $tick = time(); + try { + $this->hasBeenInterrupted(); + } catch (InterruptException $e) { + $this->stop(); + throw $e; + } + + if ($this->oldAction === $action && ($this->oldTick + self::TICK_MINIMUM > $tick)) { + return; + } + + try { + $this->runningService->update($this->tickId, $action); + } catch (TickIsNotAliveException $e) { + $this->output('Force Quit'); + exit(); + } + + $this->updateInfo($tick); + $this->oldAction = $action; + $this->oldTick = $tick; + } + + + /** + * @throws InterruptException + */ + private function hasBeenInterrupted() { + if ($this->commandBase === null) { + return; + } + $this->commandBase->hasBeenInterrupted(); + } + + + /** + * @param $tick + */ + private function updateInfo($tick) { + if (($this->ramTick + self::INFO_UPDATE) > $tick) { + return; + } + + $this->output('- RAM: ' . (memory_get_usage() / 1024 / 1024)); + $this->ramTick = $tick; + } + + + public function exception($reason, $stop) { + if (!$stop) { + $this->output('Exception: ' . $reason); + // TODO: feed an array of exceptions for log; + } + $this->runningService->exception($this->tickId, $reason, $stop); + } + + + /** + * @throws TickDoesNotExistException + */ + public function stop() { + $this->runningService->stop($this->tickId); + } + + + /** + * @param ExtendedBase $base + * @param OutputInterface $output + */ + public function sourceIsCommandLine(ExtendedBase $base, OutputInterface $output) { + $this->outputInterface = $output; + $this->commandBase = $base; + } + + + /** + * @param string $line + */ + public function output($line) { + if ($this->outputInterface === null) { + return; + } + + $this->outputInterface->writeln($line); + } + + +}
\ No newline at end of file diff --git a/lib/Model/SearchResult.php b/lib/Model/SearchResult.php new file mode 100644 index 0000000..d0e1bf1 --- /dev/null +++ b/lib/Model/SearchResult.php @@ -0,0 +1,128 @@ +<?php +/** + * FullNextSearch - Full Text Search your Nextcloud. + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Maxence Lange <maxence@artificial-owl.com> + * @copyright 2017 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * + */ + +namespace OCA\FullNextSearch\Model; + +use OCA\FullNextSearch\INextSearchProvider; + +class SearchResult implements \JsonSerializable { + + /** @var IndexDocument[] */ + private $documents = []; + + /** @var string */ + private $rawResult; + + /** @var INextSearchProvider */ + private $provider; + + public function __construct() { + } + + + /** + * @param IndexDocument[] $documents + * + * @return $this + */ + public function setDocuments($documents) { + $this->documents = $documents; + + return $this; + } + + /** + * @return IndexDocument[] + */ + public function getDocuments() { + return $this->documents; + } + + /** + * @param IndexDocument $document + * + * @return $this + */ + public function addDocument(IndexDocument $document) { + $this->documents[] = $document; + + return $this; + } + + + /** + * @param string $result + */ + public function setRawResult($result) { + $this->rawResult = $result; + } + + /** + * @return string + */ + public function getRawResult() { + return $this->rawResult; + } + + + /** + * @param INextSearchProvider $provider + */ + public function setProvider(INextSearchProvider $provider) { + $this->provider = $provider; + } + + /** + * @return INextSearchProvider + */ + public function getProvider() { + return $this->provider; + } + + + public function getSize() { + return count($this->documents); + } + + + /** + * @return array + */ + public function jsonSerialize() { + + $provider = $this->getProvider(); + + return [ + 'provider' => [ + 'id' => $provider->getId(), + 'name' => $provider->getName() + ], + 'documents' => $this->getDocuments(), + 'size' => $this->getSize() + ]; + } +}
\ No newline at end of file diff --git a/lib/Model/Tick.php b/lib/Model/Tick.php new file mode 100644 index 0000000..676e03f --- /dev/null +++ b/lib/Model/Tick.php @@ -0,0 +1,191 @@ +<?php +/** + * FullNextSearch - Full Text Search your Nextcloud. + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Maxence Lange <maxence@artificial-owl.com> + * @copyright 2017 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * + */ + + +namespace OCA\FullNextSearch\Model; + + +class Tick { + + /** @var int */ + private $id; + + /** @var string */ + private $source; + + /** @var array */ + protected $data; + + /** @var int */ + private $tick; + + /** @var int */ + private $firstTick; + + /** @var string */ + private $status; + + /** @var string */ + private $action; + + + public function __construct($source, $id = 0) { + $this->source = $source; + $this->id = $id; + } + + + /** + * @return int + */ + public function getId() { + return $this->id; + } + + /** + * @param int $id + * + * @return $this + */ + public function setId($id) { + $this->id = $id; + + return $this; + } + + + /** + * @return string + */ + public function getSource() { + return $this->source; + } + + + /** + * @return array + */ + public function getData() { + return $this->data; + } + + /** + * @param array $data + * + * @return $this + */ + public function setData($data) { + $this->data = $data; + + return $this; + } + + + /** + * @return int + */ + public function getTick() { + return $this->tick; + } + + /** + * @param int $tick + * + * @return $this + */ + public function setTick($tick = 0) { + if ($tick === 0) { + $tick = time(); + } + + $this->tick = $tick; + + return $this; + } + + + /** + * @return int + */ + public function getFirstTick() { + return $this->firstTick; + } + + /** + * @param int $tick + * + * @return $this + */ + public function setFirstTick($tick = 0) { + if ($tick === 0) { + $tick = time(); + } + + $this->firstTick = $tick; + + return $this; + } + + + /** + * @return string + */ + public function getStatus() { + return $this->status; + } + + /** + * @param string $status + * + * @return $this + */ + public function setStatus($status) { + $this->status = $status; + + return $this; + } + + + /** + * @return string + */ + public function getAction() { + return $this->action; + } + + /** + * @param string $action + * + * @return $this + */ + public function setAction($action) { + $this->action = $action; + + return $this; + } + +}
\ No newline at end of file |