diff options
Diffstat (limited to 'lib/public/Search')
-rw-r--r-- | lib/public/Search/FilterDefinition.php | 118 | ||||
-rw-r--r-- | lib/public/Search/IExternalProvider.php | 25 | ||||
-rw-r--r-- | lib/public/Search/IFilter.php | 37 | ||||
-rw-r--r-- | lib/public/Search/IFilterCollection.php | 39 | ||||
-rw-r--r-- | lib/public/Search/IFilteringProvider.php | 54 | ||||
-rw-r--r-- | lib/public/Search/IInAppSearch.php | 16 | ||||
-rw-r--r-- | lib/public/Search/IProvider.php | 31 | ||||
-rw-r--r-- | lib/public/Search/ISearchQuery.php | 38 | ||||
-rw-r--r-- | lib/public/Search/PagedProvider.php | 28 | ||||
-rw-r--r-- | lib/public/Search/Provider.php | 28 | ||||
-rw-r--r-- | lib/public/Search/Result.php | 27 | ||||
-rw-r--r-- | lib/public/Search/SearchResult.php | 36 | ||||
-rw-r--r-- | lib/public/Search/SearchResultEntry.php | 34 |
13 files changed, 338 insertions, 173 deletions
diff --git a/lib/public/Search/FilterDefinition.php b/lib/public/Search/FilterDefinition.php new file mode 100644 index 00000000000..86b2bb655ff --- /dev/null +++ b/lib/public/Search/FilterDefinition.php @@ -0,0 +1,118 @@ +<?php + +declare(strict_types=1); +/** + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +namespace OCP\Search; + +use InvalidArgumentException; + +/** + * Filter definition + * + * Describe filter attributes + * + * @since 28.0.0 + */ +class FilterDefinition { + /** + * @since 28.0.0 + */ + public const TYPE_BOOL = 'bool'; + + /** + * @since 28.0.0 + */ + public const TYPE_INT = 'int'; + + /** + * @since 28.0.0 + */ + public const TYPE_FLOAT = 'float'; + + /** + * @since 28.0.0 + */ + public const TYPE_STRING = 'string'; + + /** + * @since 28.0.0 + */ + public const TYPE_STRINGS = 'strings'; + + /** + * @since 28.0.0 + */ + public const TYPE_DATETIME = 'datetime'; + + /** + * @since 28.0.0 + */ + public const TYPE_PERSON = 'person'; + + /** + * @since 28.0.0 + */ + public const TYPE_NC_USER = 'nc-user'; + + /** + * @since 28.0.0 + */ + public const TYPE_NC_GROUP = 'nc-group'; + + /** + * Build filter definition + * + * @param self::TYPE_* $type + * @param bool $exclusive If true, all providers not supporting this filter will be ignored when this filter is provided + * @throws InvalidArgumentException in case of invalid name. Allowed characters are -, 0-9, a-z. + * @since 28.0.0 + */ + public function __construct( + private string $name, + private string $type = self::TYPE_STRING, + private bool $exclusive = true, + ) { + if (!preg_match('/[-0-9a-z]+/Au', $name)) { + throw new InvalidArgumentException('Invalid filter name. Allowed characters are [-0-9a-z]'); + } + } + + /** + * Filter name + * + * Name is used in query string and for advanced syntax `name: <value>` + * + * @since 28.0.0 + */ + public function name(): string { + return $this->name; + } + + /** + * Filter type + * + * Expected type of value for the filter + * + * @return self::TYPE_* + * @since 28.0.0 + */ + public function type(): string { + return $this->type; + } + + /** + * Is filter exclusive? + * + * If exclusive, only provider with support for this filter will receive the query. + * Example: if an exclusive filter `mimetype` is declared, a search with this term will not + * be send to providers like `settings` that doesn't support it. + * + * @since 28.0.0 + */ + public function exclusive(): bool { + return $this->exclusive; + } +} diff --git a/lib/public/Search/IExternalProvider.php b/lib/public/Search/IExternalProvider.php new file mode 100644 index 00000000000..a9a8e3ad6ba --- /dev/null +++ b/lib/public/Search/IExternalProvider.php @@ -0,0 +1,25 @@ +<?php + +declare(strict_types=1); +/** + * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +namespace OCP\Search; + +/** + * Interface for search providers that forward user queries to external services. + * + * @since 32.0.0 + */ +interface IExternalProvider extends IProvider { + /** + * Indicates whether this search provider queries external (3rd-party) resources. + * This is used by the Unified Search modal filter (toggle switch). By default, searching through external providers is disabled. + * + * @return bool default false + * + * @since 32.0.0 + */ + public function isExternalProvider(): bool; +} diff --git a/lib/public/Search/IFilter.php b/lib/public/Search/IFilter.php new file mode 100644 index 00000000000..d3617bbc843 --- /dev/null +++ b/lib/public/Search/IFilter.php @@ -0,0 +1,37 @@ +<?php + +declare(strict_types=1); +/** + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +namespace OCP\Search; + +/** + * Interface for search filters + * + * @since 28.0.0 + */ +interface IFilter { + /** @since 28.0.0 */ + public const BUILTIN_TERM = 'term'; + /** @since 28.0.0 */ + public const BUILTIN_SINCE = 'since'; + /** @since 28.0.0 */ + public const BUILTIN_UNTIL = 'until'; + /** @since 28.0.0 */ + public const BUILTIN_PERSON = 'person'; + /** @since 28.0.0 */ + public const BUILTIN_TITLE_ONLY = 'title-only'; + /** @since 28.0.0 */ + public const BUILTIN_PLACES = 'places'; + /** @since 28.0.0 */ + public const BUILTIN_PROVIDER = 'provider'; + + /** + * Get filter value + * + * @since 28.0.0 + */ + public function get(): mixed; +} diff --git a/lib/public/Search/IFilterCollection.php b/lib/public/Search/IFilterCollection.php new file mode 100644 index 00000000000..45e5e196d7f --- /dev/null +++ b/lib/public/Search/IFilterCollection.php @@ -0,0 +1,39 @@ +<?php + +declare(strict_types=1); +/** + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +namespace OCP\Search; + +use IteratorAggregate; + +/** + * Interface for search filters + * + * @since 28.0.0 + * @extends IteratorAggregate<string, \OCP\Search\IFilter> + */ +interface IFilterCollection extends IteratorAggregate { + /** + * Check if a filter exits + * + * @since 28.0.0 + */ + public function has(string $name): bool; + + /** + * Get a filter by name + * + * @since 28.0.0 + */ + public function get(string $name): ?IFilter; + + /** + * Return Iterator of filters + * + * @since 28.0.0 + */ + public function getIterator(): \Traversable; +} diff --git a/lib/public/Search/IFilteringProvider.php b/lib/public/Search/IFilteringProvider.php new file mode 100644 index 00000000000..8dee3af973d --- /dev/null +++ b/lib/public/Search/IFilteringProvider.php @@ -0,0 +1,54 @@ +<?php + +declare(strict_types=1); +/** + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +namespace OCP\Search; + +/** + * Interface for advanced search providers + * + * These providers will be implemented in apps, so they can participate in the + * global search results of Nextcloud. If an app provides more than one type of + * resource, e.g. contacts and address books in Nextcloud Contacts, it should + * register one provider per group. + * + * @since 28.0.0 + */ +interface IFilteringProvider extends IProvider { + /** + * Return the names of filters supported by the application + * + * If a filter sent by client is not in this list, + * the current provider will be ignored. + * Example: + * array('term', 'since', 'custom-filter'); + * + * @since 28.0.0 + * @return string[] Name of supported filters (default or defined by application) + */ + public function getSupportedFilters(): array; + + /** + * Get alternate IDs handled by this provider + * + * A search provider can complete results from other search providers. + * For example, files and full-text-search can search in files. + * If you use `in:files` in a search, provider files will be invoked, + * with all other providers declaring `files` in this method + * + * @since 28.0.0 + * @return string[] IDs + */ + public function getAlternateIds(): array; + + /** + * Allows application to declare custom filters + * + * @since 28.0.0 + * @return list<FilterDefinition> + */ + public function getCustomFilters(): array; +} diff --git a/lib/public/Search/IInAppSearch.php b/lib/public/Search/IInAppSearch.php new file mode 100644 index 00000000000..1baccb70d1e --- /dev/null +++ b/lib/public/Search/IInAppSearch.php @@ -0,0 +1,16 @@ +<?php + +declare(strict_types=1); +/** + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +namespace OCP\Search; + +/** + * Interface for search providers supporting in-app search + * + * @since 28.0.0 + */ +interface IInAppSearch extends IProvider { +} diff --git a/lib/public/Search/IProvider.php b/lib/public/Search/IProvider.php index c94dfe7a4e4..070e46cf798 100644 --- a/lib/public/Search/IProvider.php +++ b/lib/public/Search/IProvider.php @@ -1,29 +1,9 @@ <?php declare(strict_types=1); - /** - * @copyright 2020 Christoph Wurst <christoph@winzerhof-wurst.at> - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.com> - * @author John Molakvoæ <skjnldsv@protonmail.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: 2020 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCP\Search; @@ -40,7 +20,6 @@ use OCP\IUser; * @since 20.0.0 */ interface IProvider { - /** * Get the unique ID of this search provider * @@ -69,15 +48,17 @@ interface IProvider { /** * Get the search provider order * The lower the int, the higher it will be sorted (0 will be before 10) + * If null, the search provider will be hidden in the UI and the API not called * * @param string $route the route the user is currently at, e.g. files.view.index * @param array $routeParameters the parameters of the route the user is currently at, e.g. [fileId = 982, dir = "/"] * - * @return int + * @return int|null * * @since 20.0.0 + * @since 28.0.0 Can return null */ - public function getOrder(string $route, array $routeParameters): int; + public function getOrder(string $route, array $routeParameters): ?int; /** * Find matching search entries in an app diff --git a/lib/public/Search/ISearchQuery.php b/lib/public/Search/ISearchQuery.php index 2f4f1038fe4..80f6de914d0 100644 --- a/lib/public/Search/ISearchQuery.php +++ b/lib/public/Search/ISearchQuery.php @@ -1,28 +1,9 @@ <?php declare(strict_types=1); - /** - * @copyright 2020 Christoph Wurst <christoph@winzerhof-wurst.at> - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.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: 2020 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCP\Search; @@ -38,7 +19,6 @@ namespace OCP\Search; * @since 20.0.0 */ interface ISearchQuery { - /** * @since 20.0.0 */ @@ -53,6 +33,20 @@ interface ISearchQuery { public function getTerm(): string; /** + * Get a single request filter + * + * @since 28.0.0 + */ + public function getFilter(string $name): ?IFilter; + + /** + * Get request filters + * + * @since 28.0.0 + */ + public function getFilters(): IFilterCollection; + + /** * Get the sort order of results as defined as SORT_* constants on this interface * * @return int diff --git a/lib/public/Search/PagedProvider.php b/lib/public/Search/PagedProvider.php index 61f5dd457ee..d837633dfeb 100644 --- a/lib/public/Search/PagedProvider.php +++ b/lib/public/Search/PagedProvider.php @@ -1,28 +1,9 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.com> - * @author Jörn Friedrich Dreyer <jfd@butonic.de> - * @author Lukas Reschke <lukas@statuscode.ch> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * 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, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ namespace OCP\Search; @@ -32,7 +13,6 @@ namespace OCP\Search; * @deprecated 20.0.0 */ abstract class PagedProvider extends Provider { - /** * show all results * @since 8.0.0 diff --git a/lib/public/Search/Provider.php b/lib/public/Search/Provider.php index 2cf0c4d043b..238507098f1 100644 --- a/lib/public/Search/Provider.php +++ b/lib/public/Search/Provider.php @@ -1,28 +1,9 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Andrew Brown <andrew@casabrown.com> - * @author Bart Visscher <bartv@thisnet.nl> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Jakob Sack <mail@jakobsack.de> - * @author Jörn Friedrich Dreyer <jfd@butonic.de> - * @author Morris Jobke <hey@morrisjobke.de> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * 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, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ namespace OCP\Search; @@ -32,7 +13,6 @@ namespace OCP\Search; * @deprecated 20.0.0 */ abstract class Provider { - /** * @since 8.0.0 * @deprecated 20.0.0 diff --git a/lib/public/Search/Result.php b/lib/public/Search/Result.php index 86476ade721..169c376a215 100644 --- a/lib/public/Search/Result.php +++ b/lib/public/Search/Result.php @@ -1,27 +1,9 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Andrew Brown <andrew@casabrown.com> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Jakob Sack <mail@jakobsack.de> - * @author Jörn Friedrich Dreyer <jfd@butonic.de> - * @author Morris Jobke <hey@morrisjobke.de> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * 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, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ namespace OCP\Search; @@ -31,7 +13,6 @@ namespace OCP\Search; * @deprecated 20.0.0 */ class Result { - /** * A unique identifier for the result, usually given as the item ID in its * corresponding application. diff --git a/lib/public/Search/SearchResult.php b/lib/public/Search/SearchResult.php index 685dad0f0ca..2504ffd01e9 100644 --- a/lib/public/Search/SearchResult.php +++ b/lib/public/Search/SearchResult.php @@ -1,28 +1,9 @@ <?php declare(strict_types=1); - /** - * @copyright 2020 Christoph Wurst <christoph@winzerhof-wurst.at> - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author John Molakvoæ <skjnldsv@protonmail.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: 2020 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCP\Search; @@ -33,7 +14,6 @@ use function array_values; * @since 20.0.0 */ final class SearchResult implements JsonSerializable { - /** @var string */ private $name; @@ -50,14 +30,14 @@ final class SearchResult implements JsonSerializable { * @param string $name the translated name of the result section or group, e.g. "Mail" * @param bool $isPaginated * @param SearchResultEntry[] $entries - * @param null $cursor + * @param ?int|?string $cursor * * @since 20.0.0 */ private function __construct(string $name, - bool $isPaginated, - array $entries, - $cursor = null) { + bool $isPaginated, + array $entries, + $cursor = null) { $this->name = $name; $this->isPaginated = $isPaginated; $this->entries = $entries; @@ -88,8 +68,8 @@ final class SearchResult implements JsonSerializable { * @since 20.0.0 */ public static function paginated(string $name, - array $entries, - $cursor): self { + array $entries, + $cursor): self { return new self( $name, true, diff --git a/lib/public/Search/SearchResultEntry.php b/lib/public/Search/SearchResultEntry.php index 42c3a4cbdd7..b28cda3ea0e 100644 --- a/lib/public/Search/SearchResultEntry.php +++ b/lib/public/Search/SearchResultEntry.php @@ -1,28 +1,9 @@ <?php declare(strict_types=1); - /** - * @copyright 2020 Christoph Wurst <christoph@winzerhof-wurst.at> - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author John Molakvoæ <skjnldsv@protonmail.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: 2020 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCP\Search; @@ -44,7 +25,6 @@ use JsonSerializable; * @since 20.0.0 */ class SearchResultEntry implements JsonSerializable { - /** * @var string * @since 20.0.0 @@ -99,11 +79,11 @@ class SearchResultEntry implements JsonSerializable { * @since 20.0.0 */ public function __construct(string $thumbnailUrl, - string $title, - string $subline, - string $resourceUrl, - string $icon = '', - bool $rounded = false) { + string $title, + string $subline, + string $resourceUrl, + string $icon = '', + bool $rounded = false) { $this->thumbnailUrl = $thumbnailUrl; $this->title = $title; $this->subline = $subline; |