SearchQuery.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2020 Christoph Wurst <christoph@winzerhof-wurst.at>
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author John Molakvoæ <skjnldsv@protonmail.com>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OC\Search;
  27. use OCP\Search\IFilter;
  28. use OCP\Search\IFilterCollection;
  29. use OCP\Search\ISearchQuery;
  30. class SearchQuery implements ISearchQuery {
  31. public const LIMIT_DEFAULT = 5;
  32. /**
  33. * @param string[] $params Request query
  34. * @param string[] $routeParameters
  35. */
  36. public function __construct(
  37. private IFilterCollection $filters,
  38. private int $sortOrder = ISearchQuery::SORT_DATE_DESC,
  39. private int $limit = self::LIMIT_DEFAULT,
  40. private int|string|null $cursor = null,
  41. private string $route = '',
  42. private array $routeParameters = [],
  43. ) {
  44. }
  45. public function getTerm(): string {
  46. return $this->getFilter('term')?->get() ?? '';
  47. }
  48. public function getFilter(string $name): ?IFilter {
  49. return $this->filters->has($name)
  50. ? $this->filters->get($name)
  51. : null;
  52. }
  53. public function getFilters(): IFilterCollection {
  54. return $this->filters;
  55. }
  56. public function getSortOrder(): int {
  57. return $this->sortOrder;
  58. }
  59. public function getLimit(): int {
  60. return $this->limit;
  61. }
  62. public function getCursor(): int|string|null {
  63. return $this->cursor;
  64. }
  65. public function getRoute(): string {
  66. return $this->route;
  67. }
  68. public function getRouteParameters(): array {
  69. return $this->routeParameters;
  70. }
  71. }