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/Model
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2018-10-26 11:10:16 +0300
committerMaxence Lange <maxence@artificial-owl.com>2018-10-26 11:10:16 +0300
commit339153942c2b56afef03726caf1d3531bb33bcf4 (patch)
treef4f231a9c3a18dd8184b1fbe59b22b73aa88b10a /lib/Model
parent5d7563d1a0bcf1c6dc7ba3320824efa1fe624b4c (diff)
compat-nc15
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib/Model')
-rw-r--r--lib/Model/DocumentAccess.php192
-rw-r--r--lib/Model/ExtendedBase.php72
-rw-r--r--lib/Model/ExtendedIndex.php35
-rw-r--r--lib/Model/ExtendedTick.php64
-rw-r--r--lib/Model/Index.php122
-rw-r--r--lib/Model/IndexDocument.php633
-rw-r--r--lib/Model/IndexOptions.php70
-rw-r--r--lib/Model/PlatformWrapper.php10
-rw-r--r--lib/Model/ProviderIndexes.php18
-rw-r--r--lib/Model/ProviderWrapper.php2
-rw-r--r--lib/Model/Runner.php55
-rw-r--r--lib/Model/SearchRequest.php226
-rw-r--r--lib/Model/SearchResult.php131
-rw-r--r--lib/Model/Tick.php33
14 files changed, 408 insertions, 1255 deletions
diff --git a/lib/Model/DocumentAccess.php b/lib/Model/DocumentAccess.php
deleted file mode 100644
index 7c61b53..0000000
--- a/lib/Model/DocumentAccess.php
+++ /dev/null
@@ -1,192 +0,0 @@
-<?php
-/**
- * FullTextSearch - Full text search framework for 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 2018
- * @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\FullTextSearch\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
deleted file mode 100644
index b808f4f..0000000
--- a/lib/Model/ExtendedBase.php
+++ /dev/null
@@ -1,72 +0,0 @@
-<?php
-/**
- * FullTextSearch - Full text search framework for 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 2018
- * @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\FullTextSearch\Model;
-
-use OC\Core\Command\Base;
-use OCA\FullTextSearch\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
deleted file mode 100644
index a26377e..0000000
--- a/lib/Model/ExtendedIndex.php
+++ /dev/null
@@ -1,35 +0,0 @@
-<?php
-/**
- * FullTextSearch - Full text search framework for 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 2018
- * @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\FullTextSearch\Model;
-
-
-class ExtendedIndex extends Index {
-
-
-
-} \ No newline at end of file
diff --git a/lib/Model/ExtendedTick.php b/lib/Model/ExtendedTick.php
deleted file mode 100644
index 8c70c6c..0000000
--- a/lib/Model/ExtendedTick.php
+++ /dev/null
@@ -1,64 +0,0 @@
-<?php
-/**
- * FullTextSearch - Full text search framework for 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 2018
- * @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\FullTextSearch\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
index ebb69da..34ba9dc 100644
--- a/lib/Model/Index.php
+++ b/lib/Model/Index.php
@@ -1,6 +1,9 @@
<?php
+declare(strict_types=1);
+
+
/**
- * FullTextSearch - Full text search framework for extcloud
+ * FullTextSearch - Full text search framework for Nextcloud
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
@@ -24,29 +27,14 @@
*
*/
-namespace OCA\FullTextSearch\Model;
-
-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;
+namespace OCA\FullTextSearch\Model;
- const INDEX_DONE = 32;
- const INDEX_FAILED = 64;
+use JsonSerializable;
+use OCP\FullTextSearch\Model\IIndex;
- const ERROR_FAILED = 1;
- 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;
+class Index implements IIndex, JsonSerializable {
/** @var string */
@@ -83,7 +71,7 @@ class Index implements \JsonSerializable {
* @param string $providerId
* @param string $documentId
*/
- public function __construct($providerId, $documentId) {
+ public function __construct(string $providerId, string $documentId) {
$this->providerId = $providerId;
$this->documentId = $documentId;
}
@@ -92,14 +80,14 @@ class Index implements \JsonSerializable {
/**
* @return string
*/
- public function getProviderId() {
+ public function getProviderId(): string {
return $this->providerId;
}
/**
* @return string
*/
- public function getDocumentId() {
+ public function getDocumentId(): string {
return $this->documentId;
}
@@ -107,9 +95,9 @@ class Index implements \JsonSerializable {
/**
* @param string $source
*
- * @return $this
+ * @return IIndex
*/
- public function setSource($source) {
+ public function setSource(string $source): IIndex {
$this->source = $source;
return $this;
@@ -118,7 +106,7 @@ class Index implements \JsonSerializable {
/**
* @return string
*/
- public function getSource() {
+ public function getSource(): string {
return $this->source;
}
@@ -126,9 +114,9 @@ class Index implements \JsonSerializable {
/**
* @param string $ownerId
*
- * @return $this
+ * @return IIndex
*/
- public function setOwnerId($ownerId) {
+ public function setOwnerId(string $ownerId): IIndex {
$this->ownerId = $ownerId;
return $this;
@@ -137,7 +125,7 @@ class Index implements \JsonSerializable {
/**
* @return string
*/
- public function getOwnerId() {
+ public function getOwnerId(): string {
return $this->ownerId;
}
@@ -146,9 +134,9 @@ class Index implements \JsonSerializable {
* @param int $status
* @param bool $reset
*
- * @return $this
+ * @return IIndex
*/
- public function setStatus($status, $reset = false) {
+ public function setStatus(int $status, bool $reset = false): IIndex {
if ($reset === true) {
$this->status = $status;
} else if (!$this->isStatus($status)) {
@@ -161,7 +149,7 @@ class Index implements \JsonSerializable {
/**
* @return int
*/
- public function getStatus() {
+ public function getStatus(): int {
return $this->status;
}
@@ -170,29 +158,33 @@ class Index implements \JsonSerializable {
*
* @return bool
*/
- public function isStatus($status) {
- return ((int)$status & $this->getStatus());
+ public function isStatus(int $status): bool {
+ return (bool)((int)$status & $this->getStatus());
}
/**
* @param int $status
+ *
+ * @return IIndex
*/
- public function unsetStatus($status) {
+ public function unsetStatus(int $status): IIndex {
if (!$this->isStatus($status)) {
- return;
+ return $this;
}
$this->status -= $status;
+
+ return $this;
}
/**
* @param string $option
- * @param string|int $value
+ * @param string $value
*
- * @return $this
+ * @return IIndex
*/
- public function addOption($option, $value) {
+ public function addOption(string $option, string $value): IIndex {
$this->options[$option] = $value;
return $this;
@@ -202,9 +194,9 @@ class Index implements \JsonSerializable {
* @param string $option
* @param int $value
*
- * @return $this
+ * @return IIndex
*/
- public function addOptionInt($option, $value) {
+ public function addOptionInt(string $option, int $value): IIndex {
$this->options[$option] = $value;
return $this;
@@ -214,9 +206,9 @@ class Index implements \JsonSerializable {
/**
* @param array $options
*
- * @return $this
+ * @return IIndex
*/
- public function setOptions($options) {
+ public function setOptions(array $options): IIndex {
$this->options = $options;
return $this;
@@ -225,7 +217,7 @@ class Index implements \JsonSerializable {
/**
* @return array
*/
- public function getOptions() {
+ public function getOptions(): array {
return $this->options;
}
@@ -236,7 +228,7 @@ class Index implements \JsonSerializable {
*
* @return string
*/
- public function getOption($option, $default = '') {
+ public function getOption(string $option, string $default = ''): string {
if (!array_key_exists($option, $this->options)) {
return $default;
}
@@ -245,14 +237,13 @@ class Index implements \JsonSerializable {
}
-
/**
* @param string $option
* @param int $default
*
* @return int
*/
- public function getOptionInt($option, $default = 0) {
+ public function getOptionInt(string $option, int $default = 0): int {
if (!array_key_exists($option, $this->options)) {
return $default;
}
@@ -263,9 +254,9 @@ class Index implements \JsonSerializable {
/**
* @param int $err
*
- * @return $this
+ * @return IIndex
*/
- public function setErrorCount($err) {
+ public function setErrorCount(int $err): IIndex {
$this->err = $err;
return $this;
@@ -274,14 +265,14 @@ class Index implements \JsonSerializable {
/**
* @return int
*/
- public function getErrorCount() {
+ public function getErrorCount(): int {
return $this->err;
}
/**
* @return array
*/
- public function getLastError() {
+ public function getLastError(): array {
return array_values(array_slice($this->errors, -1))[0];
}
@@ -289,24 +280,26 @@ class Index implements \JsonSerializable {
/**
*
*/
- public function resetErrors() {
+ public function resetErrors(): IIndex {
$this->setErrors([]);
$this->setErrorCount(0);
+
+ return $this;
}
/**
* @return array
*/
- public function getErrors() {
+ public function getErrors(): array {
return $this->errors;
}
/**
* @param array $messages
*
- * @return Index
+ * @return IIndex
*/
- public function setErrors($messages) {
+ public function setErrors(array $messages): IIndex {
$this->errors = $messages;
return $this;
@@ -317,24 +310,29 @@ class Index implements \JsonSerializable {
* @param string $message
* @param string $exception
* @param int $sev
+ *
+ * @return IIndex
*/
- public function addError($message, $exception = '', $sev = self::ERROR_SEV_3) {
+ public function addError(string $message, string $exception = '', int $sev = IIndex::ERROR_SEV_3
+ ): IIndex {
$this->errors[] = [
- 'message' => substr($message, 0, 1800),
+ 'message' => substr($message, 0, 1800),
'exception' => $exception,
- 'severity' => $sev
+ 'severity' => $sev
];
$this->err++;
+
+ return $this;
}
/**
* @param int $lastIndex
*
- * @return $this
+ * @return IIndex
*/
- public function setLastIndex($lastIndex = -1) {
+ public function setLastIndex(int $lastIndex = -1): IIndex {
if ($lastIndex === -1) {
$lastIndex = time();
}
@@ -347,7 +345,7 @@ class Index implements \JsonSerializable {
/**
* @return int
*/
- public function getLastIndex() {
+ public function getLastIndex(): int {
return $this->lastIndex;
}
@@ -381,4 +379,4 @@ class Index implements \JsonSerializable {
unset($this->lastIndex);
}
-} \ No newline at end of file
+}
diff --git a/lib/Model/IndexDocument.php b/lib/Model/IndexDocument.php
deleted file mode 100644
index 12a011c..0000000
--- a/lib/Model/IndexDocument.php
+++ /dev/null
@@ -1,633 +0,0 @@
-<?php
-/**
- * FullTextSearch - Full text search framework for 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 2018
- * @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\FullTextSearch\Model;
-
-class IndexDocument implements \JsonSerializable {
-
- const NOT_ENCODED = 0;
- const ENCODED_BASE64 = 1;
-
- /** @var string|int */
- protected $id;
-
- /** @var string */
- protected $providerId;
-
- /** @var DocumentAccess */
- protected $access;
-
- /** @var Index */
- protected $index;
-
- /** @var int */
- protected $modifiedTime = 0;
-
- /** @var string */
- protected $source = '';
-
- /** @var array */
- protected $tags = [];
-
- /** @var array */
- protected $metaTags = [];
-
- /** @var array */
- protected $subTags = [];
-
- /** @var string */
- protected $title = '';
-
- /** @var string */
- protected $content = null;
-
- /** @var string */
- protected $hash = '';
-
- /** @var array */
- protected $parts = [];
-
- /** @var string */
- protected $link = '';
-
- /** @var array */
- protected $more = [];
-
- /** @var array */
- protected $excerpts = [];
-
- /** @var string */
- protected $score;
-
- /** @var array */
- protected $info = [];
-
- /** @var int */
- protected $contentEncoded;
-
-
- public function __construct($providerId, $id) {
- $this->providerId = $providerId;
- $this->id = $id;
- }
-
-
-// /**
-// * @param string|integer $id
-// *
-// * @return $this
-// */
-// public function setId($id) {
-// $this->id = $id;
-//
-// return $this;
-// }
-
- /**
- * @return string|integer
- */
- 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 array $tags
- *
- * @return $this
- */
- public function setMetaTags($tags) {
- $this->metaTags = $tags;
-
- return $this;
- }
-
- /**
- * @return array
- */
- public function getMetaTags() {
- return $this->metaTags;
- }
-
- /**
- * @param $tags
- *
- * @return $this
- */
- public function addMetaTag($tags) {
- $this->metaTags[] = $tags;
-
- return $this;
- }
-
-
- /**
- * @param array $tags
- *
- * @return $this
- */
- public function setSubTags($tags) {
- $this->subTags = $tags;
-
- return $this;
- }
-
- /**
- * @param bool $formatted
- *
- * @return array
- */
- public function getSubTags($formatted = false) {
- if ($formatted === false) {
- return $this->subTags;
- }
-
- $subTags = [];
- $ak = array_keys($this->subTags);
- foreach ($ak as $source) {
- $tags = $this->subTags[$source];
- foreach ($tags as $tag) {
- $subTags[] = $source . '_' . $tag;
- }
- }
-
- return $subTags;
- }
-
- /**
- * @param string $k
- * @param string $tag
- *
- * @return $this
- */
- public function addSubTag($k, $tag) {
- $this->subTags[$k] = $tag;
-
- return $this;
- }
-
-
- /**
- * @return string
- */
- public function getSource() {
- return $this->source;
- }
-
- /**
- * @param string $source
- *
- * @return $this
- */
- public function setSource($source) {
- $this->source = $source;
-
- 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 getContentSize() {
- return strlen($this->getContent());
- }
-
-
- /**
- * @return $this
- */
- public function initHash() {
- if ($this->getContent() === '' || is_null($this->getContent())) {
- return $this;
- }
-
- $this->hash = hash("md5", $this->getContent());
-
- return $this;
- }
-
- /**
- * @param $hash
- *
- * @return $this
- */
- public function setHash($hash) {
- $this->hash = $hash;
-
- return $this;
- }
-
- /**
- * @return string
- */
- public function getHash() {
- return $this->hash;
- }
-
-
- /**
- * @param string $part
- * @param string $content
- *
- * @return $this
- */
- public function addPart($part, $content) {
- $this->parts[$part] = $content;
-
- return $this;
- }
-
- /**
- * @param array $parts
- *
- * @return $this
- */
- public function setParts($parts) {
- $this->parts = $parts;
-
- return $this;
- }
-
- /**
- * @return array
- */
- public function getParts() {
- return $this->parts;
- }
-
-
- /**
- * @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) {
- $excerpts = array_map([$this, 'cleanExcerpt'], $excerpts);
-
- $this->excerpts = $excerpts;
-
- return $this;
- }
-
- /**
- * @return array
- */
- public function getExcerpts() {
- return $this->excerpts;
- }
-
- /**
- * @param string $excerpt
- */
- public function addExcerpt($excerpt) {
- $excerpt = $this->cleanExcerpt($excerpt);
-
- $this->excerpts[] = $excerpt;
- }
-
- /**
- * @param $excerpt
- *
- * @return mixed
- */
- public function cleanExcerpt($excerpt) {
- $excerpt = str_replace("\\n", ' ', $excerpt);
- $excerpt = str_replace("\\r", ' ', $excerpt);
- $excerpt = str_replace("\\t", ' ', $excerpt);
- $excerpt = str_replace("\n", ' ', $excerpt);
- $excerpt = str_replace("\r", ' ', $excerpt);
- $excerpt = str_replace("\t", ' ', $excerpt);
-
- return $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->hash);
- unset($this->link);
- unset($this->source);
- unset($this->tags);
- unset($this->metaTags);
- unset($this->subTags);
- unset($this->more);
- unset($this->excerpts);
- unset($this->score);
- unset($this->info);
- unset($this->contentEncoded);
- }
-
- /**
- * @return array<string,string|integer|DocumentAccess|array>
- */
- public function jsonSerialize() {
- return [
- 'id' => $this->getId(),
- 'providerId' => $this->getProviderId(),
- 'access' => $this->getAccess(),
- 'modifiedTime' => $this->getModifiedTime(),
- 'title' => $this->getTitle(),
- 'link' => $this->getLink(),
- 'index' => $this->getIndex(),
- 'source' => $this->getSource(),
- 'info' => $this->getInfoAll(),
- 'hash' => $this->getHash(),
- 'contentSize' => $this->getContentSize(),
- 'tags' => $this->getTags(),
- 'metatags' => $this->getMetaTags(),
- 'subtags' => $this->getSubTags(),
- 'more' => $this->getMore(),
- 'excerpts' => $this->getExcerpts(),
- 'score' => $this->getScore()
- ];
- }
-
-} \ No newline at end of file
diff --git a/lib/Model/IndexOptions.php b/lib/Model/IndexOptions.php
index 2c5456e..1261bab 100644
--- a/lib/Model/IndexOptions.php
+++ b/lib/Model/IndexOptions.php
@@ -27,7 +27,10 @@
namespace OCA\FullTextSearch\Model;
-class IndexOptions implements \JsonSerializable {
+use JsonSerializable;
+use OCP\FullTextSearch\Model\IIndexOptions;
+
+class IndexOptions implements IIndexOptions, JsonSerializable {
/**
* @var array
@@ -42,51 +45,67 @@ class IndexOptions implements \JsonSerializable {
/**
* @return array
*/
- public function getOptions() {
+ public function getOptions(): array {
return $this->options;
}
/**
* @param array $options
+ *
+ * @return IIndexOptions
*/
- public function setOptions($options) {
+ public function setOptions(array $options): IIndexOptions {
$this->options = $options;
+
+ return $this;
}
/**
- * @param string $k
- * @param string $v
+ * @param string $option
+ * @param string $value
+ *
+ * @return IIndexOptions
*/
- public function addOption($k, $v) {
- $this->options[$k] = $v;
+ public function addOption(string $option, string $value): IIndexOptions {
+ $this->options[$option] = $value;
+
+ return $this;
}
/**
- * @param string $k
- * @param array $array
+ * @param string $option
+ * @param array $value
+ *
+ * @return IIndexOptions
*/
- public function addOptionArray($k, $array) {
- $this->options[$k] = $array;
+ public function addOptionArray(string $option, array $value): IIndexOptions {
+ $this->options[$option] = $value;
+
+ return $this;
}
/**
- * @param string $k
- * @param bool $bool
+ * @param string $option
+ * @param bool $value
+ *
+ * @return IIndexOptions
*/
- public function addOptionBool($k, $bool) {
- $this->options[$k] = $bool;
+ public function addOptionBool(string $option, bool $value): IIndexOptions {
+ $this->options[$option] = $value;
+
+ return $this;
}
/**
- * @param string $k
+ * @param string $option
* @param string $default
*
* @return string
*/
- public function getOption($k, $default = '') {
- if (array_key_exists($k, $this->options)) {
- return $this->options[$k];
+ public function getOption(string $option, string $default = ''): string {
+ if (array_key_exists($option, $this->options)) {
+ return $this->options[$option];
}
return $default;
@@ -99,7 +118,7 @@ class IndexOptions implements \JsonSerializable {
*
* @return array
*/
- public function getOptionArray($option, $default = []) {
+ public function getOptionArray(string $option, array $default = []): array {
if (array_key_exists($option, $this->options)) {
$options = $this->options[$option];
if (is_array($options)) {
@@ -117,7 +136,7 @@ class IndexOptions implements \JsonSerializable {
*
* @return bool
*/
- public function getOptionBool($option, $default) {
+ public function getOptionBool(string $option, bool $default): bool {
if (array_key_exists($option, $this->options)) {
$options = $this->options[$option];
if (is_bool($options)) {
@@ -130,14 +149,9 @@ class IndexOptions implements \JsonSerializable {
/**
- * Specify data which should be serialized to JSON
- *
- * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
- * @return mixed data which can be serialized by <b>json_encode</b>,
- * which is a value of any type other than a resource.
- * @since 5.4.0
+ * @return array
*/
public function jsonSerialize() {
return $this->options;
}
-} \ No newline at end of file
+}
diff --git a/lib/Model/PlatformWrapper.php b/lib/Model/PlatformWrapper.php
index 2bcccbb..6a9673a 100644
--- a/lib/Model/PlatformWrapper.php
+++ b/lib/Model/PlatformWrapper.php
@@ -28,7 +28,7 @@
namespace OCA\FullTextSearch\Model;
-use OCA\FullTextSearch\IFullTextSearchPlatform;
+use OCP\FullTextSearch\IFullTextSearchPlatform;
/**
@@ -56,9 +56,9 @@ class PlatformWrapper {
* Provider constructor.
*
* @param string $appId
- * @param IFullTextSearchPlatform $platform
+ * @param string $class
*/
- public function __construct($appId, $class) {
+ public function __construct(string $appId, string $class) {
$this->appId = $appId;
$this->class = $class;
}
@@ -66,7 +66,7 @@ class PlatformWrapper {
/**
* @return string
*/
- public function getAppId() {
+ public function getAppId(): string {
return $this->appId;
}
@@ -75,7 +75,7 @@ class PlatformWrapper {
*
* @return PlatformWrapper
*/
- public function setAppId($appId) {
+ public function setAppId(string $appId): PlatformWrapper {
$this->appId = $appId;
return $this;
diff --git a/lib/Model/ProviderIndexes.php b/lib/Model/ProviderIndexes.php
index 2915181..3177066 100644
--- a/lib/Model/ProviderIndexes.php
+++ b/lib/Model/ProviderIndexes.php
@@ -27,9 +27,12 @@
namespace OCA\FullTextSearch\Model;
+use OCA\FullTextSearch\Exceptions\IndexDoesNotExistException;
+use OCP\FullTextSearch\Model\IIndex;
+
class ProviderIndexes {
- /** @var Index[] */
+ /** @var IIndex[] */
private $indexes;
@@ -39,9 +42,9 @@ class ProviderIndexes {
/**
- * @return Index[]
+ * @return IIndex[]
*/
- public function getIndexes() {
+ public function getIndexes():array {
return $this->indexes;
}
@@ -49,17 +52,18 @@ class ProviderIndexes {
/**
* @param string $documentId
*
- * @return null|Index
+ * @return IIndex
+ * @throws IndexDoesNotExistException
*/
- public function getIndex($documentId) {
+ public function getIndex(string $documentId): IIndex {
foreach ($this->indexes as $index) {
if ($index->getDocumentId() === (string)$documentId) {
return $index;
}
}
- return null;
+ throw new IndexDoesNotExistException();
}
-} \ No newline at end of file
+}
diff --git a/lib/Model/ProviderWrapper.php b/lib/Model/ProviderWrapper.php
index 866c58c..d1de140 100644
--- a/lib/Model/ProviderWrapper.php
+++ b/lib/Model/ProviderWrapper.php
@@ -28,7 +28,7 @@
namespace OCA\FullTextSearch\Model;
-use OCA\FullTextSearch\IFullTextSearchProvider;
+use OCP\FullTextSearch\IFullTextSearchProvider;
/**
diff --git a/lib/Model/Runner.php b/lib/Model/Runner.php
index a2187aa..04f1d4e 100644
--- a/lib/Model/Runner.php
+++ b/lib/Model/Runner.php
@@ -32,10 +32,12 @@ use OCA\FullTextSearch\Exceptions\TickDoesNotExistException;
use OCA\FullTextSearch\Exceptions\TickIsNotAliveException;
use OCA\FullTextSearch\Service\MiscService;
use OCA\FullTextSearch\Service\RunningService;
+use OCP\FullTextSearch\Model\IIndex;
+use OCP\FullTextSearch\Model\IRunner;
use Symfony\Component\Console\Output\OutputInterface;
-class Runner {
+class Runner implements IRunner {
const TICK_TTL = 1800;
@@ -43,10 +45,6 @@ class Runner {
const TICK_UPDATE = 10;
const MEMORY_UPDATE = 5;
- const RESULT_TYPE_SUCCESS = 1;
- const RESULT_TYPE_WARNING = 4;
- const RESULT_TYPE_FAIL = 9;
-
/** @var RunningService */
private $runningService;
@@ -59,9 +57,6 @@ class Runner {
/** @var int */
private $tickId;
- /** @var ExtendedBase */
- private $commandBase = null;
-
/** @var OutputInterface */
private $outputInterface = null;
@@ -135,7 +130,7 @@ class Runner {
* @return string
* @throws \Exception
*/
- public function updateAction($action = '', $force = false) {
+ public function updateAction(string $action = '', bool $force = false): string {
$n = '';
if (sizeof($this->methodOnKeyPress) > 0) {
$n = fread(STDIN, 9999);
@@ -195,7 +190,7 @@ class Runner {
* @param string $value
* @param int $type
*/
- public function setInfo($info, $value, $type = 0) {
+ public function setInfo(string $info, string $value, int $type = 0) {
$this->info[$info] = $value;
$this->setInfoColored($info, $type);
$this->infoUpdated();
@@ -204,7 +199,7 @@ class Runner {
/**
* @param array $data
*/
- public function setInfoArray($data) {
+ public function setInfoArray(array $data) {
$keys = array_keys($data);
//$this->info['info'] = '';
foreach ($keys as $k) {
@@ -219,7 +214,7 @@ class Runner {
* @param string $info
* @param int $level
*/
- public function setInfoColored($info, $level) {
+ public function setInfoColored(string $info, int $level) {
$value = $this->getInfo($info);
if ($value === '') {
@@ -228,15 +223,15 @@ class Runner {
$color = '';
switch ($level) {
- case self::RESULT_TYPE_SUCCESS:
+ case IRunner::RESULT_TYPE_SUCCESS:
$color = 'info';
break;
- case self::RESULT_TYPE_WARNING:
+ case IRunner::RESULT_TYPE_WARNING:
$color = 'comment';
break;
- case self::RESULT_TYPE_FAIL:
+ case IRunner::RESULT_TYPE_FAIL:
$color = 'error';
break;
}
@@ -306,12 +301,13 @@ class Runner {
}
/**
- * @param Index $index
+ * @param IIndex $index
* @param string $message
* @param string $class
* @param int $sev
*/
- public function newIndexError($index, $message, $class = '', $sev = 3) {
+ public function newIndexError(IIndex $index, string $message, string $class = '', int $sev = 3
+ ) {
$error = [
'index' => $index,
'message' => $message,
@@ -334,12 +330,12 @@ class Runner {
/**
- * @param Index $index
+ * @param IIndex $index
* @param string $message
* @param string $status
* @param int $type
*/
- public function newIndexResult($index, $message, $status, $type) {
+ public function newIndexResult(IIndex $index, string $message, string $status, int $type) {
$result = [
'index' => $index,
'message' => $message,
@@ -353,17 +349,6 @@ class Runner {
}
-// /**
-// * @throws InterruptException
-// */
-// private function hasBeenInterrupted() {
-// if ($this->commandBase === null) {
-// return;
-// }
-// $this->commandBase->hasBeenInterrupted();
-// }
-
-
/**
* @param int $tick
* @param string $action
@@ -402,10 +387,10 @@ class Runner {
/**
* @deprecated - verifier l'interet !?
*
- * @param $reason
- * @param $stop
+ * @param string $reason
+ * @param bool $stop
*/
- public function exception($reason, $stop) {
+ public function exception(string $reason, bool $stop) {
if (!$stop) {
$this->output('Exception: ' . $reason);
// TODO: feed an array of exceptions for log;
@@ -423,12 +408,10 @@ class Runner {
/**
- * @param ExtendedBase $base
* @param OutputInterface $output
*/
- public function sourceIsCommandLine(ExtendedBase $base, OutputInterface $output) {
+ public function sourceIsCommandLine(OutputInterface $output) {
$this->outputInterface = $output;
- $this->commandBase = $base;
}
diff --git a/lib/Model/SearchRequest.php b/lib/Model/SearchRequest.php
index 0fce57a..1d21169 100644
--- a/lib/Model/SearchRequest.php
+++ b/lib/Model/SearchRequest.php
@@ -26,9 +26,11 @@
namespace OCA\FullTextSearch\Model;
+use JsonSerializable;
use OCA\FullTextSearch\Service\MiscService;
+use OCP\FullTextSearch\Model\ISearchRequest;
-class SearchRequest implements \JsonSerializable {
+class SearchRequest implements ISearchRequest, JsonSerializable {
/** @var array */
private $providers;
@@ -89,52 +91,64 @@ class SearchRequest implements \JsonSerializable {
/**
* @return array
*/
- public function getProviders() {
+ public function getProviders(): array {
return $this->providers;
}
/**
* @param array $providers
+ *
+ * @return ISearchRequest
*/
- public function setProviders($providers) {
+ public function setProviders(array $providers): ISearchRequest {
$this->providers = $providers;
+
+ return $this;
}
/**
* @return string
*/
- public function getAuthor() {
+ public function getAuthor(): string {
return $this->author;
}
/**
* @param string $author
+ *
+ * @return ISearchRequest
*/
- public function setAuthor($author) {
+ public function setAuthor(string $author): ISearchRequest {
$this->author = $author;
+
+ return $this;
}
/**
* @return string
*/
- public function getSearch() {
+ public function getSearch(): string {
return $this->search;
}
/**
* @param string $search
+ *
+ * @return ISearchRequest
*/
- public function setSearch($search) {
+ public function setSearch(string $search): ISearchRequest {
$this->search = $search;
+
+ return $this;
}
/**
*
*/
- public function cleanSearch() {
+ public function cleanSearch(): ISearchRequest {
$search = trim(str_replace(' ', ' ', $this->getSearch()));
preg_match_all('/[^?]"(?:\\\\.|[^\\\\"])*"|\S+/', " $search ", $words);
@@ -148,15 +162,17 @@ class SearchRequest implements \JsonSerializable {
}
$this->setSearch(implode(" ", $searchItems));
+
+ return $this;
}
/**
- * @param $word
+ * @param string $word
*
* @return bool
*/
- private function searchQueryOptions($word) {
+ private function searchQueryOptions(string $word): bool {
if (($pos = strpos($word, ':')) === false) {
return false;
}
@@ -184,99 +200,111 @@ class SearchRequest implements \JsonSerializable {
/**
* @return int
*/
- public function getPage() {
+ public function getPage(): int {
return $this->page;
}
/**
* @param int $page
+ *
+ * @return ISearchRequest
*/
- public function setPage($page) {
+ public function setPage(int $page): ISearchRequest {
if ($page < 1) {
$page = 1;
}
$this->page = $page;
+
+ return $this;
}
/**
* @return int
*/
- public function getSize() {
+ public function getSize(): int {
return $this->size;
}
/**
* @param int $size
+ *
+ * @return ISearchRequest
*/
- public function setSize($size) {
+ public function setSize(int $size): ISearchRequest {
$this->size = $size;
+
+ return $this;
}
/**
* @return array
*/
- public function getOptions() {
+ public function getOptions(): array {
return $this->options;
}
/**
* @param array $options
+ *
+ * @return ISearchRequest
*/
- public function setOptions($options) {
+ public function setOptions(array $options): ISearchRequest {
$this->options = $options;
+
+ return $this;
}
/**
- * @param $key
+ * @param $option
* @param $value
*
- * @return $this
+ * @return ISearchRequest
*/
- public function addOption($key, $value) {
- $this->options[$key] = $value;
+ public function addOption(string $option, string $value): ISearchRequest {
+ $this->options[$option] = $value;
return $this;
}
/**
- * @param string $k
- * @param array $array
+ * @param string $option
+ * @param array $value
*
- * @return SearchRequest
+ * @return ISearchRequest
*/
- public function addOptionArray($k, $array) {
- $this->options[$k] = $array;
+ public function addOptionArray(string $option, array $value): ISearchRequest {
+ $this->options[$option] = $value;
return $this;
}
/**
- * @param string $k
- * @param bool $bool
+ * @param string $option
+ * @param bool $value
*
- * @return SearchRequest
+ * @return ISearchRequest
*/
- public function addOptionBool($k, $bool) {
- $this->options[$k] = $bool;
+ public function addOptionBool(string $option, bool $value): ISearchRequest {
+ $this->options[$option] = $value;
return $this;
}
/**
- * @param $key
- * @param $value
+ * @param string $option
+ * @param string $value
*
- * @return $this
+ * @return ISearchRequest
*/
- public function addMultipleOption($key, $value) {
- if (!array_key_exists($key, $this->options)) {
- $this->options[$key] = [];
+ public function addMultipleOption(string $option, string $value): ISearchRequest {
+ if (!array_key_exists($option, $this->options)) {
+ $this->options[$option] = [];
}
- $this->options[$key][] = $value;
+ $this->options[$option][] = $value;
return $this;
}
@@ -287,7 +315,7 @@ class SearchRequest implements \JsonSerializable {
*
* @return string
*/
- public function getOption($option, $default = '') {
+ public function getOption(string $option, string $default = ''): string {
if (array_key_exists($option, $this->options)) {
return $this->options[$option];
}
@@ -302,7 +330,7 @@ class SearchRequest implements \JsonSerializable {
*
* @return array
*/
- public function getOptionArray($option, $default = []) {
+ public function getOptionArray(string $option, array $default = []): array {
if (array_key_exists($option, $this->options)) {
$options = $this->options[$option];
if (is_array($options)) {
@@ -315,12 +343,12 @@ class SearchRequest implements \JsonSerializable {
/**
- * @param array $parts
+ * @param string $part
*
- * @return $this
+ * @return ISearchRequest
*/
- public function setParts($parts) {
- $this->parts = $parts;
+ public function addPart(string $part): ISearchRequest {
+ $this->parts[] = $part;
return $this;
}
@@ -328,24 +356,38 @@ class SearchRequest implements \JsonSerializable {
/**
* @return array
*/
- public function getParts() {
+ public function getParts(): array {
return $this->parts;
}
/**
+ * @since 15.0.0
+ *
+ * @param array $parts
+ *
+ * @return ISearchRequest
+ */
+ public function setParts(array $parts): ISearchRequest {
+ $this->parts = $parts;
+
+ return $this;
+ }
+
+
+ /**
* @return array
*/
- public function getFields() {
+ public function getFields(): array {
return $this->fields;
}
/**
* @param array $fields
*
- * @return $this
+ * @return ISearchRequest
*/
- public function setFields($fields) {
+ public function setFields(array $fields): ISearchRequest {
$this->fields = $fields;
return $this;
@@ -353,11 +395,11 @@ class SearchRequest implements \JsonSerializable {
/**
- * @param $field
+ * @param string $field
*
- * @return $this
+ * @return ISearchRequest
*/
- public function limitToField($field) {
+ public function addLimitField(string $field): ISearchRequest {
array_push($this->limitFields, $field);
return $this;
@@ -366,17 +408,17 @@ class SearchRequest implements \JsonSerializable {
/**
* @return array
*/
- public function getLimitFields() {
+ public function getLimitFields(): array {
return $this->limitFields;
}
/**
- * @param $field
+ * @param string $field
*
- * @return $this
+ * @return ISearchRequest
*/
- public function addField($field) {
+ public function addField(string $field): ISearchRequest {
$this->fields[] = $field;
return $this;
@@ -385,32 +427,40 @@ class SearchRequest implements \JsonSerializable {
/**
* @param string $tag
+ *
+ * @return ISearchRequest
*/
- public function addTag($tag) {
+ public function addTag(string $tag): ISearchRequest {
$this->tags[] = $tag;
+
+ return $this;
}
/**
* @return array
*/
- public function getTags() {
+ public function getTags(): array {
return $this->tags;
}
/**
* @param array $tags
+ *
+ * @return ISearchRequest
*/
- public function setTags($tags) {
+ public function setTags(array $tags): ISearchRequest {
$this->tags = $tags;
+
+ return $this;
}
/**
* @param array $tags
*
- * @return $this
+ * @return ISearchRequest
*/
- public function setMetaTags($tags) {
+ public function setMetaTags(array $tags): ISearchRequest {
$this->metaTags = $tags;
return $this;
@@ -419,17 +469,17 @@ class SearchRequest implements \JsonSerializable {
/**
* @return array
*/
- public function getMetaTags() {
+ public function getMetaTags(): array {
return $this->metaTags;
}
/**
- * @param string $tags
+ * @param string $tag
*
- * @return $this
+ * @return ISearchRequest
*/
- public function addMetaTag($tags) {
- $this->metaTags[] = $tags;
+ public function addMetaTag(string $tag): ISearchRequest {
+ $this->metaTags[] = $tag;
return $this;
}
@@ -438,9 +488,9 @@ class SearchRequest implements \JsonSerializable {
/**
* @param array $tags
*
- * @return $this
+ * @return ISearchRequest
*/
- public function setSubTags($tags) {
+ public function setSubTags(array $tags): ISearchRequest {
$this->subTags = $tags;
return $this;
@@ -451,7 +501,7 @@ class SearchRequest implements \JsonSerializable {
*
* @return array
*/
- public function getSubTags($formatted = false) {
+ public function getSubTags(bool $formatted = false): array {
if ($formatted === false) {
return $this->subTags;
}
@@ -472,9 +522,9 @@ class SearchRequest implements \JsonSerializable {
* @param string $source
* @param string $tag
*
- * @return $this
+ * @return ISearchRequest
*/
- public function addSubTag($source, $tag) {
+ public function addSubTag(string $source, string $tag): ISearchRequest {
if (!array_key_exists($source, $this->subTags)) {
$this->subTags[$source] = [];
}
@@ -488,9 +538,9 @@ class SearchRequest implements \JsonSerializable {
/**
* @param string $field
*
- * @return $this
+ * @return ISearchRequest
*/
- public function addWildcardField($field) {
+ public function addWildcardField(string $field): ISearchRequest {
$this->wildcardFields[] = $field;
return $this;
@@ -500,7 +550,7 @@ class SearchRequest implements \JsonSerializable {
/**
* @return array
*/
- public function getWildcardFields() {
+ public function getWildcardFields(): array {
return $this->wildcardFields;
}
@@ -508,7 +558,7 @@ class SearchRequest implements \JsonSerializable {
// /**
// * @param array $query
// *
-// * @return $this
+// * @return ISearchRequest
// */
// public function addWildcardQuery($query) {
// $this->addWildcardQueries([$query]);
@@ -519,7 +569,7 @@ class SearchRequest implements \JsonSerializable {
// /**
// * @param array $query
// *
-// * @return $this
+// * @return ISearchRequest
// */
// public function addWildcardQueries($query) {
// array_push($this->wildcardQueries, $query);
@@ -538,9 +588,9 @@ class SearchRequest implements \JsonSerializable {
/**
* @param array $filter
*
- * @return $this
+ * @return ISearchRequest
*/
- public function addWildcardFilter($filter) {
+ public function addWildcardFilter(array $filter): ISearchRequest {
$this->addWildcardFilters([$filter]);
return $this;
@@ -549,9 +599,9 @@ class SearchRequest implements \JsonSerializable {
/**
* @param array $filters
*
- * @return $this
+ * @return ISearchRequest
*/
- public function addWildcardFilters($filters) {
+ public function addWildcardFilters(array $filters): ISearchRequest {
array_push($this->wildcardFilters, $filters);
return $this;
@@ -560,17 +610,17 @@ class SearchRequest implements \JsonSerializable {
/**
* @return array
*/
- public function getWildcardFilters() {
+ public function getWildcardFilters(): array {
return $this->wildcardFilters;
}
/**
- * @param array $filter
+ * @param string $filter
*
- * @return $this
+ * @return ISearchRequest
*/
- public function addRegexFilter($filter) {
+ public function addRegexFilter(string $filter): ISearchRequest {
$this->addRegexFilters([$filter]);
return $this;
@@ -579,9 +629,9 @@ class SearchRequest implements \JsonSerializable {
/**
* @param array $filters
*
- * @return $this
+ * @return ISearchRequest
*/
- public function addRegexFilters($filters) {
+ public function addRegexFilters(array $filters): ISearchRequest {
array_push($this->regexFilters, $filters);
return $this;
@@ -590,7 +640,7 @@ class SearchRequest implements \JsonSerializable {
/**
* @return array
*/
- public function getRegexFilters() {
+ public function getRegexFilters(): array {
return $this->regexFilters;
}
@@ -619,7 +669,7 @@ class SearchRequest implements \JsonSerializable {
*
* @return SearchRequest
*/
- public static function fromJSON($json) {
+ public static function fromJSON($json): SearchRequest {
return self::fromArray(json_decode($json, true));
}
@@ -628,7 +678,7 @@ class SearchRequest implements \JsonSerializable {
*
* @return SearchRequest
*/
- public static function fromArray($arr) {
+ public static function fromArray($arr): SearchRequest {
$providers = $arr['providers'];
if (!is_array($providers)) {
$providers = [$providers];
@@ -650,4 +700,4 @@ class SearchRequest implements \JsonSerializable {
}
-} \ No newline at end of file
+}
diff --git a/lib/Model/SearchResult.php b/lib/Model/SearchResult.php
index e985fc3..f51a7f0 100644
--- a/lib/Model/SearchResult.php
+++ b/lib/Model/SearchResult.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,12 +27,18 @@
*
*/
+
namespace OCA\FullTextSearch\Model;
-use OCA\FullTextSearch\IFullTextSearchPlatform;
-use OCA\FullTextSearch\IFullTextSearchProvider;
+use JsonSerializable;
+use OCP\FullTextSearch\IFullTextSearchPlatform;
+use OCP\FullTextSearch\IFullTextSearchProvider;
+use OCP\FullTextSearch\Model\IndexDocument;
+use OCP\FullTextSearch\Model\ISearchRequest;
+use OCP\FullTextSearch\Model\ISearchResult;
-class SearchResult implements \JsonSerializable {
+
+class SearchResult implements ISearchResult, JsonSerializable {
/** @var IndexDocument[] */
private $documents = [];
@@ -55,7 +64,7 @@ class SearchResult implements \JsonSerializable {
/** @var boolean */
private $timedOut;
- /** @var SearchRequest */
+ /** @var ISearchRequest */
private $request;
@@ -67,9 +76,9 @@ class SearchResult implements \JsonSerializable {
/**
* @param IndexDocument[] $documents
*
- * @return $this
+ * @return ISearchResult
*/
- public function setDocuments($documents) {
+ public function setDocuments(array $documents): ISearchResult {
$this->documents = $documents;
return $this;
@@ -78,16 +87,16 @@ class SearchResult implements \JsonSerializable {
/**
* @return IndexDocument[]
*/
- public function getDocuments() {
+ public function getDocuments(): array {
return $this->documents;
}
/**
* @param IndexDocument $document
*
- * @return $this
+ * @return ISearchResult
*/
- public function addDocument(IndexDocument $document) {
+ public function addDocument(IndexDocument $document): ISearchResult {
$this->documents[] = $document;
return $this;
@@ -96,37 +105,45 @@ class SearchResult implements \JsonSerializable {
/**
* @return int
*/
- public function getCount() {
+ public function getCount(): int {
return count($this->documents);
}
/**
* @param string $result
+ *
+ * @return ISearchResult
*/
- public function setRawResult($result) {
+ public function setRawResult(string $result): ISearchResult {
$this->rawResult = $result;
+
+ return $this;
}
/**
* @return string
*/
- public function getRawResult() {
+ public function getRawResult(): string {
return $this->rawResult;
}
/**
* @param IFullTextSearchProvider $provider
+ *
+ * @return ISearchResult
*/
- public function setProvider(IFullTextSearchProvider $provider) {
+ public function setProvider(IFullTextSearchProvider $provider): ISearchResult {
$this->provider = $provider;
+
+ return $this;
}
/**
* @return IFullTextSearchProvider
*/
- public function getProvider() {
+ public function getProvider(): IFullTextSearchProvider {
return $this->provider;
}
@@ -134,30 +151,38 @@ class SearchResult implements \JsonSerializable {
/**
* @return IFullTextSearchPlatform
*/
- public function getPlatform() {
+ public function getPlatform(): IFullTextSearchPlatform {
return $this->platform;
}
/**
* @param IFullTextSearchPlatform $platform
+ *
+ * @return ISearchResult
*/
- public function setPlatform($platform) {
+ public function setPlatform($platform): ISearchResult {
$this->platform = $platform;
+
+ return $this;
}
/**
* @return int
*/
- public function getTotal() {
+ public function getTotal(): int {
return $this->total;
}
/**
* @param int $total
+ *
+ * @return ISearchResult
*/
- public function setTotal($total) {
+ public function setTotal(int $total): ISearchResult {
$this->total = $total;
+
+ return $this;
}
@@ -170,54 +195,70 @@ class SearchResult implements \JsonSerializable {
/**
* @param int $maxScore
+ *
+ * @return ISearchResult
*/
- public function setMaxScore($maxScore) {
+ public function setMaxScore(int $maxScore): ISearchResult {
$this->maxScore = $maxScore;
+
+ return $this;
}
/**
* @return int
*/
- public function getTime() {
+ public function getTime(): int {
return $this->time;
}
/**
* @param int $time
+ *
+ * @return ISearchResult
*/
- public function setTime($time) {
+ public function setTime(int $time): ISearchResult {
$this->time = $time;
+
+ return $this;
}
/**
* @return bool
*/
- public function isTimedOut() {
+ public function isTimedOut(): bool {
return $this->timedOut;
}
/**
* @param bool $timedOut
+ *
+ * @return ISearchResult
*/
- public function setTimedOut($timedOut) {
+ public function setTimedOut(bool $timedOut): ISearchResult {
$this->timedOut = $timedOut;
+
+ return $this;
}
/**
- * @return SearchRequest
+ * @return ISearchRequest
*/
- public function getRequest() {
+ public function getRequest(): ISearchRequest {
return $this->request;
}
/**
- * @param SearchRequest $request
+ * @param ISearchRequest $request
+ *
+ * @return ISearchResult
*/
- public function setRequest($request) {
+ public function setRequest(ISearchRequest $request): ISearchResult {
$this->request = $request;
+
+ return $this;
}
@@ -230,8 +271,8 @@ class SearchResult implements \JsonSerializable {
$provider = [];
if ($providerObj !== null) {
$provider = [
- 'id' => $providerObj->getId(),
- 'name' => $providerObj->getName()
+ 'id' => $providerObj->getId(),
+ 'name' => $providerObj->getName()
];
}
@@ -239,8 +280,8 @@ class SearchResult implements \JsonSerializable {
$platform = [];
if ($platformObj !== null) {
$platform = [
- 'id' => $platformObj->getId(),
- 'name' => $platformObj->getName()
+ 'id' => $platformObj->getId(),
+ 'name' => $platformObj->getName()
];
}
@@ -258,4 +299,32 @@ class SearchResult implements \JsonSerializable {
]
];
}
+
+ /**
+ * @since 15.0.0
+ *
+ * @param string $category
+ * @param string $value
+ * @param int $count
+ *
+ * @return ISearchResult
+ */
+ public function addAggregation(string $category, string $value, int $count): ISearchResult {
+ // TODO: Implement addAggregation() method.
+
+ return $this;
+ }
+
+ /**
+ * @since 15.0.0
+ *
+ * @param string $category
+ *
+ * @return array
+ */
+ public function getAggregations(string $category): array {
+ // TODO: Implement getAggregations() method.
+
+ return [];
+ }
}
diff --git a/lib/Model/Tick.php b/lib/Model/Tick.php
index 865bb86..bd7649d 100644
--- a/lib/Model/Tick.php
+++ b/lib/Model/Tick.php
@@ -187,4 +187,35 @@ class Tick {
return $this;
}
-} \ No newline at end of file
+
+ /**
+ * @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];
+
+ }
+}