IFullTextSearchProvider.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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. * Returns all indexable document for a user as an array of IndexDocument.
  144. *
  145. * There is no need to fill each IndexDocument with content; at this point,
  146. * only fill the object with the minimum information to not waste memory while
  147. * still being able to identify the document it is referring to.
  148. *
  149. * FullTextSearch will call 2 other methods of this interface for each
  150. * IndexDocument of the array, prior to their indexing:
  151. *
  152. * - first, to compare the date of the last index,
  153. * - then, to fill each IndexDocument with complete data
  154. *
  155. * @see IndexDocument
  156. *
  157. * @since 15.0.0
  158. *
  159. * @param string $userId
  160. *
  161. * @return IndexDocument[]
  162. */
  163. public function generateIndexableDocuments(string $userId): array;
  164. /**
  165. * Called to verify that the document is not already indexed and that the
  166. * old index is not up-to-date, using the IIndex from
  167. * IndexDocument->getIndex()
  168. *
  169. * Returning true will not queue the current IndexDocument to any further
  170. * operation and will continue on the next element from the list returned by
  171. * generateIndexableDocuments().
  172. *
  173. * @since 15.0.0
  174. *
  175. * @param IndexDocument $document
  176. *
  177. * @return bool
  178. */
  179. public function isDocumentUpToDate(IndexDocument $document): bool;
  180. /**
  181. * Must fill IndexDocument with all information relative to the document,
  182. * before its indexing by the Search Platform.
  183. *
  184. * Method is called for each element returned previously by
  185. * generateIndexableDocuments().
  186. *
  187. * @see IndexDocument
  188. *
  189. * @since 15.0.0
  190. *
  191. * @param IndexDocument $document
  192. */
  193. public function fillIndexDocument(IndexDocument $document);
  194. /**
  195. * The Search Provider must create and return an IndexDocument
  196. * based on the IIndex and its status. The IndexDocument must contains all
  197. * information as it will be send for indexing.
  198. *
  199. * Method is called during a cron or a ./occ fulltextsearch:live after a
  200. * new document is created, or an old document is set as modified.
  201. *
  202. * @since 15.0.0
  203. *
  204. * @param IIndex $index
  205. *
  206. * @return IndexDocument
  207. */
  208. public function updateDocument(IIndex $index): IndexDocument;
  209. /**
  210. * Called when an index is initiated by the administrator.
  211. * This is should only be used in case of a specific mapping is needed.
  212. * (ie. _almost_ never)
  213. *
  214. * @since 15.0.0
  215. *
  216. * @param IFullTextSearchPlatform $platform
  217. */
  218. public function onInitializingIndex(IFullTextSearchPlatform $platform);
  219. /**
  220. * Called when administrator is resetting the index.
  221. * This is should only be used in case of a specific mapping has been
  222. * created.
  223. *
  224. * @since 15.0.0
  225. *
  226. * @param IFullTextSearchPlatform $platform
  227. */
  228. public function onResettingIndex(IFullTextSearchPlatform $platform);
  229. /**
  230. * Method is called when a search request is initiated by a user, prior to
  231. * be sent to the Search Platform.
  232. *
  233. * Your Content Provider can interact with the ISearchRequest to apply the
  234. * search options and make the search more precise.
  235. *
  236. * @see ISearchRequest
  237. *
  238. * @since 15.0.0
  239. *
  240. * @param ISearchRequest $searchRequest
  241. */
  242. public function improveSearchRequest(ISearchRequest $searchRequest);
  243. /**
  244. * Method is called after results of a search are returned by the
  245. * Search Platform.
  246. *
  247. * Your Content Provider can detail each entry with local data to improve
  248. * the display of the search result.
  249. *
  250. * @see ISearchResult
  251. *
  252. * @since 15.0.0
  253. *
  254. * @param ISearchResult $searchResult
  255. */
  256. public function improveSearchResult(ISearchResult $searchResult);
  257. /**
  258. * not used yet.
  259. *
  260. * @since 15.0.0
  261. */
  262. public function unloadProvider();
  263. }