IFullTextSearchProvider.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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\IIndex;
  29. use OCP\FullTextSearch\Model\IIndexOptions;
  30. use OCP\FullTextSearch\Model\IndexDocument;
  31. use OCP\FullTextSearch\Model\IRunner;
  32. use OCP\FullTextSearch\Model\ISearchRequest;
  33. use OCP\FullTextSearch\Model\ISearchResult;
  34. use OCP\FullTextSearch\Model\SearchTemplate;
  35. /**
  36. * Interface IFullTextSearchProvider
  37. *
  38. * This interface must be use when creating a Content Provider for FullTextSearch.
  39. *
  40. * A Content Provider is an extension to the FullTextSearch that will extract and
  41. * provide content to the FullTextSearch.
  42. *
  43. * There is no limit to the number of Content Provider that can be integrated to
  44. * FullTextSearch. Each Content Provider corresponding to a type of content
  45. * available in Nextcloud (files, bookmarks, notes, deck cards, mails, ...)
  46. *
  47. * Content is split in document identified by an ID and the ID of the Content
  48. * Provider. The content is indexed by a Search Platform that will returns a
  49. * documentId as a result on a search request.
  50. *
  51. *
  52. * To oversimplify the mechanism:
  53. *
  54. * - When indexing, FullTextSearch will ask for documents to every Content Provider.
  55. * - On search, results from the Search Platform, identified by documentId, will
  56. * be improved by each relative Content Provider.
  57. *
  58. *
  59. * The Content Provider is 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. * <provider>OCA\YourApp\YourContentProvider</provider>
  64. * </fulltextsearch>
  65. *
  66. * Multiple Content Provider can be defined in a single app.
  67. *
  68. * @since 15.0.0
  69. *
  70. * @package OCP\FullTextSearch
  71. */
  72. interface IFullTextSearchProvider {
  73. /**
  74. * Must returns a unique Id used to identify the Content Provider.
  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 Content Provider.
  84. * This is used in multiple places, so better use a clear display name.
  85. *
  86. * @since 15.0.0
  87. *
  88. * @return string
  89. */
  90. public function getName(): string;
  91. /**
  92. * Should returns the current configuration of the Content Provider.
  93. * This is used to display the configuration when using the
  94. * ./occ fulltextsearch:check command line.
  95. *
  96. * @since 15.0.0
  97. *
  98. * @return array
  99. */
  100. public function getConfiguration(): array;
  101. /**
  102. * Must returns a SearchTemplate that contains displayable items and
  103. * available options to users when searching.
  104. *
  105. * @see SearchTemplate
  106. *
  107. * @since 15.0.0
  108. *
  109. * @return SearchTemplate
  110. */
  111. public function getSearchTemplate(): SearchTemplate;
  112. /**
  113. * Called when FullTextSearch is loading your Content Provider.
  114. *
  115. * @since 15.0.0
  116. */
  117. public function loadProvider();
  118. /**
  119. * Set the wrapper of the currently executed process.
  120. * Because the index process can be long and heavy, and because errors can
  121. * be encountered during the process, the IRunner is a wrapper that allow the
  122. * Content Provider to communicate with the process initiated by
  123. * FullTextSearch.
  124. *
  125. * The IRunner is coming with some methods so the Content Provider can
  126. * returns important information and errors to be displayed to the admin.
  127. *
  128. * @since 15.0.0
  129. *
  130. * @param IRunner $runner
  131. */
  132. public function setRunner(IRunner $runner);
  133. /**
  134. * This method is called when the administrator specify options when running
  135. * the ./occ fulltextsearch:index or ./occ fulltextsearch:live
  136. *
  137. * @since 15.0.0
  138. *
  139. * @param IIndexOptions $options
  140. */
  141. public function setIndexOptions(IIndexOptions $options);
  142. /**
  143. * Allow the provider to generate a list of chunk to split a huge list of
  144. * indexable documents
  145. *
  146. * During the indexing the generateIndexableDocuments method will be called
  147. * for each entry of the returned array.
  148. * If the returned array is empty, the generateIndexableDocuments() will be
  149. * called only once (per user).
  150. *
  151. * @since 16.0.0
  152. *
  153. * @param string $userId
  154. *
  155. * @return string[]
  156. */
  157. public function generateChunks(string $userId): array;
  158. /**
  159. * Returns all indexable document for a user as an array of IndexDocument.
  160. *
  161. * There is no need to fill each IndexDocument with content; at this point,
  162. * only fill the object with the minimum information to not waste memory while
  163. * still being able to identify the document it is referring to.
  164. *
  165. * FullTextSearch will call 2 other methods of this interface for each
  166. * IndexDocument of the array, prior to their indexing:
  167. *
  168. * - first, to compare the date of the last index,
  169. * - then, to fill each IndexDocument with complete data
  170. *
  171. * @see IndexDocument
  172. *
  173. * @since 15.0.0
  174. * -> 16.0.0: the parameter "$chunk" was added
  175. *
  176. * @param string $userId
  177. * @param string $chunk
  178. *
  179. * @return IndexDocument[]
  180. */
  181. public function generateIndexableDocuments(string $userId, string $chunk): array;
  182. /**
  183. * Called to verify that the document is not already indexed and that the
  184. * old index is not up-to-date, using the IIndex from
  185. * IndexDocument->getIndex()
  186. *
  187. * Returning true will not queue the current IndexDocument to any further
  188. * operation and will continue on the next element from the list returned by
  189. * generateIndexableDocuments().
  190. *
  191. * @since 15.0.0
  192. *
  193. * @param IndexDocument $document
  194. *
  195. * @return bool
  196. */
  197. public function isDocumentUpToDate(IndexDocument $document): bool;
  198. /**
  199. * Must fill IndexDocument with all information relative to the document,
  200. * before its indexing by the Search Platform.
  201. *
  202. * Method is called for each element returned previously by
  203. * generateIndexableDocuments().
  204. *
  205. * @see IndexDocument
  206. *
  207. * @since 15.0.0
  208. *
  209. * @param IndexDocument $document
  210. */
  211. public function fillIndexDocument(IndexDocument $document);
  212. /**
  213. * The Search Provider must create and return an IndexDocument
  214. * based on the IIndex and its status. The IndexDocument must contains all
  215. * information as it will be send for indexing.
  216. *
  217. * Method is called during a cron or a ./occ fulltextsearch:live after a
  218. * new document is created, or an old document is set as modified.
  219. *
  220. * @since 15.0.0
  221. *
  222. * @param IIndex $index
  223. *
  224. * @return IndexDocument
  225. */
  226. public function updateDocument(IIndex $index): IndexDocument;
  227. /**
  228. * Called when an index is initiated by the administrator.
  229. * This is should only be used in case of a specific mapping is needed.
  230. * (ie. _almost_ never)
  231. *
  232. * @since 15.0.0
  233. *
  234. * @param IFullTextSearchPlatform $platform
  235. */
  236. public function onInitializingIndex(IFullTextSearchPlatform $platform);
  237. /**
  238. * Called when administrator is resetting the index.
  239. * This is should only be used in case of a specific mapping has been
  240. * created.
  241. *
  242. * @since 15.0.0
  243. *
  244. * @param IFullTextSearchPlatform $platform
  245. */
  246. public function onResettingIndex(IFullTextSearchPlatform $platform);
  247. /**
  248. * Method is called when a search request is initiated by a user, prior to
  249. * be sent to the Search Platform.
  250. *
  251. * Your Content Provider can interact with the ISearchRequest to apply the
  252. * search options and make the search more precise.
  253. *
  254. * @see ISearchRequest
  255. *
  256. * @since 15.0.0
  257. *
  258. * @param ISearchRequest $searchRequest
  259. */
  260. public function improveSearchRequest(ISearchRequest $searchRequest);
  261. /**
  262. * Method is called after results of a search are returned by the
  263. * Search Platform.
  264. *
  265. * Your Content Provider can detail each entry with local data to improve
  266. * the display of the search result.
  267. *
  268. * @see ISearchResult
  269. *
  270. * @since 15.0.0
  271. *
  272. * @param ISearchResult $searchResult
  273. */
  274. public function improveSearchResult(ISearchResult $searchResult);
  275. /**
  276. * not used yet.
  277. *
  278. * @since 15.0.0
  279. */
  280. public function unloadProvider();
  281. }