SearchQuery.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OC\Search;
  8. use OCP\Search\IFilter;
  9. use OCP\Search\IFilterCollection;
  10. use OCP\Search\ISearchQuery;
  11. class SearchQuery implements ISearchQuery {
  12. public const LIMIT_DEFAULT = 5;
  13. /**
  14. * @param string[] $params Request query
  15. * @param string[] $routeParameters
  16. */
  17. public function __construct(
  18. private IFilterCollection $filters,
  19. private int $sortOrder = ISearchQuery::SORT_DATE_DESC,
  20. private int $limit = self::LIMIT_DEFAULT,
  21. private int|string|null $cursor = null,
  22. private string $route = '',
  23. private array $routeParameters = [],
  24. ) {
  25. }
  26. public function getTerm(): string {
  27. return $this->getFilter('term')?->get() ?? '';
  28. }
  29. public function getFilter(string $name): ?IFilter {
  30. return $this->filters->has($name)
  31. ? $this->filters->get($name)
  32. : null;
  33. }
  34. public function getFilters(): IFilterCollection {
  35. return $this->filters;
  36. }
  37. public function getSortOrder(): int {
  38. return $this->sortOrder;
  39. }
  40. public function getLimit(): int {
  41. return $this->limit;
  42. }
  43. public function getCursor(): int|string|null {
  44. return $this->cursor;
  45. }
  46. public function getRoute(): string {
  47. return $this->route;
  48. }
  49. public function getRouteParameters(): array {
  50. return $this->routeParameters;
  51. }
  52. }