mirror of https://github.com/nextcloud/server.git
feat(search): Allow multiple search terms in UnifiedController
Signed-off-by: Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>pull/40618/head
parent
9de8e8e224
commit
c753eefb21
@ -1,5 +1,68 @@
|
||||
{
|
||||
"packages": [],
|
||||
"dev": false,
|
||||
"dev-package-names": []
|
||||
"packages": [
|
||||
{
|
||||
"name": "bamarni/composer-bin-plugin",
|
||||
"version": "1.8.2",
|
||||
"version_normalized": "1.8.2.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/bamarni/composer-bin-plugin.git",
|
||||
"reference": "92fd7b1e6e9cdae19b0d57369d8ad31a37b6a880"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/bamarni/composer-bin-plugin/zipball/92fd7b1e6e9cdae19b0d57369d8ad31a37b6a880",
|
||||
"reference": "92fd7b1e6e9cdae19b0d57369d8ad31a37b6a880",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"composer-plugin-api": "^2.0",
|
||||
"php": "^7.2.5 || ^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"composer/composer": "^2.0",
|
||||
"ext-json": "*",
|
||||
"phpstan/extension-installer": "^1.1",
|
||||
"phpstan/phpstan": "^1.8",
|
||||
"phpstan/phpstan-phpunit": "^1.1",
|
||||
"phpunit/phpunit": "^8.5 || ^9.5",
|
||||
"symfony/console": "^2.8.52 || ^3.4.35 || ^4.4 || ^5.0 || ^6.0",
|
||||
"symfony/finder": "^2.8.52 || ^3.4.35 || ^4.4 || ^5.0 || ^6.0",
|
||||
"symfony/process": "^2.8.52 || ^3.4.35 || ^4.4 || ^5.0 || ^6.0"
|
||||
},
|
||||
"time": "2022-10-31T08:38:03+00:00",
|
||||
"type": "composer-plugin",
|
||||
"extra": {
|
||||
"class": "Bamarni\\Composer\\Bin\\BamarniBinPlugin"
|
||||
},
|
||||
"installation-source": "dist",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Bamarni\\Composer\\Bin\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"description": "No conflicts for your bin dependencies",
|
||||
"keywords": [
|
||||
"composer",
|
||||
"conflict",
|
||||
"dependency",
|
||||
"executable",
|
||||
"isolation",
|
||||
"tool"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/bamarni/composer-bin-plugin/issues",
|
||||
"source": "https://github.com/bamarni/composer-bin-plugin/tree/1.8.2"
|
||||
},
|
||||
"install-path": "../bamarni/composer-bin-plugin"
|
||||
}
|
||||
],
|
||||
"dev": true,
|
||||
"dev-package-names": [
|
||||
"bamarni/composer-bin-plugin"
|
||||
]
|
||||
}
|
||||
|
@ -1,23 +1,32 @@
|
||||
<?php return array(
|
||||
'root' => array(
|
||||
'pretty_version' => '1.0.0+no-version-set',
|
||||
'version' => '1.0.0.0',
|
||||
'name' => '__root__',
|
||||
'pretty_version' => 'dev-master',
|
||||
'version' => 'dev-master',
|
||||
'reference' => '1ad489970cd05a57df6649d0e601bfa46eba8564',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../../../',
|
||||
'aliases' => array(),
|
||||
'reference' => NULL,
|
||||
'name' => '__root__',
|
||||
'dev' => false,
|
||||
'dev' => true,
|
||||
),
|
||||
'versions' => array(
|
||||
'__root__' => array(
|
||||
'pretty_version' => '1.0.0+no-version-set',
|
||||
'version' => '1.0.0.0',
|
||||
'pretty_version' => 'dev-master',
|
||||
'version' => 'dev-master',
|
||||
'reference' => '1ad489970cd05a57df6649d0e601bfa46eba8564',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../../../',
|
||||
'aliases' => array(),
|
||||
'reference' => NULL,
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'bamarni/composer-bin-plugin' => array(
|
||||
'pretty_version' => '1.8.2',
|
||||
'version' => '1.8.2.0',
|
||||
'reference' => '92fd7b1e6e9cdae19b0d57369d8ad31a37b6a880',
|
||||
'type' => 'composer-plugin',
|
||||
'install_path' => __DIR__ . '/../bamarni/composer-bin-plugin',
|
||||
'aliases' => array(),
|
||||
'dev_requirement' => true,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright 2023 Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
|
||||
*
|
||||
* @author Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.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\Search\Filter;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use OCP\Search\IFilter;
|
||||
|
||||
class BooleanFilter implements IFilter {
|
||||
private bool $value;
|
||||
|
||||
public function __construct(string $value) {
|
||||
$this->value = match ($value) {
|
||||
'true', 'yes', 'y', '1' => true,
|
||||
'false', 'no', 'n', '0', '' => false,
|
||||
default => throw new InvalidArgumentException('Invalid boolean value '. $value),
|
||||
};
|
||||
}
|
||||
|
||||
public function get(): bool {
|
||||
return $this->value;
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright 2023 Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
|
||||
*
|
||||
* @author Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.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\Search\Filter;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use OCP\Search\IFilter;
|
||||
|
||||
class DateTimeFilter implements IFilter {
|
||||
private DateTimeImmutable $value;
|
||||
|
||||
public function __construct(string $value) {
|
||||
if (filter_var($value, FILTER_VALIDATE_INT)) {
|
||||
$value = '@'.$value;
|
||||
}
|
||||
|
||||
$this->value = new DateTimeImmutable($value);
|
||||
}
|
||||
|
||||
public function get(): DateTimeImmutable {
|
||||
return $this->value;
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright 2023 Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
|
||||
*
|
||||
* @author Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.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\Search\Filter;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use OCP\Search\IFilter;
|
||||
|
||||
class FloatFilter implements IFilter {
|
||||
private float $value;
|
||||
|
||||
public function __construct(string $value) {
|
||||
$this->value = filter_var($value, FILTER_VALIDATE_FLOAT);
|
||||
if ($this->value === false) {
|
||||
throw new InvalidArgumentException('Invalid float value '. $value);
|
||||
}
|
||||
}
|
||||
|
||||
public function get(): float {
|
||||
return $this->value;
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright 2023 Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
|
||||
*
|
||||
* @author Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.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\Search\Filter;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use OCP\IGroup;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\Search\IFilter;
|
||||
|
||||
class GroupFilter implements IFilter {
|
||||
private IGroup $group;
|
||||
|
||||
public function __construct(
|
||||
string $value,
|
||||
IGroupManager $groupManager,
|
||||
) {
|
||||
$this->group = $groupManager->get($value);
|
||||
if ($this->group === null) {
|
||||
throw new InvalidArgumentException('Group '.$value.' not found');
|
||||
}
|
||||
}
|
||||
|
||||
public function get(): IGroup {
|
||||
return $this->group;
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright 2023 Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
|
||||
*
|
||||
* @author Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.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\Search\Filter;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use OCP\Search\IFilter;
|
||||
|
||||
class IntegerFilter implements IFilter {
|
||||
private int $value;
|
||||
|
||||
public function __construct(string $value) {
|
||||
$this->value = filter_var($value, FILTER_VALIDATE_INT);
|
||||
if ($this->value === false) {
|
||||
throw new InvalidArgumentException('Invalid integer value '. $value);
|
||||
}
|
||||
}
|
||||
|
||||
public function get(): int {
|
||||
return $this->value;
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright 2023 Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
|
||||
*
|
||||
* @author Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.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\Search\Filter;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use OCP\Search\IFilter;
|
||||
|
||||
class UserFilter implements IFilter {
|
||||
private IUser $user;
|
||||
|
||||
public function __construct(
|
||||
string $value,
|
||||
IUserManager $userManager,
|
||||
) {
|
||||
$this->user = $userManager->get($value);
|
||||
if ($this->user === null) {
|
||||
throw new InvalidArgumentException('User '.$value.' not found');
|
||||
}
|
||||
}
|
||||
|
||||
public function get(): IUser {
|
||||
return $this->user;
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright 2023 Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
|
||||
*
|
||||
* @author Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.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\Search;
|
||||
|
||||
use Generator;
|
||||
use OCP\Search\IFilterCollection;
|
||||
use OCP\Search\IFilter;
|
||||
|
||||
/**
|
||||
* Interface for search filters
|
||||
*
|
||||
* @since 28.0.0
|
||||
*/
|
||||
class FilterCollection implements IFilterCollection {
|
||||
/**
|
||||
* @var IFilter[]
|
||||
*/
|
||||
private array $filters;
|
||||
|
||||
public function __construct(IFilter ...$filters) {
|
||||
$this->filters = $filters;
|
||||
}
|
||||
|
||||
public function has(string $name): bool {
|
||||
return isset($this->filters[$name]);
|
||||
}
|
||||
|
||||
public function get(string $name): ?IFilter {
|
||||
return $this->filters[$name] ?? null;
|
||||
}
|
||||
|
||||
public function getIterator(): Generator {
|
||||
foreach ($this->filters as $k => $v) {
|
||||
yield $k => $v;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright 2023 Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
|
||||
*
|
||||
* @author Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.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\Search;
|
||||
|
||||
use OCP\Search\FilterDefinition;
|
||||
use OCP\Search\IFilter;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IUserManager;
|
||||
use RuntimeException;
|
||||
|
||||
final class FilterFactory {
|
||||
public static function get(string $type, string|array $filter): IFilter {
|
||||
return match ($type) {
|
||||
FilterDefinition::TYPE_BOOL => new Filter\BooleanFilter($filter),
|
||||
FilterDefinition::TYPE_DATETIME => new Filter\DateTimeFilter($filter),
|
||||
FilterDefinition::TYPE_FLOAT => new Filter\FloatFilter($filter),
|
||||
FilterDefinition::TYPE_INT => new Filter\IntegerFilter($filter),
|
||||
FilterDefinition::TYPE_NC_GROUP => new Filter\GroupFilter($filter, \OC::$server->get(IGroupManager::class)),
|
||||
FilterDefinition::TYPE_NC_USER => new Filter\UserFilter($filter, \OC::$server->get(IUserManager::class)),
|
||||
FilterDefinition::TYPE_PERSON => self::getPerson($filter),
|
||||
FilterDefinition::TYPE_STRING => new Filter\StringFilter($filter),
|
||||
FilterDefinition::TYPE_STRINGS => new Filter\StringsFilter(... (array) $filter),
|
||||
default => throw new RuntimeException('Invalid filter type '. $type),
|
||||
};
|
||||
}
|
||||
|
||||
private static function getPerson(string $person): IFilter {
|
||||
$parts = explode('_', $person, 2);
|
||||
|
||||
return match (count($parts)) {
|
||||
1 => self::get(FilterDefinition::TYPE_NC_USER, $person),
|
||||
2 => self::get(... $parts),
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright 2023 Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
|
||||
*
|
||||
* @author Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.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 OCP\Search;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Filter definition
|
||||
*
|
||||
* Describe filter attributes
|
||||
*
|
||||
* @since 28.0.0
|
||||
*/
|
||||
class FilterDefinition {
|
||||
public const TYPE_BOOL = 'bool';
|
||||
public const TYPE_INT = 'int';
|
||||
public const TYPE_FLOAT = 'float';
|
||||
public const TYPE_STRING = 'string';
|
||||
public const TYPE_STRINGS = 'strings';
|
||||
public const TYPE_DATETIME = 'datetime';
|
||||
public const TYPE_PERSON = 'person';
|
||||
public const TYPE_NC_USER = 'nc-user';
|
||||
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
|
||||
* @throw 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;
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright 2023 Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
|
||||
*
|
||||
* @author Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.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 OCP\Search;
|
||||
|
||||
/**
|
||||
* Interface for search filters
|
||||
*
|
||||
* @since 28.0.0
|
||||
*/
|
||||
interface IFilter {
|
||||
/**
|
||||
* Get filter value
|
||||
*
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function get(): mixed;
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright 2023 Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
|
||||
*
|
||||
* @author Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.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 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;
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright 2023 Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
|
||||
*
|
||||
* @author Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.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 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;
|
||||
}
|
Loading…
Reference in New Issue