IFullTextSearchPlatform.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * FullTextSearch - Full text search framework for Nextcloud
  5. *
  6. * This file is licensed under the Affero General Public License version 3 or
  7. * later. See the COPYING file.
  8. *
  9. * @author Maxence Lange <maxence@artificial-owl.com>
  10. * @copyright 2018
  11. * @license GNU AGPL version 3 or any later version
  12. *
  13. * This program is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License as
  15. * published by the Free Software Foundation, either version 3 of the
  16. * License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  25. *
  26. */
  27. namespace OCP\FullTextSearch;
  28. use OCP\FullTextSearch\Model\DocumentAccess;
  29. use OCP\FullTextSearch\Model\IIndex;
  30. use OCP\FullTextSearch\Model\IndexDocument;
  31. use OCP\FullTextSearch\Model\IRunner;
  32. use OCP\FullTextSearch\Model\ISearchResult;
  33. /**
  34. * Interface IFullTextSearchPlatform
  35. *
  36. * This interface must be use when creating a Search Platform for FullTextSearch.
  37. *
  38. * A Search Platform is an extension to the FullTextSearch that will act as a
  39. * a gateway between FullTextSearch and a search server (ie. ElasticSearch,
  40. * Solr, ...)
  41. *
  42. * Multiple Search Platform can exist at the same time in Nextcloud, however only
  43. * one Search Platform will be used by FullTextSearch.
  44. * Administrator must select at least one Search Platform to be used by
  45. * FullTextSearch in the admin settings page.
  46. *
  47. * The content provided by FullTextSearch comes in chunk from multiple Content
  48. * Provider. Each chunk is identified by the ID of the Content Provider, and the
  49. * ID of the document.
  50. *
  51. *
  52. * To oversimplify the mechanism:
  53. *
  54. * - When indexing, FullTextSearch will send providerId, documentId, content.
  55. * - When searching within the content of a Content Provider, identified by its
  56. * providerId, FullTextSearch expect documentId as result.
  57. *
  58. *
  59. * The Search Platform ia a PHP class that implement this interface and is defined
  60. * in appinfo/info.xml of the app that contains that class:
  61. *
  62. * <fulltextsearch>
  63. * <platform>OCA\YourApp\YourSearchPlatform</platform>
  64. * </fulltextsearch>
  65. *
  66. * Multiple Search Platform can be defined in a single app.
  67. *
  68. * @since 15.0.0
  69. *
  70. * @package OCP\FullTextSearch
  71. */
  72. interface IFullTextSearchPlatform {
  73. /**
  74. * Must returns a unique Id used to identify the Search Platform.
  75. * Id must contains only alphanumeric chars, with no space.
  76. *
  77. * @since 15.0.0
  78. *
  79. * @return string
  80. */
  81. public function getId(): string;
  82. /**
  83. * Must returns a descriptive name of the Search Platform.
  84. * This is used mainly in the admin settings page to display the list of
  85. * available Search Platform
  86. *
  87. * @since 15.0.0
  88. *
  89. * @return string
  90. */
  91. public function getName(): string;
  92. /**
  93. * should returns the current configuration of the Search Platform.
  94. * This is used to display the configuration when using the
  95. * ./occ fulltextsearch:check command line.
  96. *
  97. * @since 15.0.0
  98. *
  99. * @return array
  100. */
  101. public function getConfiguration(): array;
  102. /**
  103. * Set the wrapper of the currently executed process.
  104. * Because the index process can be long and heavy, and because errors can
  105. * be encountered during the process, the IRunner is a wrapper that allow the
  106. * Search Platform to communicate with the process initiated by
  107. * FullTextSearch.
  108. *
  109. * The IRunner is coming with some methods so the Search Platform can
  110. * returns important information and errors to be displayed to the admin.
  111. *
  112. * @since 15.0.0
  113. *
  114. * @param IRunner $runner
  115. */
  116. public function setRunner(IRunner $runner);
  117. /**
  118. * Called when FullTextSearch is loading your Search Platform.
  119. *
  120. * @since 15.0.0
  121. */
  122. public function loadPlatform();
  123. /**
  124. * Called to check that your Search Platform is correctly configured and that
  125. * This is also the right place to check that the Search Service is available.
  126. *
  127. * @since 15.0.0
  128. *
  129. * @return bool
  130. */
  131. public function testPlatform(): bool;
  132. /**
  133. * Called before an index is initiated.
  134. * Best place to initiate some stuff on the Search Server (mapping, ...)
  135. *
  136. * @since 15.0.0
  137. */
  138. public function initializeIndex();
  139. /**
  140. * Reset the indexes for a specific providerId.
  141. * $providerId can be 'all' if it is a global reset.
  142. *
  143. * @since 15.0.0
  144. *
  145. * @param string $providerId
  146. */
  147. public function resetIndex(string $providerId);
  148. /**
  149. * Deleting some IIndex, sent in an array
  150. *
  151. * @see IIndex
  152. *
  153. * @since 15.0.0
  154. *
  155. * @param IIndex[] $indexes
  156. */
  157. public function deleteIndexes(array $indexes);
  158. /**
  159. * Indexing a document.
  160. *
  161. * @see IndexDocument
  162. *
  163. * @since 15.0.0
  164. *
  165. * @param IndexDocument $document
  166. *
  167. * @return IIndex
  168. */
  169. public function indexDocument(IndexDocument $document): IIndex;
  170. /**
  171. * Searching documents, ISearchResult should be updated with the result of
  172. * the search.
  173. *
  174. * @since 15.0.0
  175. *
  176. * @param ISearchResult $result
  177. * @param DocumentAccess $access
  178. */
  179. public function searchRequest(ISearchResult $result, DocumentAccess $access);
  180. /**
  181. * Return a document based on its Id and the Provider.
  182. * This is used when an admin execute ./occ fulltextsearch:document:platform
  183. *
  184. * @since 15.0.0
  185. *
  186. * @param string $providerId
  187. * @param string $documentId
  188. *
  189. * @return IndexDocument
  190. */
  191. public function getDocument(string $providerId, string $documentId): IndexDocument;
  192. }