IProvider.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 OCP\Search;
  8. use OCP\IUser;
  9. /**
  10. * Interface for search providers
  11. *
  12. * These providers will be implemented in apps, so they can participate in the
  13. * global search results of Nextcloud. If an app provides more than one type of
  14. * resource, e.g. contacts and address books in Nextcloud Contacts, it should
  15. * register one provider per group.
  16. *
  17. * @since 20.0.0
  18. */
  19. interface IProvider {
  20. /**
  21. * Get the unique ID of this search provider
  22. *
  23. * Ideally this should be the app name or an identifier identified with the
  24. * app name, especially if the app registers more than one provider.
  25. *
  26. * Example: 'mail', 'mail_recipients', 'files_sharing'
  27. *
  28. * @return string
  29. *
  30. * @since 20.0.0
  31. */
  32. public function getId(): string;
  33. /**
  34. * Get the translated name of this search provider
  35. *
  36. * Example: 'Mail', 'Contacts'...
  37. *
  38. * @return string
  39. *
  40. * @since 20.0.0
  41. */
  42. public function getName(): string;
  43. /**
  44. * Get the search provider order
  45. * The lower the int, the higher it will be sorted (0 will be before 10)
  46. * If null, the search provider will be hidden in the UI and the API not called
  47. *
  48. * @param string $route the route the user is currently at, e.g. files.view.index
  49. * @param array $routeParameters the parameters of the route the user is currently at, e.g. [fileId = 982, dir = "/"]
  50. *
  51. * @return int|null
  52. *
  53. * @since 20.0.0
  54. * @since 28.0.0 Can return null
  55. */
  56. public function getOrder(string $route, array $routeParameters): ?int;
  57. /**
  58. * Find matching search entries in an app
  59. *
  60. * Search results can either be a complete list of all the matches the app can
  61. * find, or ideally a paginated result set where more data can be fetched on
  62. * demand. To be able to tell where the next offset starts the search uses
  63. * "cursors" which are a property of the last result entry. E.g. search results
  64. * that show most recent entries first can look for entries older than the last
  65. * one of the first result set. This approach was chosen over a numeric limit/
  66. * offset approach as the offset moves as new data comes in. The cursor is
  67. * resistant to these changes and will still show results without overlaps or
  68. * gaps.
  69. *
  70. * See https://dev.to/jackmarchant/offset-and-cursor-pagination-explained-b89
  71. * for the concept of cursors.
  72. *
  73. * Implementations that return result pages have to adhere to the limit
  74. * property of a search query.
  75. *
  76. * @param IUser $user
  77. * @param ISearchQuery $query
  78. *
  79. * @return SearchResult
  80. *
  81. * @since 20.0.0
  82. */
  83. public function search(IUser $user, ISearchQuery $query): SearchResult;
  84. }