diff options
Diffstat (limited to 'lib/private/FullTextSearch')
-rw-r--r-- | lib/private/FullTextSearch/FullTextSearchManager.php | 106 | ||||
-rw-r--r-- | lib/private/FullTextSearch/Model/DocumentAccess.php | 108 | ||||
-rw-r--r-- | lib/private/FullTextSearch/Model/IndexDocument.php | 292 | ||||
-rw-r--r-- | lib/private/FullTextSearch/Model/SearchOption.php | 99 | ||||
-rw-r--r-- | lib/private/FullTextSearch/Model/SearchRequestSimpleQuery.php | 62 | ||||
-rw-r--r-- | lib/private/FullTextSearch/Model/SearchTemplate.php | 81 |
6 files changed, 108 insertions, 640 deletions
diff --git a/lib/private/FullTextSearch/FullTextSearchManager.php b/lib/private/FullTextSearch/FullTextSearchManager.php index 6265c6dc94d..989da8d6bae 100644 --- a/lib/private/FullTextSearch/FullTextSearchManager.php +++ b/lib/private/FullTextSearch/FullTextSearchManager.php @@ -3,25 +3,8 @@ declare(strict_types=1); /** - * @copyright 2018, Maxence Lange <maxence@artificial-owl.com> - * - * @author Maxence Lange <maxence@artificial-owl.com> - * - * @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/>. - * + * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OC\FullTextSearch; @@ -39,54 +22,40 @@ use OCP\FullTextSearch\Service\ISearchService; * @package OC\FullTextSearch */ class FullTextSearchManager implements IFullTextSearchManager { + private ?IProviderService $providerService = null; + private ?IIndexService $indexService = null; - /** @var IProviderService */ - private $providerService; - - /** @var IIndexService */ - private $indexService; - - /** @var ISearchService */ - private $searchService; - + private ?ISearchService $searchService = null; /** * @since 15.0.0 - * - * @param IProviderService $providerService */ - public function registerProviderService(IProviderService $providerService) { + public function registerProviderService(IProviderService $providerService): void { $this->providerService = $providerService; } /** * @since 15.0.0 - * - * @param IIndexService $indexService */ - public function registerIndexService(IIndexService $indexService) { + public function registerIndexService(IIndexService $indexService): void { $this->indexService = $indexService; } /** * @since 15.0.0 - * - * @param ISearchService $searchService */ - public function registerSearchService(ISearchService $searchService) { + public function registerSearchService(ISearchService $searchService): void { $this->searchService = $searchService; } /** * @since 16.0.0 - * - * @return bool */ public function isAvailable(): bool { - if ($this->indexService === null || - $this->providerService === null || - $this->searchService === null) { + if ($this->indexService === null + || $this->providerService === null + || $this->searchService === null) { return false; } @@ -95,7 +64,6 @@ class FullTextSearchManager implements IFullTextSearchManager { /** - * @return IProviderService * @throws FullTextSearchAppNotAvailableException */ private function getProviderService(): IProviderService { @@ -108,7 +76,6 @@ class FullTextSearchManager implements IFullTextSearchManager { /** - * @return IIndexService * @throws FullTextSearchAppNotAvailableException */ private function getIndexService(): IIndexService { @@ -121,7 +88,6 @@ class FullTextSearchManager implements IFullTextSearchManager { /** - * @return ISearchService * @throws FullTextSearchAppNotAvailableException */ private function getSearchService(): ISearchService { @@ -136,15 +102,12 @@ class FullTextSearchManager implements IFullTextSearchManager { /** * @throws FullTextSearchAppNotAvailableException */ - public function addJavascriptAPI() { + public function addJavascriptAPI(): void { $this->getProviderService()->addJavascriptAPI(); } /** - * @param string $providerId - * - * @return bool * @throws FullTextSearchAppNotAvailableException */ public function isProviderIndexed(string $providerId): bool { @@ -153,9 +116,6 @@ class FullTextSearchManager implements IFullTextSearchManager { /** - * @param string $providerId - * @param string $documentId - * @return IIndex * @throws FullTextSearchAppNotAvailableException */ public function getIndex(string $providerId, string $documentId): IIndex { @@ -163,46 +123,45 @@ class FullTextSearchManager implements IFullTextSearchManager { } /** - * @param string $providerId - * @param string $documentId - * @param string $userId - * @param int $status - * * @see IIndex for available value for $status. * - * @return IIndex * @throws FullTextSearchAppNotAvailableException */ - public function createIndex(string $providerId, string $documentId, string $userId, int $status = 0): IIndex { + public function createIndex( + string $providerId, + string $documentId, + string $userId, + int $status = 0, + ): IIndex { return $this->getIndexService()->createIndex($providerId, $documentId, $userId, $status); } /** - * @param string $providerId - * @param string $documentId - * @param int $status - * @param bool $reset - * * @see IIndex for available value for $status. * * @throws FullTextSearchAppNotAvailableException */ - public function updateIndexStatus(string $providerId, string $documentId, int $status, bool $reset = false) { + public function updateIndexStatus( + string $providerId, + string $documentId, + int $status, + bool $reset = false, + ): void { $this->getIndexService()->updateIndexStatus($providerId, $documentId, $status, $reset); } /** - * @param string $providerId - * @param array $documentIds - * @param int $status - * @param bool $reset - * * @see IIndex for available value for $status. * * @throws FullTextSearchAppNotAvailableException */ - public function updateIndexesStatus(string $providerId, array $documentIds, int $status, bool $reset = false) { + public function updateIndexesStatus( + string $providerId, + array $documentIds, + int $status, + bool $reset = false, + ): void { $this->getIndexService()->updateIndexesStatus($providerId, $documentIds, $status, $reset); } @@ -212,15 +171,12 @@ class FullTextSearchManager implements IFullTextSearchManager { * * @throws FullTextSearchAppNotAvailableException */ - public function updateIndexes(array $indexes) { + public function updateIndexes(array $indexes): void { $this->getIndexService()->updateIndexes($indexes); } /** - * @param array $request - * @param string $userId - * * @return ISearchResult[] * @throws FullTextSearchAppNotAvailableException */ diff --git a/lib/private/FullTextSearch/Model/DocumentAccess.php b/lib/private/FullTextSearch/Model/DocumentAccess.php index 3fe08dfcc08..9efffeaee88 100644 --- a/lib/private/FullTextSearch/Model/DocumentAccess.php +++ b/lib/private/FullTextSearch/Model/DocumentAccess.php @@ -1,27 +1,9 @@ <?php declare(strict_types=1); - /** - * @copyright 2018 - * - * @author Maxence Lange <maxence@artificial-owl.com> - * - * @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/>. - * + * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OC\FullTextSearch\Model; @@ -49,25 +31,17 @@ use OCP\FullTextSearch\Model\IDocumentAccess; * @package OC\FullTextSearch\Model */ final class DocumentAccess implements IDocumentAccess, JsonSerializable { + private string $ownerId; + private string $viewerId = ''; - /** @var string */ - private $ownerId; - - /** @var string */ - private $viewerId = ''; - - /** @var array */ - private $users = []; + private array $users = []; - /** @var array */ - private $groups = []; + private array $groups = []; - /** @var array */ - private $circles = []; + private array $circles = []; - /** @var array */ - private $links = []; + private array $links = []; /** @@ -76,8 +50,6 @@ final class DocumentAccess implements IDocumentAccess, JsonSerializable { * @since 16.0.0 * * IDocumentAccess constructor. - * - * @param string $ownerId */ public function __construct(string $ownerId = '') { $this->setOwnerId($ownerId); @@ -88,10 +60,6 @@ final class DocumentAccess implements IDocumentAccess, JsonSerializable { * Set the Owner of the document. * * @since 16.0.0 - * - * @param string $ownerId - * - * @return IDocumentAccess */ public function setOwnerId(string $ownerId): IDocumentAccess { $this->ownerId = $ownerId; @@ -103,8 +71,6 @@ final class DocumentAccess implements IDocumentAccess, JsonSerializable { * Get the Owner of the document. * * @since 16.0.0 - * - * @return string */ public function getOwnerId(): string { return $this->ownerId; @@ -115,10 +81,6 @@ final class DocumentAccess implements IDocumentAccess, JsonSerializable { * Set the viewer of the document. * * @since 16.0.0 - * - * @param string $viewerId - * - * @return IDocumentAccess */ public function setViewerId(string $viewerId): IDocumentAccess { $this->viewerId = $viewerId; @@ -130,8 +92,6 @@ final class DocumentAccess implements IDocumentAccess, JsonSerializable { * Get the viewer of the document. * * @since 16.0.0 - * - * @return string */ public function getViewerId(): string { return $this->viewerId; @@ -142,10 +102,6 @@ final class DocumentAccess implements IDocumentAccess, JsonSerializable { * Set the list of users that have read access to the document. * * @since 16.0.0 - * - * @param array $users - * - * @return IDocumentAccess */ public function setUsers(array $users): IDocumentAccess { $this->users = $users; @@ -157,10 +113,6 @@ final class DocumentAccess implements IDocumentAccess, JsonSerializable { * Add an entry to the list of users that have read access to the document. * * @since 16.0.0 - * - * @param string $user - * - * @return IDocumentAccess */ public function addUser(string $user): IDocumentAccess { $this->users[] = $user; @@ -173,10 +125,6 @@ final class DocumentAccess implements IDocumentAccess, JsonSerializable { * document. * * @since 16.0.0 - * - * @param array $users - * - * @return IDocumentAccess */ public function addUsers($users): IDocumentAccess { $this->users = array_merge($this->users, $users); @@ -188,8 +136,6 @@ final class DocumentAccess implements IDocumentAccess, JsonSerializable { * Get the complete list of users that have read access to the document. * * @since 16.0.0 - * - * @return array */ public function getUsers(): array { return $this->users; @@ -200,10 +146,6 @@ final class DocumentAccess implements IDocumentAccess, JsonSerializable { * Set the list of groups that have read access to the document. * * @since 16.0.0 - * - * @param array $groups - * - * @return IDocumentAccess */ public function setGroups(array $groups): IDocumentAccess { $this->groups = $groups; @@ -215,10 +157,6 @@ final class DocumentAccess implements IDocumentAccess, JsonSerializable { * Add an entry to the list of groups that have read access to the document. * * @since 16.0.0 - * - * @param string $group - * - * @return IDocumentAccess */ public function addGroup(string $group): IDocumentAccess { $this->groups[] = $group; @@ -231,12 +169,8 @@ final class DocumentAccess implements IDocumentAccess, JsonSerializable { * document. * * @since 16.0.0 - * - * @param array $groups - * - * @return IDocumentAccess */ - public function addGroups(array $groups) { + public function addGroups(array $groups): IDocumentAccess { $this->groups = array_merge($this->groups, $groups); return $this; @@ -246,8 +180,6 @@ final class DocumentAccess implements IDocumentAccess, JsonSerializable { * Get the complete list of groups that have read access to the document. * * @since 16.0.0 - * - * @return array */ public function getGroups(): array { return $this->groups; @@ -258,10 +190,6 @@ final class DocumentAccess implements IDocumentAccess, JsonSerializable { * Set the list of circles that have read access to the document. * * @since 16.0.0 - * - * @param array $circles - * - * @return IDocumentAccess */ public function setCircles(array $circles): IDocumentAccess { $this->circles = $circles; @@ -273,10 +201,6 @@ final class DocumentAccess implements IDocumentAccess, JsonSerializable { * Add an entry to the list of circles that have read access to the document. * * @since 16.0.0 - * - * @param string $circle - * - * @return IDocumentAccess */ public function addCircle(string $circle): IDocumentAccess { $this->circles[] = $circle; @@ -289,10 +213,6 @@ final class DocumentAccess implements IDocumentAccess, JsonSerializable { * document. * * @since 16.0.0 - * - * @param array $circles - * - * @return IDocumentAccess */ public function addCircles(array $circles): IDocumentAccess { $this->circles = array_merge($this->circles, $circles); @@ -304,8 +224,6 @@ final class DocumentAccess implements IDocumentAccess, JsonSerializable { * Get the complete list of circles that have read access to the document. * * @since 16.0.0 - * - * @return array */ public function getCircles(): array { return $this->circles; @@ -316,10 +234,6 @@ final class DocumentAccess implements IDocumentAccess, JsonSerializable { * Set the list of links that have read access to the document. * * @since 16.0.0 - * - * @param array $links - * - * @return IDocumentAccess */ public function setLinks(array $links): IDocumentAccess { $this->links = $links; @@ -331,8 +245,6 @@ final class DocumentAccess implements IDocumentAccess, JsonSerializable { * Get the list of links that have read access to the document. * * @since 16.0.0 - * - * @return array */ public function getLinks(): array { return $this->links; @@ -341,8 +253,6 @@ final class DocumentAccess implements IDocumentAccess, JsonSerializable { /** * @since 16.0.0 - * - * @return array */ public function jsonSerialize(): array { return [ diff --git a/lib/private/FullTextSearch/Model/IndexDocument.php b/lib/private/FullTextSearch/Model/IndexDocument.php index 3078f12c465..a51447393ed 100644 --- a/lib/private/FullTextSearch/Model/IndexDocument.php +++ b/lib/private/FullTextSearch/Model/IndexDocument.php @@ -1,31 +1,14 @@ <?php declare(strict_types=1); - /** - * @copyright 2018 - * - * @author Maxence Lange <maxence@artificial-owl.com> - * - * @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/>. - * + * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OC\FullTextSearch\Model; use JsonSerializable; +use OCP\FullTextSearch\Exceptions\FullTextSearchIndexNotAvailableException; use OCP\FullTextSearch\Model\IDocumentAccess; use OCP\FullTextSearch\Model\IIndex; use OCP\FullTextSearch\Model\IIndexDocument; @@ -47,64 +30,41 @@ use OCP\FullTextSearch\Model\IIndexDocument; * @package OC\FullTextSearch\Model */ class IndexDocument implements IIndexDocument, JsonSerializable { + protected string $id = ''; + protected DocumentAccess $access; - /** @var string */ - protected $id = ''; - - /** @var string */ - protected $providerId = ''; - - /** @var DocumentAccess */ - protected $access; + protected ?IIndex $index = null; - /** @var IIndex */ - protected $index; + protected int $modifiedTime = 0; - /** @var int */ - protected $modifiedTime = 0; + protected string $source = ''; - /** @var string */ - protected $source = ''; + protected array $tags = []; - /** @var array */ - protected $tags = []; + protected array $metaTags = []; - /** @var array */ - protected $metaTags = []; + protected array $subTags = []; - /** @var array */ - protected $subTags = []; + protected string $title = ''; - /** @var string */ - protected $title = ''; + protected string $content = ''; - /** @var string */ - protected $content = ''; + protected string $hash = ''; - /** @var string */ - protected $hash = ''; + protected array $parts = []; - /** @var array */ - protected $parts = []; + protected string $link = ''; - /** @var string */ - protected $link = ''; + protected array $more = []; - /** @var array */ - protected $more = []; + protected array $excerpts = []; - /** @var array */ - protected $excerpts = []; + protected string $score = ''; - /** @var string */ - protected $score = ''; + protected array $info = []; - /** @var array */ - protected $info = []; - - /** @var int */ - protected $contentEncoded = 0; + protected int $contentEncoded = 0; /** @@ -114,12 +74,11 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * and the Id of the original document. * * @since 15.0.0 - * - * @param string $providerId - * @param string $documentId */ - public function __construct(string $providerId, string $documentId) { - $this->providerId = $providerId; + public function __construct( + protected string $providerId, + string $documentId, + ) { $this->id = $documentId; } @@ -128,8 +87,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * Returns the Id of the original document. * * @since 15.0.0 - * - * @return string */ final public function getId(): string { return $this->id; @@ -140,8 +97,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * Returns the Id of the provider. * * @since 15.0.0 - * - * @return string */ final public function getProviderId(): string { return $this->providerId; @@ -154,10 +109,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * @see IIndex * * @since 15.0.0 - * - * @param IIndex $index - * - * @return IIndexDocument */ final public function setIndex(IIndex $index): IIndexDocument { $this->index = $index; @@ -168,11 +119,14 @@ class IndexDocument implements IIndexDocument, JsonSerializable { /** * Get the Index. * + * @throws FullTextSearchIndexNotAvailableException * @since 15.0.0 - * - * @return IIndex */ final public function getIndex(): IIndex { + if ($this->index === null) { + throw new FullTextSearchIndexNotAvailableException('No IIndex generated'); + } + return $this->index; } @@ -180,22 +134,15 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * return if Index is defined. * * @since 16.0.0 - * - * @return bool */ final public function hasIndex(): bool { - return ($this->index !== null); + return $this->index !== null; } - /** * Set the modified time of the original document. * * @since 15.0.0 - * - * @param int $modifiedTime - * - * @return IIndexDocument */ final public function setModifiedTime(int $modifiedTime): IIndexDocument { $this->modifiedTime = $modifiedTime; @@ -207,8 +154,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * Get the modified time of the original document. * * @since 15.0.0 - * - * @return int */ final public function getModifiedTime(): int { return $this->modifiedTime; @@ -218,10 +163,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * Check if the original document of the IIndexDocument is older than $time. * * @since 15.0.0 - * - * @param int $time - * - * @return bool */ final public function isOlderThan(int $time): bool { return ($this->modifiedTime < $time); @@ -234,10 +175,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * @see IDocumentAccess * * @since 15.0.0 - * - * @param IDocumentAccess $access - * - * @return $this */ final public function setAccess(IDocumentAccess $access): IIndexDocument { $this->access = $access; @@ -249,8 +186,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * Get the IDocumentAccess related to the original document. * * @since 15.0.0 - * - * @return IDocumentAccess */ final public function getAccess(): IDocumentAccess { return $this->access; @@ -261,10 +196,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * Add a tag to the list. * * @since 15.0.0 - * - * @param string $tag - * - * @return IIndexDocument */ final public function addTag(string $tag): IIndexDocument { $this->tags[] = $tag; @@ -276,10 +207,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * Set the list of tags assigned to the original document. * * @since 15.0.0 - * - * @param array $tags - * - * @return IIndexDocument */ final public function setTags(array $tags): IIndexDocument { $this->tags = $tags; @@ -291,8 +218,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * Get the list of tags assigned to the original document. * * @since 15.0.0 - * - * @return array */ final public function getTags(): array { return $this->tags; @@ -303,10 +228,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * Add a meta tag to the list. * * @since 15.0.0 - * - * @param string $tag - * - * @return IIndexDocument */ final public function addMetaTag(string $tag): IIndexDocument { $this->metaTags[] = $tag; @@ -318,10 +239,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * Set the list of meta tags assigned to the original document. * * @since 15.0.0 - * - * @param array $tags - * - * @return IIndexDocument */ final public function setMetaTags(array $tags): IIndexDocument { $this->metaTags = $tags; @@ -333,8 +250,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * Get the list of meta tags assigned to the original document. * * @since 15.0.0 - * - * @return array */ final public function getMetaTags(): array { return $this->metaTags; @@ -345,11 +260,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * Add a sub tag to the list. * * @since 15.0.0 - * - * @param string $sub - * @param string $tag - * - * @return IIndexDocument */ final public function addSubTag(string $sub, string $tag): IIndexDocument { if (!array_key_exists($sub, $this->subTags)) { @@ -366,10 +276,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * Set the list of sub tags assigned to the original document. * * @since 15.0.0 - * - * @param array $tags - * - * @return IIndexDocument */ final public function setSubTags(array $tags): IIndexDocument { $this->subTags = $tags; @@ -383,10 +289,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * dimensional array. * * @since 15.0.0 - * - * @param bool $formatted - * - * @return array */ final public function getSubTags(bool $formatted = false): array { if ($formatted === false) { @@ -410,10 +312,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * Set the source of the original document. * * @since 15.0.0 - * - * @param string $source - * - * @return IIndexDocument */ final public function setSource(string $source): IIndexDocument { $this->source = $source; @@ -425,8 +323,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * Get the source of the original document. * * @since 15.0.0 - * - * @return string */ final public function getSource(): string { return $this->source; @@ -437,10 +333,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * Set the title of the original document. * * @since 15.0.0 - * - * @param string $title - * - * @return IIndexDocument */ final public function setTitle(string $title): IIndexDocument { $this->title = $title; @@ -452,8 +344,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * Get the title of the original document. * * @since 15.0.0 - * - * @return string */ final public function getTitle(): string { return $this->title; @@ -466,11 +356,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * encoded in base64. * * @since 15.0.0 - * - * @param string $content - * @param int $encoded - * - * @return IIndexDocument */ final public function setContent(string $content, int $encoded = 0): IIndexDocument { $this->content = $content; @@ -483,8 +368,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * Get the content of the original document. * * @since 15.0.0 - * - * @return string */ final public function getContent(): string { return $this->content; @@ -494,8 +377,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * Returns the type of the encoding on the content. * * @since 15.0.0 - * - * @return int */ final public function isContentEncoded(): int { return $this->contentEncoded; @@ -505,8 +386,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * Return the size of the content. * * @since 15.0.0 - * - * @return int */ final public function getContentSize(): int { return strlen($this->getContent()); @@ -514,18 +393,16 @@ class IndexDocument implements IIndexDocument, JsonSerializable { /** - * Generate an hash, based on the content of the original document. + * Generate a hash, based on the content of the original document. * * @since 15.0.0 - * - * @return IIndexDocument */ final public function initHash(): IIndexDocument { if ($this->getContent() === '' || is_null($this->getContent())) { return $this; } - $this->hash = hash("md5", $this->getContent()); + $this->hash = hash('md5', $this->getContent()); return $this; } @@ -534,10 +411,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * Set the hash of the original document. * * @since 15.0.0 - * - * @param string $hash - * - * @return IIndexDocument */ final public function setHash(string $hash): IIndexDocument { $this->hash = $hash; @@ -549,8 +422,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * Get the hash of the original document. * * @since 15.0.0 - * - * @return string */ final public function getHash(): string { return $this->hash; @@ -564,11 +435,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * $part string. * * @since 15.0.0 - * - * @param string $part - * @param string $content - * - * @return IIndexDocument */ final public function addPart(string $part, string $content): IIndexDocument { $this->parts[$part] = $content; @@ -580,10 +446,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * Set all parts and their content. * * @since 15.0.0 - * - * @param array $parts - * - * @return IIndexDocument */ final public function setParts(array $parts): IIndexDocument { $this->parts = $parts; @@ -595,8 +457,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * Get all parts of the IIndexDocument. * * @since 15.0.0 - * - * @return array */ final public function getParts(): array { return $this->parts; @@ -607,10 +467,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * Add a link, usable by the frontend. * * @since 15.0.0 - * - * @param string $link - * - * @return IIndexDocument */ final public function setLink(string $link): IIndexDocument { $this->link = $link; @@ -622,8 +478,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * Get the link. * * @since 15.0.0 - * - * @return string */ final public function getLink(): string { return $this->link; @@ -634,10 +488,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * Set more information that couldn't be set using other method. * * @since 15.0.0 - * - * @param array $more - * - * @return IIndexDocument */ final public function setMore(array $more): IIndexDocument { $this->more = $more; @@ -649,8 +499,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * Get more information. * * @since 15.0.0 - * - * @return array */ final public function getMore(): array { return $this->more; @@ -662,15 +510,10 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * on the search request. * * @since 16.0.0 - * - * @param string $source - * @param string $excerpt - * - * @return IIndexDocument */ final public function addExcerpt(string $source, string $excerpt): IIndexDocument { - $this->excerpts[] = - [ + $this->excerpts[] + = [ 'source' => $source, 'excerpt' => $this->cleanExcerpt($excerpt) ]; @@ -683,10 +526,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * Set all excerpts of the content of the original document. * * @since 16.0.0 - * - * @param array $excerpts - * - * @return IIndexDocument */ final public function setExcerpts(array $excerpts): IIndexDocument { $new = []; @@ -706,8 +545,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * Get all excerpts of the content of the original document. * * @since 15.0.0 - * - * @return array */ final public function getExcerpts(): array { return $this->excerpts; @@ -717,14 +554,11 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * Clean excerpt. * * @since 16.0.0 - * - * @param string $excerpt - * @return string */ private function cleanExcerpt(string $excerpt): string { - $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); $excerpt = str_replace("\n", ' ', $excerpt); $excerpt = str_replace("\r", ' ', $excerpt); $excerpt = str_replace("\t", ' ', $excerpt); @@ -738,10 +572,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * request. * * @since 15.0.0 - * - * @param string $score - * - * @return IIndexDocument */ final public function setScore(string $score): IIndexDocument { $this->score = $score; @@ -753,8 +583,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * Get the score. * * @since 15.0.0 - * - * @return string */ final public function getScore(): string { return $this->score; @@ -769,11 +597,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * indexing. * * @since 15.0.0 - * - * @param string $info - * @param string $value - * - * @return IIndexDocument */ final public function setInfo(string $info, string $value): IIndexDocument { $this->info[$info] = $value; @@ -785,11 +608,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * Get an information about a document. (string) * * @since 15.0.0 - * - * @param string $info - * @param string $default - * - * @return string */ final public function getInfo(string $info, string $default = ''): string { if (!key_exists($info, $this->info)) { @@ -807,11 +625,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * indexing. * * @since 15.0.0 - * - * @param string $info - * @param array $value - * - * @return IIndexDocument */ final public function setInfoArray(string $info, array $value): IIndexDocument { $this->info[$info] = $value; @@ -823,11 +636,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * Get an information about a document. (array) * * @since 15.0.0 - * - * @param string $info - * @param array $default - * - * @return array */ final public function getInfoArray(string $info, array $default = []): array { if (!key_exists($info, $this->info)) { @@ -845,11 +653,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * indexing. * * @since 15.0.0 - * - * @param string $info - * @param int $value - * - * @return IIndexDocument */ final public function setInfoInt(string $info, int $value): IIndexDocument { $this->info[$info] = $value; @@ -861,11 +664,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * Get an information about a document. (int) * * @since 15.0.0 - * - * @param string $info - * @param int $default - * - * @return int */ final public function getInfoInt(string $info, int $default = 0): int { if (!key_exists($info, $this->info)) { @@ -883,11 +681,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * indexing. * * @since 15.0.0 - * - * @param string $info - * @param bool $value - * - * @return IIndexDocument */ final public function setInfoBool(string $info, bool $value): IIndexDocument { $this->info[$info] = $value; @@ -899,11 +692,6 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * Get an information about a document. (bool) * * @since 15.0.0 - * - * @param string $info - * @param bool $default - * - * @return bool */ final public function getInfoBool(string $info, bool $default = false): bool { if (!key_exists($info, $this->info)) { @@ -917,13 +705,11 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * Get all info. * * @since 15.0.0 - * - * @return array */ final public function getInfoAll(): array { $info = []; foreach ($this->info as $k => $v) { - if (substr($k, 0, 1) === '_') { + if (str_starts_with($k, '_')) { continue; } diff --git a/lib/private/FullTextSearch/Model/SearchOption.php b/lib/private/FullTextSearch/Model/SearchOption.php index c4c63a801a3..c7769a62138 100644 --- a/lib/private/FullTextSearch/Model/SearchOption.php +++ b/lib/private/FullTextSearch/Model/SearchOption.php @@ -1,27 +1,9 @@ <?php declare(strict_types=1); - /** - * @copyright 2018 - * - * @author Maxence Lange <maxence@artificial-owl.com> - * - * @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/>. - * + * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OC\FullTextSearch\Model; @@ -36,24 +18,6 @@ use OCP\FullTextSearch\Model\ISearchOption; * @package OC\FullTextSearch\Model */ final class SearchOption implements ISearchOption, JsonSerializable { - - - /** @var string */ - private $name = ''; - - /** @var string */ - private $title = ''; - - /** @var string */ - private $type = ''; - - /** @var string */ - private $size = ''; - - /** @var string */ - private $placeholder = ''; - - /** * * * @@ -106,37 +70,28 @@ final class SearchOption implements ISearchOption, JsonSerializable { /** * ISearchOption constructor. * - * Some value can be setduring the creation of the object. + * Some value can be set during the creation of the object. * * @since 15.0.0 - * - * @param string $name - * @param string $title - * @param string $type - * @param string $size - * @param string $placeholder */ - public function __construct(string $name = '', string $title = '', string $type = '', string $size = '', string $placeholder = '') { - $this->name = $name; - $this->title = $title; - $this->type = $type; - $this->size = $size; - $this->placeholder = $placeholder; + public function __construct( + private string $name = '', + private string $title = '', + private string $type = '', + private string $size = '', + private string $placeholder = '', + ) { } /** * Set the name/key of the option. - * The string should only contains alphanumerical chars and underscore. - * The key can be retrieve when using ISearchRequest::getOption + * The string should only contain alphanumerical chars and underscore. + * The key can be retrieved when using ISearchRequest::getOption * * @see ISearchRequest::getOption * * @since 15.0.0 - * - * @param string $name - * - * @return ISearchOption */ public function setName(string $name): ISearchOption { $this->name = $name; @@ -148,8 +103,6 @@ final class SearchOption implements ISearchOption, JsonSerializable { * Get the name/key of the option. * * @since 15.0.0 - * - * @return string */ public function getName(): string { return $this->name; @@ -160,10 +113,6 @@ final class SearchOption implements ISearchOption, JsonSerializable { * Set the title/display name of the option. * * @since 15.0.0 - * - * @param string $title - * - * @return ISearchOption */ public function setTitle(string $title): ISearchOption { $this->title = $title; @@ -175,8 +124,6 @@ final class SearchOption implements ISearchOption, JsonSerializable { * Get the title of the option. * * @since 15.0.0 - * - * @return string */ public function getTitle(): string { return $this->title; @@ -188,10 +135,6 @@ final class SearchOption implements ISearchOption, JsonSerializable { * $type can be ISearchOption::CHECKBOX or ISearchOption::INPUT * * @since 15.0.0 - * - * @param string $type - * - * @return ISearchOption */ public function setType(string $type): ISearchOption { $this->type = $type; @@ -203,8 +146,6 @@ final class SearchOption implements ISearchOption, JsonSerializable { * Get the type of the option. * * @since 15.0.0 - * - * @return string */ public function getType(): string { return $this->type; @@ -216,10 +157,6 @@ final class SearchOption implements ISearchOption, JsonSerializable { * Value can be ISearchOption::INPUT_SMALL or not defined. * * @since 15.0.0 - * - * @param string $size - * - * @return ISearchOption */ public function setSize(string $size): ISearchOption { $this->size = $size; @@ -231,23 +168,16 @@ final class SearchOption implements ISearchOption, JsonSerializable { * Get the size of the INPUT. * * @since 15.0.0 - * - * @return string */ public function getSize(): string { return $this->size; } - /** * In case of Type is , set the placeholder to be displayed in the input * field. * * @since 15.0.0 - * - * @param string $placeholder - * - * @return ISearchOption */ public function setPlaceholder(string $placeholder): ISearchOption { $this->placeholder = $placeholder; @@ -259,18 +189,13 @@ final class SearchOption implements ISearchOption, JsonSerializable { * Get the placeholder. * * @since 15.0.0 - * - * @return string */ public function getPlaceholder(): string { return $this->placeholder; } - /** * @since 15.0.0 - * - * @return array */ public function jsonSerialize(): array { return [ diff --git a/lib/private/FullTextSearch/Model/SearchRequestSimpleQuery.php b/lib/private/FullTextSearch/Model/SearchRequestSimpleQuery.php index d6bfe6d9102..5b075daf7e6 100644 --- a/lib/private/FullTextSearch/Model/SearchRequestSimpleQuery.php +++ b/lib/private/FullTextSearch/Model/SearchRequestSimpleQuery.php @@ -1,28 +1,9 @@ <?php declare(strict_types=1); - /** - * @copyright 2018 - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Maxence Lange <maxence@artificial-owl.com> - * - * @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/>. - * + * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OC\FullTextSearch\Model; @@ -37,36 +18,24 @@ use OCP\FullTextSearch\Model\ISearchRequestSimpleQuery; * @package OC\FullTextSearch\Model */ final class SearchRequestSimpleQuery implements ISearchRequestSimpleQuery, JsonSerializable { - - - /** @var int */ - private $type = 0; - - /** @var string */ - private $field = ''; - - /** @var array */ - private $values = []; + private array $values = []; /** * SearchRequestQuery constructor. * - * @param $type - * @param $field - * * @since 17.0.0 */ - public function __construct(string $field, int $type) { - $this->field = $field; - $this->type = $type; + public function __construct( + private string $field, + private int $type, + ) { } /** * Get the compare type of the query * - * @return int * @since 17.0.0 */ public function getType(): int { @@ -77,7 +46,6 @@ final class SearchRequestSimpleQuery implements ISearchRequestSimpleQuery, JsonS /** * Get the field to apply query * - * @return string * @since 17.0.0 */ public function getField(): string { @@ -87,9 +55,6 @@ final class SearchRequestSimpleQuery implements ISearchRequestSimpleQuery, JsonS /** * Set the field to apply query * - * @param string $field - * - * @return ISearchRequestSimpleQuery * @since 17.0.0 */ public function setField(string $field): ISearchRequestSimpleQuery { @@ -102,7 +67,6 @@ final class SearchRequestSimpleQuery implements ISearchRequestSimpleQuery, JsonS /** * Get the value to compare (string) * - * @return array * @since 17.0.0 */ public function getValues(): array { @@ -113,9 +77,6 @@ final class SearchRequestSimpleQuery implements ISearchRequestSimpleQuery, JsonS /** * Add value to compare (string) * - * @param string $value - * - * @return ISearchRequestSimpleQuery * @since 17.0.0 */ public function addValue(string $value): ISearchRequestSimpleQuery { @@ -127,9 +88,6 @@ final class SearchRequestSimpleQuery implements ISearchRequestSimpleQuery, JsonS /** * Add value to compare (int) * - * @param int $value - * - * @return ISearchRequestSimpleQuery * @since 17.0.0 */ public function addValueInt(int $value): ISearchRequestSimpleQuery { @@ -141,9 +99,6 @@ final class SearchRequestSimpleQuery implements ISearchRequestSimpleQuery, JsonS /** * Add value to compare (array) * - * @param array $value - * - * @return ISearchRequestSimpleQuery * @since 17.0.0 */ public function addValueArray(array $value): ISearchRequestSimpleQuery { @@ -155,9 +110,6 @@ final class SearchRequestSimpleQuery implements ISearchRequestSimpleQuery, JsonS /** * Add value to compare (bool) * - * @param bool $value - * - * @return ISearchRequestSimpleQuery * @since 17.0.0 */ public function addValueBool(bool $value): ISearchRequestSimpleQuery { diff --git a/lib/private/FullTextSearch/Model/SearchTemplate.php b/lib/private/FullTextSearch/Model/SearchTemplate.php index eb1ab8ead84..6f9a04a911e 100644 --- a/lib/private/FullTextSearch/Model/SearchTemplate.php +++ b/lib/private/FullTextSearch/Model/SearchTemplate.php @@ -3,25 +3,8 @@ declare(strict_types=1); /** - * @copyright 2018 - * - * @author Maxence Lange <maxence@artificial-owl.com> - * - * @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/>. - * + * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OC\FullTextSearch\Model; @@ -37,7 +20,7 @@ use OCP\FullTextSearch\Model\ISearchTemplate; * when the getSearchTemplate() method is called. * * The object will contain templates to be displayed, and the list of the different - * options to be available to the user when he start a new search. + * options to be available to the user when they start a new search. * * The display of the Options is generated by the FullTextSearch app and Options * can be displayed in 2 places: @@ -56,23 +39,13 @@ use OCP\FullTextSearch\Model\ISearchTemplate; * @package OC\FullTextSearch\Model */ final class SearchTemplate implements ISearchTemplate, JsonSerializable { - - - /** @var string */ - private $icon = ''; - - /** @var string */ - private $css = ''; - - /** @var string */ - private $template = ''; + private string $template = ''; /** @var SearchOption[] */ - private $panelOptions = []; + private array $panelOptions = []; /** @var SearchOption[] */ - private $navigationOptions = []; - + private array $navigationOptions = []; /** * ISearchTemplate constructor. @@ -81,13 +54,11 @@ final class SearchTemplate implements ISearchTemplate, JsonSerializable { * creation of the object. * * @since 15.0.0 - * - * @param string $icon - * @param string $css */ - public function __construct(string $icon = '', string $css = '') { - $this->icon = $icon; - $this->css = $css; + public function __construct( + private string $icon = '', + private string $css = '', + ) { } @@ -96,10 +67,6 @@ final class SearchTemplate implements ISearchTemplate, JsonSerializable { * FullTextSearch navigation page, in front of the related Content Provider. * * @since 15.0.0 - * - * @param string $class - * - * @return ISearchTemplate */ public function setIcon(string $class): ISearchTemplate { $this->icon = $class; @@ -109,10 +76,6 @@ final class SearchTemplate implements ISearchTemplate, JsonSerializable { /** * Get the class of the icon. - * - * @since 15.0.0 - * - * @return string */ public function getIcon(): string { return $this->icon; @@ -123,10 +86,6 @@ final class SearchTemplate implements ISearchTemplate, JsonSerializable { * Set the path of a CSS file that will be loaded when needed. * * @since 15.0.0 - * - * @param string $css - * - * @return ISearchTemplate */ public function setCss(string $css): ISearchTemplate { $this->css = $css; @@ -138,8 +97,6 @@ final class SearchTemplate implements ISearchTemplate, JsonSerializable { * Get the path of the CSS file. * * @since 15.0.0 - * - * @return string */ public function getCss(): string { return $this->css; @@ -153,10 +110,6 @@ final class SearchTemplate implements ISearchTemplate, JsonSerializable { * a way not generated by FullTextSearch * * @since 15.0.0 - * - * @param string $template - * - * @return ISearchTemplate */ public function setTemplate(string $template): ISearchTemplate { $this->template = $template; @@ -168,8 +121,6 @@ final class SearchTemplate implements ISearchTemplate, JsonSerializable { * Get the path of the template file. * * @since 15.0.0 - * - * @return string */ public function getTemplate(): string { return $this->template; @@ -183,10 +134,6 @@ final class SearchTemplate implements ISearchTemplate, JsonSerializable { * @see ISearchOption * * @since 15.0.0 - * - * @param ISearchOption $option - * - * @return ISearchTemplate */ public function addPanelOption(ISearchOption $option): ISearchTemplate { $this->panelOptions[] = $option; @@ -212,10 +159,6 @@ final class SearchTemplate implements ISearchTemplate, JsonSerializable { * @see ISearchOption * * @since 15.0.0 - * - * @param ISearchOption $option - * - * @return ISearchTemplate */ public function addNavigationOption(ISearchOption $option): ISearchTemplate { $this->navigationOptions[] = $option; @@ -227,8 +170,6 @@ final class SearchTemplate implements ISearchTemplate, JsonSerializable { * Get all options to be displayed in the FullTextSearch navigation page. * * @since 15.0.0 - * - * @return array */ public function getNavigationOptions(): array { return $this->navigationOptions; @@ -237,8 +178,6 @@ final class SearchTemplate implements ISearchTemplate, JsonSerializable { /** * @since 15.0.0 - * - * @return array */ public function jsonSerialize(): array { return [ |