migrate therinaldos.com data
Build & Deploy to DigitalOcean Space / build (push) Failing after 2m38s

This commit is contained in:
2024-05-05 15:50:45 -04:00
commit ef1ff240d4
23182 changed files with 3801898 additions and 0 deletions
@@ -0,0 +1,355 @@
<?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/>.
*
*/
namespace OC\FullTextSearch\Model;
use JsonSerializable;
use OCP\FullTextSearch\Model\IDocumentAccess;
/**
* Class IDocumentAccess
*
* This object is used as a data transfer object when
*
* - indexing a document,
* - generating a search request.
*
* During the index, it is used to define which users, groups, circles, ...
* have access to the IndexDocument
*
* During the search, it is internally use to define to which group, circles, ...
* a user that perform the search belongs to.
*
* @see IIndexDocument::setAccess
*
* @since 16.0.0
*
* @package OC\FullTextSearch\Model
*/
final class DocumentAccess implements IDocumentAccess, 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 = [];
/**
* Owner of the document can be set at the init of the object.
*
* @since 16.0.0
*
* IDocumentAccess constructor.
*
* @param string $ownerId
*/
public function __construct(string $ownerId = '') {
$this->setOwnerId($ownerId);
}
/**
* Set the Owner of the document.
*
* @since 16.0.0
*
* @param string $ownerId
*
* @return IDocumentAccess
*/
public function setOwnerId(string $ownerId): IDocumentAccess {
$this->ownerId = $ownerId;
return $this;
}
/**
* Get the Owner of the document.
*
* @since 16.0.0
*
* @return string
*/
public function getOwnerId(): string {
return $this->ownerId;
}
/**
* Set the viewer of the document.
*
* @since 16.0.0
*
* @param string $viewerId
*
* @return IDocumentAccess
*/
public function setViewerId(string $viewerId): IDocumentAccess {
$this->viewerId = $viewerId;
return $this;
}
/**
* Get the viewer of the document.
*
* @since 16.0.0
*
* @return string
*/
public function getViewerId(): string {
return $this->viewerId;
}
/**
* 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;
return $this;
}
/**
* 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;
return $this;
}
/**
* Add multiple entries to the list of users that have read access to the
* document.
*
* @since 16.0.0
*
* @param array $users
*
* @return IDocumentAccess
*/
public function addUsers($users): IDocumentAccess {
$this->users = array_merge($this->users, $users);
return $this;
}
/**
* 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;
}
/**
* 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;
return $this;
}
/**
* 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;
return $this;
}
/**
* Add multiple entries to the list of groups that have read access to the
* document.
*
* @since 16.0.0
*
* @param array $groups
*
* @return IDocumentAccess
*/
public function addGroups(array $groups) {
$this->groups = array_merge($this->groups, $groups);
return $this;
}
/**
* 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;
}
/**
* 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;
return $this;
}
/**
* 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;
return $this;
}
/**
* Add multiple entries to the list of groups that have read access to the
* document.
*
* @since 16.0.0
*
* @param array $circles
*
* @return IDocumentAccess
*/
public function addCircles(array $circles): IDocumentAccess {
$this->circles = array_merge($this->circles, $circles);
return $this;
}
/**
* 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;
}
/**
* 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;
return $this;
}
/**
* 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;
}
/**
* @since 16.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()
];
}
}
@@ -0,0 +1,986 @@
<?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/>.
*
*/
namespace OC\FullTextSearch\Model;
use JsonSerializable;
use OCP\FullTextSearch\Model\IDocumentAccess;
use OCP\FullTextSearch\Model\IIndex;
use OCP\FullTextSearch\Model\IIndexDocument;
/**
* Class IndexDocument
*
* This is one of the main class of the FullTextSearch, used as a data transfer
* object. An IndexDocument is created to manage documents around FullTextSearch,
* during an index and during a search.
* The uniqueness of an IndexDocument 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
* generated. As an example, an original document can be a file, a mail, ...
*
* @since 15.0.0
*
* @package OC\FullTextSearch\Model
*/
class IndexDocument implements IIndexDocument, JsonSerializable {
/** @var string */
protected $id = '';
/** @var string */
protected $providerId = '';
/** @var DocumentAccess */
protected $access;
/** @var IIndex */
protected $index;
/** @var int */
protected $modifiedTime = 0;
/** @var string */
protected $source = '';
/** @var array */
protected $tags = [];
/** @var array */
protected $metaTags = [];
/** @var array */
protected $subTags = [];
/** @var string */
protected $title = '';
/** @var string */
protected $content = '';
/** @var string */
protected $hash = '';
/** @var array */
protected $parts = [];
/** @var string */
protected $link = '';
/** @var array */
protected $more = [];
/** @var array */
protected $excerpts = [];
/** @var string */
protected $score = '';
/** @var array */
protected $info = [];
/** @var int */
protected $contentEncoded = 0;
/**
* IIndexDocument constructor.
*
* On creation, we assure the uniqueness of the object using the providerId
* 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;
$this->id = $documentId;
}
/**
* Returns the Id of the original document.
*
* @since 15.0.0
*
* @return string
*/
final public function getId(): string {
return $this->id;
}
/**
* Returns the Id of the provider.
*
* @since 15.0.0
*
* @return string
*/
final public function getProviderId(): string {
return $this->providerId;
}
/**
* Set the Index related to the IIndexDocument.
*
* @see IIndex
*
* @since 15.0.0
*
* @param IIndex $index
*
* @return IIndexDocument
*/
final public function setIndex(IIndex $index): IIndexDocument {
$this->index = $index;
return $this;
}
/**
* Get the Index.
*
* @since 15.0.0
*
* @return IIndex
*/
final public function getIndex(): IIndex {
return $this->index;
}
/**
* return if Index is defined.
*
* @since 16.0.0
*
* @return bool
*/
final public function hasIndex(): bool {
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;
return $this;
}
/**
* Get the modified time of the original document.
*
* @since 15.0.0
*
* @return int
*/
final public function getModifiedTime(): int {
return $this->modifiedTime;
}
/**
* 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);
}
/**
* Set the read rights of the original document using a IDocumentAccess.
*
* @see IDocumentAccess
*
* @since 15.0.0
*
* @param IDocumentAccess $access
*
* @return $this
*/
final public function setAccess(IDocumentAccess $access): IIndexDocument {
$this->access = $access;
return $this;
}
/**
* Get the IDocumentAccess related to the original document.
*
* @since 15.0.0
*
* @return IDocumentAccess
*/
final public function getAccess(): IDocumentAccess {
return $this->access;
}
/**
* 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;
return $this;
}
/**
* 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;
return $this;
}
/**
* Get the list of tags assigned to the original document.
*
* @since 15.0.0
*
* @return array
*/
final public function getTags(): array {
return $this->tags;
}
/**
* 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;
return $this;
}
/**
* 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;
return $this;
}
/**
* 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;
}
/**
* 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)) {
$this->subTags[$sub] = [];
}
$this->subTags[$sub][] = $tag;
return $this;
}
/**
* 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;
return $this;
}
/**
* 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
*/
final public function getSubTags(bool $formatted = false): array {
if ($formatted === false) {
return $this->subTags;
}
$subTags = [];
$ak = array_keys($this->subTags);
foreach ($ak as $source) {
$tags = $this->subTags[$source];
foreach ($tags as $tag) {
$subTags[] = $source . '_' . $tag;
}
}
return $subTags;
}
/**
* 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;
return $this;
}
/**
* Get the source of the original document.
*
* @since 15.0.0
*
* @return string
*/
final public function getSource(): string {
return $this->source;
}
/**
* 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;
return $this;
}
/**
* Get the title of the original document.
*
* @since 15.0.0
*
* @return string
*/
final public function getTitle(): string {
return $this->title;
}
/**
* 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
*/
final public function setContent(string $content, int $encoded = 0): IIndexDocument {
$this->content = $content;
$this->contentEncoded = $encoded;
return $this;
}
/**
* Get the content of the original document.
*
* @since 15.0.0
*
* @return string
*/
final public function getContent(): string {
return $this->content;
}
/**
* Returns the type of the encoding on the content.
*
* @since 15.0.0
*
* @return int
*/
final public function isContentEncoded(): int {
return $this->contentEncoded;
}
/**
* Return the size of the content.
*
* @since 15.0.0
*
* @return int
*/
final public function getContentSize(): int {
return strlen($this->getContent());
}
/**
* Generate an 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());
return $this;
}
/**
* 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;
return $this;
}
/**
* Get the hash of the original document.
*
* @since 15.0.0
*
* @return string
*/
final public function getHash(): string {
return $this->hash;
}
/**
* 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
*/
final public function addPart(string $part, string $content): IIndexDocument {
$this->parts[$part] = $content;
return $this;
}
/**
* 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;
return $this;
}
/**
* Get all parts of the IIndexDocument.
*
* @since 15.0.0
*
* @return array
*/
final public function getParts(): array {
return $this->parts;
}
/**
* 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;
return $this;
}
/**
* Get the link.
*
* @since 15.0.0
*
* @return string
*/
final public function getLink(): string {
return $this->link;
}
/**
* 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;
return $this;
}
/**
* Get more information.
*
* @since 15.0.0
*
* @return array
*/
final public function getMore(): array {
return $this->more;
}
/**
* 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
*/
final public function addExcerpt(string $source, string $excerpt): IIndexDocument {
$this->excerpts[] =
[
'source' => $source,
'excerpt' => $this->cleanExcerpt($excerpt)
];
return $this;
}
/**
* 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 = [];
foreach ($excerpts as $entry) {
$new[] = [
'source' => $entry['source'],
'excerpt' => $this->cleanExcerpt($entry['excerpt'])
];
}
$this->excerpts = $new;
return $this;
}
/**
* Get all excerpts of the content of the original document.
*
* @since 15.0.0
*
* @return array
*/
final public function getExcerpts(): array {
return $this->excerpts;
}
/**
* 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);
return $excerpt;
}
/**
* Set the score to the result assigned to this document during a search
* request.
*
* @since 15.0.0
*
* @param string $score
*
* @return IIndexDocument
*/
final public function setScore(string $score): IIndexDocument {
$this->score = $score;
return $this;
}
/**
* Get the score.
*
* @since 15.0.0
*
* @return string
*/
final public function getScore(): string {
return $this->score;
}
/**
* 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
*/
final public function setInfo(string $info, string $value): IIndexDocument {
$this->info[$info] = $value;
return $this;
}
/**
* 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)) {
return $default;
}
return $this->info[$info];
}
/**
* 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
*/
final public function setInfoArray(string $info, array $value): IIndexDocument {
$this->info[$info] = $value;
return $this;
}
/**
* 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)) {
return $default;
}
return $this->info[$info];
}
/**
* 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
*/
final public function setInfoInt(string $info, int $value): IIndexDocument {
$this->info[$info] = $value;
return $this;
}
/**
* 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)) {
return $default;
}
return $this->info[$info];
}
/**
* 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
*/
final public function setInfoBool(string $info, bool $value): IIndexDocument {
$this->info[$info] = $value;
return $this;
}
/**
* 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)) {
return $default;
}
return $this->info[$info];
}
/**
* 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) === '_') {
continue;
}
$info[$k] = $v;
}
return $info;
}
/**
* @since 15.0.0
*
* On some version of PHP, it is better to force destruct the object.
* And during the index, the number of generated IIndexDocument can be
* _huge_.
*/
public function __destruct() {
unset($this->id);
unset($this->providerId);
unset($this->access);
unset($this->modifiedTime);
unset($this->title);
unset($this->content);
unset($this->hash);
unset($this->link);
unset($this->source);
unset($this->tags);
unset($this->metaTags);
unset($this->subTags);
unset($this->more);
unset($this->excerpts);
unset($this->score);
unset($this->info);
unset($this->contentEncoded);
}
/**
* @since 15.0.0
*/
public function jsonSerialize(): array {
return [
'id' => $this->getId(),
'providerId' => $this->getProviderId(),
'access' => $this->access,
'modifiedTime' => $this->getModifiedTime(),
'title' => $this->getTitle(),
'link' => $this->getLink(),
'index' => $this->index,
'source' => $this->getSource(),
'info' => $this->getInfoAll(),
'hash' => $this->getHash(),
'contentSize' => $this->getContentSize(),
'tags' => $this->getTags(),
'metatags' => $this->getMetaTags(),
'subtags' => $this->getSubTags(),
'more' => $this->getMore(),
'excerpts' => $this->getExcerpts(),
'score' => $this->getScore()
];
}
}
@@ -0,0 +1,282 @@
<?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/>.
*
*/
namespace OC\FullTextSearch\Model;
use JsonSerializable;
use OCP\FullTextSearch\Model\ISearchOption;
/**
* @since 15.0.0
*
* Class 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 = '';
/**
* *
*
* 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.
*/
/**
* ISearchOption 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 ISearchOption
*/
public function setName(string $name): ISearchOption {
$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 ISearchOption
*/
public function setTitle(string $title): ISearchOption {
$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 ISearchOption::CHECKBOX or ISearchOption::INPUT
*
* @since 15.0.0
*
* @param string $type
*
* @return ISearchOption
*/
public function setType(string $type): ISearchOption {
$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 ISearchOption::INPUT_SMALL or not defined.
*
* @since 15.0.0
*
* @param string $size
*
* @return ISearchOption
*/
public function setSize(string $size): ISearchOption {
$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 ISearchOption
*/
public function setPlaceholder(string $placeholder): ISearchOption {
$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()
];
}
}
@@ -0,0 +1,178 @@
<?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/>.
*
*/
namespace OC\FullTextSearch\Model;
use JsonSerializable;
use OCP\FullTextSearch\Model\ISearchRequestSimpleQuery;
/**
* @since 17.0.0
*
* Class SearchRequestSimpleQuery
*
* @package OC\FullTextSearch\Model
*/
final class SearchRequestSimpleQuery implements ISearchRequestSimpleQuery, JsonSerializable {
/** @var int */
private $type = 0;
/** @var string */
private $field = '';
/** @var array */
private $values = [];
/**
* SearchRequestQuery constructor.
*
* @param $type
* @param $field
*
* @since 17.0.0
*/
public function __construct(string $field, int $type) {
$this->field = $field;
$this->type = $type;
}
/**
* Get the compare type of the query
*
* @return int
* @since 17.0.0
*/
public function getType(): int {
return $this->type;
}
/**
* Get the field to apply query
*
* @return string
* @since 17.0.0
*/
public function getField(): string {
return $this->field;
}
/**
* Set the field to apply query
*
* @param string $field
*
* @return ISearchRequestSimpleQuery
* @since 17.0.0
*/
public function setField(string $field): ISearchRequestSimpleQuery {
$this->field = $field;
return $this;
}
/**
* Get the value to compare (string)
*
* @return array
* @since 17.0.0
*/
public function getValues(): array {
return $this->values;
}
/**
* Add value to compare (string)
*
* @param string $value
*
* @return ISearchRequestSimpleQuery
* @since 17.0.0
*/
public function addValue(string $value): ISearchRequestSimpleQuery {
$this->values[] = $value;
return $this;
}
/**
* Add value to compare (int)
*
* @param int $value
*
* @return ISearchRequestSimpleQuery
* @since 17.0.0
*/
public function addValueInt(int $value): ISearchRequestSimpleQuery {
$this->values[] = $value;
return $this;
}
/**
* Add value to compare (array)
*
* @param array $value
*
* @return ISearchRequestSimpleQuery
* @since 17.0.0
*/
public function addValueArray(array $value): ISearchRequestSimpleQuery {
$this->values[] = $value;
return $this;
}
/**
* Add value to compare (bool)
*
* @param bool $value
*
* @return ISearchRequestSimpleQuery
* @since 17.0.0
*/
public function addValueBool(bool $value): ISearchRequestSimpleQuery {
$this->values[] = $value;
return $this;
}
/**
* @since 17.0.0
*/
public function jsonSerialize(): array {
return [
'type' => $this->getType(),
'field' => $this->getField(),
'values' => $this->getValues()
];
}
}
@@ -0,0 +1,250 @@
<?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/>.
*
*/
namespace OC\FullTextSearch\Model;
use JsonSerializable;
use OCP\FullTextSearch\IFullTextSearchProvider;
use OCP\FullTextSearch\Model\ISearchOption;
use OCP\FullTextSearch\Model\ISearchTemplate;
/**
* Class ISearchTemplate
*
* This is a data transfer object that should be created by Content Provider
* 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.
*
* The display of the Options is generated by the FullTextSearch app and Options
* can be displayed in 2 places:
*
* - the navigation page of the app that generate the indexed content.
* (files, bookmarks, deck, mails, ...)
* - the navigation page of the FullTextSearch app.
*
* Both pages will have different Options, and only the first one can integrate
* a specific template.
*
* @see IFullTextSearchProvider::getSearchTemplate
*
* @since 15.0.0
*
* @package OC\FullTextSearch\Model
*/
final class SearchTemplate implements ISearchTemplate, JsonSerializable {
/** @var string */
private $icon = '';
/** @var string */
private $css = '';
/** @var string */
private $template = '';
/** @var SearchOption[] */
private $panelOptions = [];
/** @var SearchOption[] */
private $navigationOptions = [];
/**
* ISearchTemplate 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;
}
/**
* Set the class of the icon to be displayed in the left panel of the
* 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;
return $this;
}
/**
* Get the class of the icon.
*
* @since 15.0.0
*
* @return string
*/
public function getIcon(): string {
return $this->icon;
}
/**
* 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;
return $this;
}
/**
* Get the path of the CSS file.
*
* @since 15.0.0
*
* @return string
*/
public function getCss(): string {
return $this->css;
}
/**
* Set the path of the file of a template that the HTML will be displayed
* below the Options.
* This should only be used if your Content Provider needs to set options in
* a way not generated by FullTextSearch
*
* @since 15.0.0
*
* @param string $template
*
* @return ISearchTemplate
*/
public function setTemplate(string $template): ISearchTemplate {
$this->template = $template;
return $this;
}
/**
* Get the path of the template file.
*
* @since 15.0.0
*
* @return string
*/
public function getTemplate(): string {
return $this->template;
}
/**
* Add an option in the Panel that is displayed when the user start a search
* within the app that generate the content.
*
* @see ISearchOption
*
* @since 15.0.0
*
* @param ISearchOption $option
*
* @return ISearchTemplate
*/
public function addPanelOption(ISearchOption $option): ISearchTemplate {
$this->panelOptions[] = $option;
return $this;
}
/**
* Get all options to be displayed in the Panel.
*
* @since 15.0.0
*
* @return SearchOption[]
*/
public function getPanelOptions(): array {
return $this->panelOptions;
}
/**
* Add an option in the left panel of the FullTextSearch navigation page.
*
* @see ISearchOption
*
* @since 15.0.0
*
* @param ISearchOption $option
*
* @return ISearchTemplate
*/
public function addNavigationOption(ISearchOption $option): ISearchTemplate {
$this->navigationOptions[] = $option;
return $this;
}
/**
* Get all options to be displayed in the FullTextSearch navigation page.
*
* @since 15.0.0
*
* @return array
*/
public function getNavigationOptions(): array {
return $this->navigationOptions;
}
/**
* @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()
];
}
}