diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2019-02-20 09:38:19 -0100 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2019-03-04 09:54:45 -0100 |
commit | a644ad5793b75f6cb4a5ddcd6ac33619764db738 (patch) | |
tree | 9ec50b694b00469970998e1cc9c252dafacc2b35 /lib/public | |
parent | 358c9e649bebdc82424b999e9941c37541e730ea (diff) | |
download | nextcloud-server-a644ad5793b75f6cb4a5ddcd6ac33619764db738.tar.gz nextcloud-server-a644ad5793b75f6cb4a5ddcd6ac33619764db738.zip |
moving final class to private, new interface in public
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib/public')
-rw-r--r-- | lib/public/Files_FullTextSearch/Model/AFilesDocument.php | 7 | ||||
-rw-r--r-- | lib/public/FullTextSearch/IFullTextSearchPlatform.php | 16 | ||||
-rw-r--r-- | lib/public/FullTextSearch/IFullTextSearchProvider.php | 48 | ||||
-rw-r--r-- | lib/public/FullTextSearch/Model/IDocumentAccess.php (renamed from lib/public/FullTextSearch/Model/DocumentAccess.php) | 171 | ||||
-rw-r--r-- | lib/public/FullTextSearch/Model/IIndex.php | 4 | ||||
-rw-r--r-- | lib/public/FullTextSearch/Model/IIndexDocument.php | 636 | ||||
-rw-r--r-- | lib/public/FullTextSearch/Model/ISearchOption.php | 161 | ||||
-rw-r--r-- | lib/public/FullTextSearch/Model/ISearchResult.php | 14 | ||||
-rw-r--r-- | lib/public/FullTextSearch/Model/ISearchTemplate.php (renamed from lib/public/FullTextSearch/Model/SearchTemplate.php) | 123 | ||||
-rw-r--r-- | lib/public/FullTextSearch/Model/SearchOption.php | 296 |
10 files changed, 899 insertions, 577 deletions
diff --git a/lib/public/Files_FullTextSearch/Model/AFilesDocument.php b/lib/public/Files_FullTextSearch/Model/AFilesDocument.php index 3eed956df84..143788f33ad 100644 --- a/lib/public/Files_FullTextSearch/Model/AFilesDocument.php +++ b/lib/public/Files_FullTextSearch/Model/AFilesDocument.php @@ -31,13 +31,14 @@ declare(strict_types=1); namespace OCP\Files_FullTextSearch\Model; -use OCP\FullTextSearch\Model\IndexDocument; +use OC\FullTextSearch\Model\IndexDocument; +use OCP\FullTextSearch\Model\IIndexDocument; /** * Abstract Class AFilesDocument * - * This is mostly used by 3rd party apps that want to complete the IndexDocument + * This is mostly used by 3rd party apps that want to complete the IIndexDocument * with more information about a file before its index: * * \OC::$server->getEventDispatcher()->addListener( @@ -48,7 +49,6 @@ use OCP\FullTextSearch\Model\IndexDocument; * * // @var \OCP\Files_FullTextSearch\Model\AFilesDocument $document * $document = $e->getArgument('document'); - * * } * ); * @@ -107,6 +107,5 @@ abstract class AFilesDocument extends IndexDocument { */ abstract public function getPath(): string; - } diff --git a/lib/public/FullTextSearch/IFullTextSearchPlatform.php b/lib/public/FullTextSearch/IFullTextSearchPlatform.php index f3f9a35bae2..01016269f6b 100644 --- a/lib/public/FullTextSearch/IFullTextSearchPlatform.php +++ b/lib/public/FullTextSearch/IFullTextSearchPlatform.php @@ -31,9 +31,9 @@ declare(strict_types=1); namespace OCP\FullTextSearch; -use OCP\FullTextSearch\Model\DocumentAccess; +use OCP\FullTextSearch\Model\IDocumentAccess; use OCP\FullTextSearch\Model\IIndex; -use OCP\FullTextSearch\Model\IndexDocument; +use OCP\FullTextSearch\Model\IIndexDocument; use OCP\FullTextSearch\Model\IRunner; use OCP\FullTextSearch\Model\ISearchResult; @@ -190,11 +190,11 @@ interface IFullTextSearchPlatform { * * @since 15.0.0 * - * @param IndexDocument $document + * @param IIndexDocument $document * * @return IIndex */ - public function indexDocument(IndexDocument $document): IIndex; + public function indexDocument(IIndexDocument $document): IIndex; /** @@ -204,9 +204,9 @@ interface IFullTextSearchPlatform { * @since 15.0.0 * * @param ISearchResult $result - * @param DocumentAccess $access + * @param IDocumentAccess $access */ - public function searchRequest(ISearchResult $result, DocumentAccess $access); + public function searchRequest(ISearchResult $result, IDocumentAccess $access); /** @@ -218,9 +218,9 @@ interface IFullTextSearchPlatform { * @param string $providerId * @param string $documentId * - * @return IndexDocument + * @return IIndexDocument */ - public function getDocument(string $providerId, string $documentId): IndexDocument; + public function getDocument(string $providerId, string $documentId): IIndexDocument; } diff --git a/lib/public/FullTextSearch/IFullTextSearchProvider.php b/lib/public/FullTextSearch/IFullTextSearchProvider.php index a46ef051491..b72c9e55435 100644 --- a/lib/public/FullTextSearch/IFullTextSearchProvider.php +++ b/lib/public/FullTextSearch/IFullTextSearchProvider.php @@ -33,11 +33,11 @@ namespace OCP\FullTextSearch; use OCP\FullTextSearch\Model\IIndex; use OCP\FullTextSearch\Model\IIndexOptions; -use OCP\FullTextSearch\Model\IndexDocument; +use OCP\FullTextSearch\Model\IIndexDocument; use OCP\FullTextSearch\Model\IRunner; use OCP\FullTextSearch\Model\ISearchRequest; use OCP\FullTextSearch\Model\ISearchResult; -use OCP\FullTextSearch\Model\SearchTemplate; +use OCP\FullTextSearch\Model\ISearchTemplate; /** @@ -115,16 +115,16 @@ interface IFullTextSearchProvider { /** - * Must returns a SearchTemplate that contains displayable items and + * Must returns a ISearchTemplate that contains displayable items and * available options to users when searching. * - * @see SearchTemplate + * @see ISearchTemplate * * @since 15.0.0 * - * @return SearchTemplate + * @return ISearchTemplate */ - public function getSearchTemplate(): SearchTemplate; + public function getSearchTemplate(): ISearchTemplate; /** @@ -182,19 +182,19 @@ interface IFullTextSearchProvider { /** - * Returns all indexable document for a user as an array of IndexDocument. + * Returns all indexable document for a user as an array of IIndexDocument. * - * There is no need to fill each IndexDocument with content; at this point, + * There is no need to fill each IIndexDocument with content; at this point, * only fill the object with the minimum information to not waste memory while * still being able to identify the document it is referring to. * * FullTextSearch will call 2 other methods of this interface for each - * IndexDocument of the array, prior to their indexing: + * IIndexDocument of the array, prior to their indexing: * * - first, to compare the date of the last index, - * - then, to fill each IndexDocument with complete data + * - then, to fill each IIndexDocument with complete data * - * @see IndexDocument + * @see IIndexDocument * * @since 15.0.0 * -> 16.0.0: the parameter "$chunk" was added @@ -202,7 +202,7 @@ interface IFullTextSearchProvider { * @param string $userId * @param string $chunk * - * @return IndexDocument[] + * @return IIndexDocument[] */ public function generateIndexableDocuments(string $userId, string $chunk): array; @@ -210,40 +210,40 @@ interface IFullTextSearchProvider { /** * Called to verify that the document is not already indexed and that the * old index is not up-to-date, using the IIndex from - * IndexDocument->getIndex() + * IIndexDocument->getIndex() * - * Returning true will not queue the current IndexDocument to any further + * Returning true will not queue the current IIndexDocument to any further * operation and will continue on the next element from the list returned by * generateIndexableDocuments(). * * @since 15.0.0 * - * @param IndexDocument $document + * @param IIndexDocument $document * * @return bool */ - public function isDocumentUpToDate(IndexDocument $document): bool; + public function isDocumentUpToDate(IIndexDocument $document): bool; /** - * Must fill IndexDocument with all information relative to the document, + * Must fill IIndexDocument with all information relative to the document, * before its indexing by the Search Platform. * * Method is called for each element returned previously by * generateIndexableDocuments(). * - * @see IndexDocument + * @see IIndexDocument * * @since 15.0.0 * - * @param IndexDocument $document + * @param IIndexDocument $document */ - public function fillIndexDocument(IndexDocument $document); + public function fillIndexDocument(IIndexDocument $document); /** - * The Search Provider must create and return an IndexDocument - * based on the IIndex and its status. The IndexDocument must contains all + * The Search Provider must create and return an IIndexDocument + * based on the IIndex and its status. The IIndexDocument must contains all * information as it will be send for indexing. * * Method is called during a cron or a ./occ fulltextsearch:live after a @@ -253,9 +253,9 @@ interface IFullTextSearchProvider { * * @param IIndex $index * - * @return IndexDocument + * @return IIndexDocument */ - public function updateDocument(IIndex $index): IndexDocument; + public function updateDocument(IIndex $index): IIndexDocument; /** diff --git a/lib/public/FullTextSearch/Model/DocumentAccess.php b/lib/public/FullTextSearch/Model/IDocumentAccess.php index ef199fb7385..66697340a8c 100644 --- a/lib/public/FullTextSearch/Model/DocumentAccess.php +++ b/lib/public/FullTextSearch/Model/IDocumentAccess.php @@ -31,11 +31,8 @@ declare(strict_types=1); namespace OCP\FullTextSearch\Model; -use JsonSerializable; - - /** - * Class DocumentAccess + * Interface IDocumentAccess * * This object is used as a data transfer object when * @@ -43,36 +40,18 @@ use JsonSerializable; * - generating a search request. * * During the index, it is used to define which users, groups, circles, ... - * have access to the IndexDocument + * have access to the IIndexDocument * * During the search, it is internally use to define to which group, circles, ... * a user that perform the search belongs to. * - * @see IndexDocument::setAccess + * @see IIndexDocument::setAccess * * @since 15.0.0 * * @package OCP\FullTextSearch\Model */ -final 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 = []; +interface IDocumentAccess { /** @@ -80,13 +59,11 @@ final class DocumentAccess implements JsonSerializable { * * @since 15.0.0 * - * DocumentAccess constructor. + * IDocumentAccess constructor. * * @param string $ownerId */ - public function __construct(string $ownerId = '') { - $this->setOwnerId($ownerId); - } + public function __construct(string $ownerId = ''); /** @@ -96,13 +73,9 @@ final class DocumentAccess implements JsonSerializable { * * @param string $ownerId * - * @return DocumentAccess + * @return IDocumentAccess */ - public function setOwnerId(string $ownerId) { - $this->ownerId = $ownerId; - - return $this; - } + public function setOwnerId(string $ownerId): IDocumentAccess; /** * Get the Owner of the document. @@ -111,9 +84,7 @@ final class DocumentAccess implements JsonSerializable { * * @return string */ - public function getOwnerId(): string { - return $this->ownerId; - } + public function getOwnerId(): string; /** @@ -123,13 +94,9 @@ final class DocumentAccess implements JsonSerializable { * * @param string $viewerId * - * @return DocumentAccess + * @return IDocumentAccess */ - public function setViewerId(string $viewerId): DocumentAccess { - $this->viewerId = $viewerId; - - return $this; - } + public function setViewerId(string $viewerId): IDocumentAccess; /** * Get the viewer of the document. @@ -138,9 +105,7 @@ final class DocumentAccess implements JsonSerializable { * * @return string */ - public function getViewerId(): string { - return $this->viewerId; - } + public function getViewerId(): string; /** @@ -150,13 +115,9 @@ final class DocumentAccess implements JsonSerializable { * * @param array $users * - * @return DocumentAccess + * @return IDocumentAccess */ - public function setUsers(array $users): DocumentAccess { - $this->users = $users; - - return $this; - } + public function setUsers(array $users): IDocumentAccess; /** * Add an entry to the list of users that have read access to the document. @@ -165,13 +126,9 @@ final class DocumentAccess implements JsonSerializable { * * @param string $user * - * @return DocumentAccess + * @return IDocumentAccess */ - public function addUser(string $user): DocumentAccess { - $this->users[] = $user; - - return $this; - } + public function addUser(string $user): IDocumentAccess; /** * Add multiple entries to the list of users that have read access to the @@ -181,13 +138,9 @@ final class DocumentAccess implements JsonSerializable { * * @param array $users * - * @return DocumentAccess + * @return IDocumentAccess */ - public function addUsers($users): DocumentAccess { - $this->users = array_merge($this->users, $users); - - return $this; - } + public function addUsers($users): IDocumentAccess; /** * Get the complete list of users that have read access to the document. @@ -196,9 +149,7 @@ final class DocumentAccess implements JsonSerializable { * * @return array */ - public function getUsers(): array { - return $this->users; - } + public function getUsers(): array; /** @@ -208,13 +159,9 @@ final class DocumentAccess implements JsonSerializable { * * @param array $groups * - * @return DocumentAccess + * @return IDocumentAccess */ - public function setGroups(array $groups): DocumentAccess { - $this->groups = $groups; - - return $this; - } + public function setGroups(array $groups): IDocumentAccess; /** * Add an entry to the list of groups that have read access to the document. @@ -223,13 +170,9 @@ final class DocumentAccess implements JsonSerializable { * * @param string $group * - * @return DocumentAccess + * @return IDocumentAccess */ - public function addGroup(string $group): DocumentAccess { - $this->groups[] = $group; - - return $this; - } + public function addGroup(string $group): IDocumentAccess; /** * Add multiple entries to the list of groups that have read access to the @@ -239,13 +182,9 @@ final class DocumentAccess implements JsonSerializable { * * @param array $groups * - * @return DocumentAccess + * @return IDocumentAccess */ - public function addGroups(array $groups) { - $this->groups = array_merge($this->groups, $groups); - - return $this; - } + public function addGroups(array $groups); /** * Get the complete list of groups that have read access to the document. @@ -254,9 +193,7 @@ final class DocumentAccess implements JsonSerializable { * * @return array */ - public function getGroups(): array { - return $this->groups; - } + public function getGroups(): array; /** @@ -266,13 +203,9 @@ final class DocumentAccess implements JsonSerializable { * * @param array $circles * - * @return DocumentAccess + * @return IDocumentAccess */ - public function setCircles(array $circles): DocumentAccess { - $this->circles = $circles; - - return $this; - } + public function setCircles(array $circles): IDocumentAccess; /** * Add an entry to the list of circles that have read access to the document. @@ -281,13 +214,9 @@ final class DocumentAccess implements JsonSerializable { * * @param string $circle * - * @return DocumentAccess + * @return IDocumentAccess */ - public function addCircle(string $circle): DocumentAccess { - $this->circles[] = $circle; - - return $this; - } + public function addCircle(string $circle): IDocumentAccess; /** * Add multiple entries to the list of groups that have read access to the @@ -297,13 +226,9 @@ final class DocumentAccess implements JsonSerializable { * * @param array $circles * - * @return DocumentAccess + * @return IDocumentAccess */ - public function addCircles(array $circles): DocumentAccess { - $this->circles = array_merge($this->circles, $circles); - - return $this; - } + public function addCircles(array $circles): IDocumentAccess; /** * Get the complete list of circles that have read access to the document. @@ -312,9 +237,7 @@ final class DocumentAccess implements JsonSerializable { * * @return array */ - public function getCircles(): array { - return $this->circles; - } + public function getCircles(): array; /** @@ -324,13 +247,9 @@ final class DocumentAccess implements JsonSerializable { * * @param array $links * - * @return DocumentAccess + * @return IDocumentAccess */ - public function setLinks(array $links): DocumentAccess { - $this->links = $links; - - return $this; - } + public function setLinks(array $links): IDocumentAccess; /** * Get the list of links that have read access to the document. @@ -339,25 +258,7 @@ final class DocumentAccess implements JsonSerializable { * * @return array */ - public function getLinks(): array { - return $this->links; - } + public function getLinks(): array; - - /** - * @since 15.0.0 - * - * @return array - */ - public function jsonSerialize(): array { - return [ - 'ownerId' => $this->getOwnerId(), - 'viewerId' => $this->getViewerId(), - 'users' => $this->getUsers(), - 'groups' => $this->getGroups(), - 'circles' => $this->getCircles(), - 'links' => $this->getLinks() - ]; - } } diff --git a/lib/public/FullTextSearch/Model/IIndex.php b/lib/public/FullTextSearch/Model/IIndex.php index adfdf34aee6..d8a1db1a1b7 100644 --- a/lib/public/FullTextSearch/Model/IIndex.php +++ b/lib/public/FullTextSearch/Model/IIndex.php @@ -38,10 +38,10 @@ namespace OCP\FullTextSearch\Model; * regarding the date of the last index and the date of the last modification * of the original document. * - * The uniqueness of an IndexDocument is made by the Id of the Content Provider + * The uniqueness of an IIndexDocument is made by the Id of the Content Provider * and the Id of the original document within the Content Provider. * - * We will call original document the source from which the IndexDocument is + * We will call original document the source from which the IIndexDocument is * generated. As an example, an original document can be a file, a mail, ... * * @since 15.0.0 diff --git a/lib/public/FullTextSearch/Model/IIndexDocument.php b/lib/public/FullTextSearch/Model/IIndexDocument.php new file mode 100644 index 00000000000..d3184530a7f --- /dev/null +++ b/lib/public/FullTextSearch/Model/IIndexDocument.php @@ -0,0 +1,636 @@ +<?php +declare(strict_types=1); + + +/** + * 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 OCP\FullTextSearch\Model; + + +/** + * Class IIndexDocument + * + * This is one of the main class of the FullTextSearch, used as a data transfer + * object. An IIndexDocument is created to manage documents around FullTextSearch, + * during an index and during a search. + * The uniqueness of an IIndexDocument is made by the Id of the Content Provider + * and the Id of the original document within the Content Provider. + * + * We will call original document the source from which the IIndexDocument is + * generated. As an example, an original document can be a file, a mail, ... + * + * @since 15.0.0 + * + * @package OC\FullTextSearch\Model + */ +interface IIndexDocument { + + + const NOT_ENCODED = 0; + const ENCODED_BASE64 = 1; + + + + /** + * Returns the Id of the original document. + * + * @since 15.0.0 + * + * @return string + */ + public function getId(): string; + + + /** + * Returns the Id of the provider. + * + * @since 15.0.0 + * + * @return string + */ + public function getProviderId(): string; + + + /** + * Set the Index related to the IIndexDocument. + * + * @see IIndex + * + * @since 15.0.0 + * + * @param IIndex $index + * + * @return IIndexDocument + */ + public function setIndex(IIndex $index): IIndexDocument; + + /** + * Get the Index. + * + * @since 15.0.0 + * + * @return IIndex + */ + public function getIndex(): IIndex; + + /** + * return if Index is defined. + * + * @since 16.0.0 + * + * @return bool + */ + public function hasIndex(): bool; + + + /** + * Set the modified time of the original document. + * + * @since 15.0.0 + * + * @param int $modifiedTime + * + * @return IIndexDocument + */ + public function setModifiedTime(int $modifiedTime): IIndexDocument; + + /** + * Get the modified time of the original document. + * + * @since 15.0.0 + * + * @return int + */ + public function getModifiedTime(): int; + + /** + * Check if the original document of the IIndexDocument is older than $time. + * + * @since 15.0.0 + * + * @param int $time + * + * @return bool + */ + public function isOlderThan(int $time): bool; + + + /** + * Set the read rights of the original document using a IDocumentAccess. + * + * @see IDocumentAccess + * + * @since 15.0.0 + * + * @param IDocumentAccess $access + * + * @return $this + */ + public function setAccess(IDocumentAccess $access): IIndexDocument; + + /** + * Get the IDocumentAccess related to the original document. + * + * @since 15.0.0 + * + * @return IDocumentAccess + */ + public function getAccess(): IDocumentAccess; + + + /** + * Add a tag to the list. + * + * @since 15.0.0 + * + * @param string $tag + * + * @return IIndexDocument + */ + public function addTag(string $tag): IIndexDocument; + + /** + * Set the list of tags assigned to the original document. + * + * @since 15.0.0 + * + * @param array $tags + * + * @return IIndexDocument + */ + public function setTags(array $tags): IIndexDocument; + + /** + * Get the list of tags assigned to the original document. + * + * @since 15.0.0 + * + * @return array + */ + public function getTags(): array; + + + /** + * Add a meta tag to the list. + * + * @since 15.0.0 + * + * @param string $tag + * + * @return IIndexDocument + */ + public function addMetaTag(string $tag): IIndexDocument; + + /** + * Set the list of meta tags assigned to the original document. + * + * @since 15.0.0 + * + * @param array $tags + * + * @return IIndexDocument + */ + public function setMetaTags(array $tags): IIndexDocument; + + /** + * Get the list of meta tags assigned to the original document. + * + * @since 15.0.0 + * + * @return array + */ + public function getMetaTags(): array; + + + /** + * Add a sub tag to the list. + * + * @since 15.0.0 + * + * @param string $sub + * @param string $tag + * + * @return IIndexDocument + */ + public function addSubTag(string $sub, string $tag): IIndexDocument; + + /** + * Set the list of sub tags assigned to the original document. + * + * @since 15.0.0 + * + * @param array $tags + * + * @return IIndexDocument + */ + public function setSubTags(array $tags): IIndexDocument; + + /** + * Get the list of sub tags assigned to the original document. + * If $formatted is true, the result will be formatted in a one + * dimensional array. + * + * @since 15.0.0 + * + * @param bool $formatted + * + * @return array + */ + public function getSubTags(bool $formatted = false): array; + + + /** + * Set the source of the original document. + * + * @since 15.0.0 + * + * @param string $source + * + * @return IIndexDocument + */ + public function setSource(string $source): IIndexDocument; + + /** + * Get the source of the original document. + * + * @since 15.0.0 + * + * @return string + */ + public function getSource(): string; + + + /** + * Set the title of the original document. + * + * @since 15.0.0 + * + * @param string $title + * + * @return IIndexDocument + */ + public function setTitle(string $title): IIndexDocument; + + /** + * Get the title of the original document. + * + * @since 15.0.0 + * + * @return string + */ + public function getTitle(): string; + + + /** + * Set the content of the document. + * $encoded can be NOT_ENCODED or ENCODED_BASE64 if the content is raw or + * encoded in base64. + * + * @since 15.0.0 + * + * @param string $content + * @param int $encoded + * + * @return IIndexDocument + */ + public function setContent(string $content, int $encoded = 0): IIndexDocument; + + /** + * Get the content of the original document. + * + * @since 15.0.0 + * + * @return string + */ + public function getContent(): string; + + /** + * Returns the type of the encoding on the content. + * + * @since 15.0.0 + * + * @return int + */ + public function isContentEncoded(): int; + + /** + * Return the size of the content. + * + * @since 15.0.0 + * + * @return int + */ + public function getContentSize(): int; + + + /** + * Generate an hash, based on the content of the original document. + * + * @since 15.0.0 + * + * @return IIndexDocument + */ + public function initHash(): IIndexDocument; + + /** + * Set the hash of the original document. + * + * @since 15.0.0 + * + * @param string $hash + * + * @return IIndexDocument + */ + public function setHash(string $hash): IIndexDocument; + + /** + * Get the hash of the original document. + * + * @since 15.0.0 + * + * @return string + */ + public function getHash(): string; + + + /** + * Add a part, identified by a string, and its content. + * + * It is strongly advised to use alphanumerical chars with no space in the + * $part string. + * + * @since 15.0.0 + * + * @param string $part + * @param string $content + * + * @return IIndexDocument + */ + public function addPart(string $part, string $content): IIndexDocument; + + /** + * Set all parts and their content. + * + * @since 15.0.0 + * + * @param array $parts + * + * @return IIndexDocument + */ + public function setParts(array $parts): IIndexDocument; + + /** + * Get all parts of the IIndexDocument. + * + * @since 15.0.0 + * + * @return array + */ + public function getParts(): array; + + + /** + * Add a link, usable by the frontend. + * + * @since 15.0.0 + * + * @param string $link + * + * @return IIndexDocument + */ + public function setLink(string $link): IIndexDocument; + + /** + * Get the link. + * + * @since 15.0.0 + * + * @return string + */ + public function getLink(): string; + + + /** + * Set more information that couldn't be set using other method. + * + * @since 15.0.0 + * + * @param array $more + * + * @return IIndexDocument + */ + public function setMore(array $more): IIndexDocument; + + /** + * Get more information. + * + * @since 15.0.0 + * + * @return array + */ + public function getMore(): array; + + + /** + * Add some excerpt of the content of the original document, usually based + * on the search request. + * + * @since 16.0.0 + * + * @param string $source + * @param string $excerpt + * + * @return IIndexDocument + */ + public function addExcerpt(string $source, string $excerpt): IIndexDocument; + + /** + * Set all excerpts of the content of the original document. + * + * @since 16.0.0 + * + * @param array $excerpts + * + * @return IIndexDocument + */ + public function setExcerpts(array $excerpts): IIndexDocument; + + /** + * Get all excerpts of the content of the original document. + * + * @since 15.0.0 + * + * @return array + */ + public function getExcerpts(): array; + + + /** + * Set the score to the result assigned to this document during a search + * request. + * + * @since 15.0.0 + * + * @param string $score + * + * @return IIndexDocument + */ + public function setScore(string $score): IIndexDocument; + + /** + * Get the score. + * + * @since 15.0.0 + * + * @return string + */ + public function getScore(): string; + + + /** + * Set some information about the original document that will be available + * to the front-end when displaying search result. (as string) + * Because this information will not be indexed, this method can also be + * used to manage some data while filling the IIndexDocument before its + * indexing. + * + * @since 15.0.0 + * + * @param string $info + * @param string $value + * + * @return IIndexDocument + */ + public function setInfo(string $info, string $value): IIndexDocument; + + /** + * Get an information about a document. (string) + * + * @since 15.0.0 + * + * @param string $info + * @param string $default + * + * @return string + */ + public function getInfo(string $info, string $default = ''): string; + + /** + * Set some information about the original document that will be available + * to the front-end when displaying search result. (as array) + * Because this information will not be indexed, this method can also be + * used to manage some data while filling the IIndexDocument before its + * indexing. + * + * @since 15.0.0 + * + * @param string $info + * @param array $value + * + * @return IIndexDocument + */ + public function setInfoArray(string $info, array $value): IIndexDocument; + + /** + * Get an information about a document. (array) + * + * @since 15.0.0 + * + * @param string $info + * @param array $default + * + * @return array + */ + public function getInfoArray(string $info, array $default = []): array; + + /** + * Set some information about the original document that will be available + * to the front-end when displaying search result. (as int) + * Because this information will not be indexed, this method can also be + * used to manage some data while filling the IIndexDocument before its + * indexing. + * + * @since 15.0.0 + * + * @param string $info + * @param int $value + * + * @return IIndexDocument + */ + public function setInfoInt(string $info, int $value): IIndexDocument; + + /** + * Get an information about a document. (int) + * + * @since 15.0.0 + * + * @param string $info + * @param int $default + * + * @return int + */ + public function getInfoInt(string $info, int $default = 0): int; + + /** + * Set some information about the original document that will be available + * to the front-end when displaying search result. (as bool) + * Because this information will not be indexed, this method can also be + * used to manage some data while filling the IIndexDocument before its + * indexing. + * + * @since 15.0.0 + * + * @param string $info + * @param bool $value + * + * @return IIndexDocument + */ + public function setInfoBool(string $info, bool $value): IIndexDocument; + + /** + * Get an information about a document. (bool) + * + * @since 15.0.0 + * + * @param string $info + * @param bool $default + * + * @return bool + */ + public function getInfoBool(string $info, bool $default = false): bool; + + /** + * Get all info. + * + * @since 15.0.0 + * + * @return array + */ + public function getInfoAll(): array; + +} + diff --git a/lib/public/FullTextSearch/Model/ISearchOption.php b/lib/public/FullTextSearch/Model/ISearchOption.php new file mode 100644 index 00000000000..33802028547 --- /dev/null +++ b/lib/public/FullTextSearch/Model/ISearchOption.php @@ -0,0 +1,161 @@ +<?php +declare(strict_types=1); + + +/** + * 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 OCP\FullTextSearch\Model; + + +/** + * @since 15.0.0 + * + * Interface ISearchOption + * + * @package OCP\FullTextSearch\Model + */ +interface ISearchOption { + + + const CHECKBOX = 'checkbox'; + const INPUT = 'input'; + + const INPUT_SMALL = 'small'; + + + /** + * 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 + * + * @see ISearchRequest::getOption + * + * @since 15.0.0 + * + * @param string $name + * + * @return ISearchOption + */ + public function setName(string $name): ISearchOption; + + /** + * Get the name/key of the option. + * + * @since 15.0.0 + * + * @return string + */ + public function getName(): string; + + + /** + * Set the title/display name of the option. + * + * @since 15.0.0 + * + * @param string $title + * + * @return ISearchOption + */ + public function setTitle(string $title): ISearchOption; + + /** + * Get the title of the option. + * + * @since 15.0.0 + * + * @return string + */ + public function getTitle(): string; + + + /** + * Set the type of the option. + * $type can be ISearchOption::CHECKBOX or ISearchOption::INPUT + * + * @since 15.0.0 + * + * @param string $type + * + * @return ISearchOption + */ + public function setType(string $type): ISearchOption; + + /** + * Get the type of the option. + * + * @since 15.0.0 + * + * @return string + */ + public function getType(): string; + + + /** + * In case of Type is INPUT, set the size of the input field. + * Value can be ISearchOption::INPUT_SMALL or not defined. + * + * @since 15.0.0 + * + * @param string $size + * + * @return ISearchOption + */ + public function setSize(string $size): ISearchOption; + + /** + * Get the size of the INPUT. + * + * @since 15.0.0 + * + * @return string + */ + public function getSize(): string; + + + /** + * 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; + + /** + * Get the placeholder. + * + * @since 15.0.0 + * + * @return string + */ + public function getPlaceholder(): string; + +} diff --git a/lib/public/FullTextSearch/Model/ISearchResult.php b/lib/public/FullTextSearch/Model/ISearchResult.php index 453ec61e7de..2ca61c2f37b 100644 --- a/lib/public/FullTextSearch/Model/ISearchResult.php +++ b/lib/public/FullTextSearch/Model/ISearchResult.php @@ -78,31 +78,31 @@ interface ISearchResult { /** - * Add an IndexDocument as one of the result of the search request. + * Add an IIndexDocument as one of the result of the search request. * * @since 15.0.0 * - * @param IndexDocument $document + * @param IIndexDocument $document * * @return ISearchResult */ - public function addDocument(IndexDocument $document): ISearchResult; + public function addDocument(IIndexDocument $document): ISearchResult; /** - * Returns all result of the search request, in an array of IndexDocument. + * Returns all result of the search request, in an array of IIndexDocument. * * @since 15.0.0 * - * @return IndexDocument[] + * @return IIndexDocument[] */ public function getDocuments(): array; /** - * Set an array of IndexDocument as the result of the search request. + * Set an array of IIndexDocument as the result of the search request. * * @since 15.0.0 * - * @param IndexDocument[] $documents + * @param IIndexDocument[] $documents * * @return ISearchResult */ diff --git a/lib/public/FullTextSearch/Model/SearchTemplate.php b/lib/public/FullTextSearch/Model/ISearchTemplate.php index 7d9159190ea..e0140b23252 100644 --- a/lib/public/FullTextSearch/Model/SearchTemplate.php +++ b/lib/public/FullTextSearch/Model/ISearchTemplate.php @@ -31,12 +31,11 @@ declare(strict_types=1); namespace OCP\FullTextSearch\Model; -use JsonSerializable; use OCP\FullTextSearch\IFullTextSearchProvider; /** - * Class SearchTemplate + * Class ISearchTemplate * * This is a data transfer object that should be created by Content Provider * when the getSearchTemplate() method is called. @@ -60,40 +59,7 @@ use OCP\FullTextSearch\IFullTextSearchProvider; * * @package OCP\FullTextSearch\Model */ -final class SearchTemplate implements JsonSerializable { - - - /** @var string */ - private $icon = ''; - - /** @var string */ - private $css = ''; - - /** @var string */ - private $template = ''; - - /** @var SearchOption[] */ - private $panelOptions = []; - - /** @var SearchOption[] */ - private $navigationOptions = []; - - - /** - * SearchTemplate constructor. - * - * the class of the icon and the css file to be loaded can be set during the - * 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; - } +interface ISearchTemplate { /** @@ -104,13 +70,9 @@ final class SearchTemplate implements JsonSerializable { * * @param string $class * - * @return SearchTemplate + * @return ISearchTemplate */ - public function setIcon(string $class): SearchTemplate { - $this->icon = $class; - - return $this; - } + public function setIcon(string $class): ISearchTemplate; /** * Get the class of the icon. @@ -119,9 +81,7 @@ final class SearchTemplate implements JsonSerializable { * * @return string */ - public function getIcon(): string { - return $this->icon; - } + public function getIcon(): string; /** @@ -131,13 +91,9 @@ final class SearchTemplate implements JsonSerializable { * * @param string $css * - * @return SearchTemplate + * @return ISearchTemplate */ - public function setCss(string $css): SearchTemplate { - $this->css = $css; - - return $this; - } + public function setCss(string $css): ISearchTemplate; /** * Get the path of the CSS file. @@ -146,9 +102,7 @@ final class SearchTemplate implements JsonSerializable { * * @return string */ - public function getCss(): string { - return $this->css; - } + public function getCss(): string; /** @@ -161,13 +115,9 @@ final class SearchTemplate implements JsonSerializable { * * @param string $template * - * @return SearchTemplate + * @return ISearchTemplate */ - public function setTemplate(string $template): SearchTemplate { - $this->template = $template; - - return $this; - } + public function setTemplate(string $template): ISearchTemplate; /** * Get the path of the template file. @@ -176,57 +126,45 @@ final class SearchTemplate implements JsonSerializable { * * @return string */ - public function getTemplate(): string { - return $this->template; - } + public function getTemplate(): string; /** * Add an option in the Panel that is displayed when the user start a search * within the app that generate the content. * - * @see SearchOption + * @see ISearchOption * * @since 15.0.0 * - * @param SearchOption $option + * @param ISearchOption $option * - * @return SearchTemplate + * @return ISearchTemplate */ - public function addPanelOption(SearchOption $option): SearchTemplate { - $this->panelOptions[] = $option; - - return $this; - } + public function addPanelOption(ISearchOption $option): ISearchTemplate; /** * Get all options to be displayed in the Panel. * * @since 15.0.0 * - * @return SearchOption[] + * @return ISearchOption[] */ - public function getPanelOptions(): array { - return $this->panelOptions; - } + public function getPanelOptions(): array; /** * Add an option in the left panel of the FullTextSearch navigation page. * - * @see SearchOption + * @see ISearchOption * * @since 15.0.0 * - * @param SearchOption $option + * @param ISearchOption $option * - * @return SearchTemplate + * @return ISearchTemplate */ - public function addNavigationOption(SearchOption $option): SearchTemplate { - $this->navigationOptions[] = $option; - - return $this; - } + public function addNavigationOption(ISearchOption $option): ISearchTemplate; /** * Get all options to be displayed in the FullTextSearch navigation page. @@ -235,24 +173,7 @@ final class SearchTemplate implements JsonSerializable { * * @return array */ - public function getNavigationOptions(): array { - return $this->navigationOptions; - } + public function getNavigationOptions(): array; - - /** - * @since 15.0.0 - * - * @return array - */ - public function jsonSerialize(): array { - return [ - 'icon' => $this->getIcon(), - 'css' => $this->getCss(), - 'template' => $this->getTemplate(), - 'panel' => $this->getPanelOptions(), - 'navigation' => $this->getNavigationOptions() - ]; - } } diff --git a/lib/public/FullTextSearch/Model/SearchOption.php b/lib/public/FullTextSearch/Model/SearchOption.php deleted file mode 100644 index ae6ad3241b6..00000000000 --- a/lib/public/FullTextSearch/Model/SearchOption.php +++ /dev/null @@ -1,296 +0,0 @@ -<?php -declare(strict_types=1); - - -/** - * 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 OCP\FullTextSearch\Model; - - -use JsonSerializable; - - -/** - * @since 15.0.0 - * - * Class SearchOption - * - * @package OCP\FullTextSearch\Model - */ -final class SearchOption implements JsonSerializable { - - - const CHECKBOX = 'checkbox'; - const INPUT = 'input'; - - const INPUT_SMALL = 'small'; - - - /** @var string */ - private $name = ''; - - /** @var string */ - private $title = ''; - - /** @var string */ - private $type = ''; - - /** @var string */ - private $size = ''; - - /** @var string */ - private $placeholder = ''; - - - /** - * * - * - * The array can be empty in case no search options are available. - * The format of the array must be like this: - * - * [ - * 'panel' => [ - * 'options' => [ - * OPTION1, - * OPTION2, - * OPTION3 - * ] - * ], - * 'navigation' => [ - * 'icon' => 'css-class-of-the-icon', - * 'options' => [ - * OPTION1, - * OPTION2, - * OPTION3 - * ] - * ] - * ] - * - * - PANEL contains entries that will be displayed in the app itself, when - * a search is initiated. - * - NAVIGATION contains entries that will be available when using the - * FullTextSearch navigation page - * - OPTION is an element that define each option available to the user. - * - * The format for the options must be like this: - * - * [ - * 'name' => 'name_of_the_option', - * 'title' => 'Name displayed in the panel', - * 'type' => '', - * 'size' => '' (optional), - * 'placeholder' => '' (optional) - * ] - * - * - NAME is the variable name that is sent to the IFullTextSearchProvider - * when a ISearchRequest is requested. (keys in the array returned by the - * ISearchRequest->getOptions()) - * - TYPE can be 'input' or 'checkbox' - * - SIZE is only used in case TYPE='input', default is 'large' but can be - * 'small' - * - PLACEHOLDER is only used in case TYPE='input', default is empty. - */ - - /** - * SearchOption constructor. - * - * Some value can be setduring 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; - } - - - /** - * 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 - * - * @see ISearchRequest::getOption - * - * @since 15.0.0 - * - * @param string $name - * - * @return SearchOption - */ - public function setName(string $name): SearchOption { - $this->name = $name; - - return $this; - } - - /** - * Get the name/key of the option. - * - * @since 15.0.0 - * - * @return string - */ - public function getName(): string { - return $this->name; - } - - - /** - * Set the title/display name of the option. - * - * @since 15.0.0 - * - * @param string $title - * - * @return SearchOption - */ - public function setTitle(string $title): SearchOption { - $this->title = $title; - - return $this; - } - - /** - * Get the title of the option. - * - * @since 15.0.0 - * - * @return string - */ - public function getTitle(): string { - return $this->title; - } - - - /** - * Set the type of the option. - * $type can be SearchOption::CHECKBOX or SearchOption::INPUT - * - * @since 15.0.0 - * - * @param string $type - * - * @return SearchOption - */ - public function setType(string $type): SearchOption { - $this->type = $type; - - return $this; - } - - /** - * Get the type of the option. - * - * @since 15.0.0 - * - * @return string - */ - public function getType(): string { - return $this->type; - } - - - /** - * In case of Type is INPUT, set the size of the input field. - * Value can be SearchOption::INPUT_SMALL or not defined. - * - * @since 15.0.0 - * - * @param string $size - * - * @return SearchOption - */ - public function setSize(string $size): SearchOption { - $this->size = $size; - - return $this; - } - - /** - * 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 SearchOption - */ - public function setPlaceholder(string $placeholder): SearchOption { - $this->placeholder = $placeholder; - - return $this; - } - - /** - * 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 [ - 'name' => $this->getName(), - 'title' => $this->getTitle(), - 'type' => $this->getType(), - 'size' => $this->getSize(), - 'placeholder' => $this->getPlaceholder() - ]; - } -} |