1
0

IIndexDocument.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCP\FullTextSearch\Model;
  8. /**
  9. * Class IIndexDocument
  10. *
  11. * This is one of the main class of the FullTextSearch, used as a data transfer
  12. * object. An IIndexDocument is created to manage documents around FullTextSearch,
  13. * during an index and during a search.
  14. * The uniqueness of an IIndexDocument is made by the Id of the Content Provider
  15. * and the Id of the original document within the Content Provider.
  16. *
  17. * We will call original document the source from which the IIndexDocument is
  18. * generated. As an example, an original document can be a file, a mail, ...
  19. *
  20. * @since 15.0.0
  21. */
  22. interface IIndexDocument {
  23. /**
  24. * @since 15.0.0
  25. */
  26. public const NOT_ENCODED = 0;
  27. /**
  28. * @since 15.0.0
  29. */
  30. public const ENCODED_BASE64 = 1;
  31. /**
  32. * Returns the Id of the original document.
  33. *
  34. * @since 15.0.0
  35. *
  36. * @return string
  37. */
  38. public function getId(): string;
  39. /**
  40. * Returns the Id of the provider.
  41. *
  42. * @since 15.0.0
  43. *
  44. * @return string
  45. */
  46. public function getProviderId(): string;
  47. /**
  48. * Set the Index related to the IIndexDocument.
  49. *
  50. * @see IIndex
  51. *
  52. * @since 15.0.0
  53. *
  54. * @param IIndex $index
  55. *
  56. * @return IIndexDocument
  57. */
  58. public function setIndex(IIndex $index): IIndexDocument;
  59. /**
  60. * Get the Index.
  61. *
  62. * @since 15.0.0
  63. *
  64. * @return IIndex
  65. */
  66. public function getIndex(): IIndex;
  67. /**
  68. * return if Index is defined.
  69. *
  70. * @since 16.0.0
  71. *
  72. * @return bool
  73. */
  74. public function hasIndex(): bool;
  75. /**
  76. * Set the modified time of the original document.
  77. *
  78. * @since 15.0.0
  79. *
  80. * @param int $modifiedTime
  81. *
  82. * @return IIndexDocument
  83. */
  84. public function setModifiedTime(int $modifiedTime): IIndexDocument;
  85. /**
  86. * Get the modified time of the original document.
  87. *
  88. * @since 15.0.0
  89. *
  90. * @return int
  91. */
  92. public function getModifiedTime(): int;
  93. /**
  94. * Check if the original document of the IIndexDocument is older than $time.
  95. *
  96. * @since 15.0.0
  97. *
  98. * @param int $time
  99. *
  100. * @return bool
  101. */
  102. public function isOlderThan(int $time): bool;
  103. /**
  104. * Set the read rights of the original document using a IDocumentAccess.
  105. *
  106. * @see IDocumentAccess
  107. *
  108. * @since 15.0.0
  109. *
  110. * @param IDocumentAccess $access
  111. *
  112. * @return $this
  113. */
  114. public function setAccess(IDocumentAccess $access): IIndexDocument;
  115. /**
  116. * Get the IDocumentAccess related to the original document.
  117. *
  118. * @since 15.0.0
  119. *
  120. * @return IDocumentAccess
  121. */
  122. public function getAccess(): IDocumentAccess;
  123. /**
  124. * Add a tag to the list.
  125. *
  126. * @since 15.0.0
  127. *
  128. * @param string $tag
  129. *
  130. * @return IIndexDocument
  131. */
  132. public function addTag(string $tag): IIndexDocument;
  133. /**
  134. * Set the list of tags assigned to the original document.
  135. *
  136. * @since 15.0.0
  137. *
  138. * @param array $tags
  139. *
  140. * @return IIndexDocument
  141. */
  142. public function setTags(array $tags): IIndexDocument;
  143. /**
  144. * Get the list of tags assigned to the original document.
  145. *
  146. * @since 15.0.0
  147. *
  148. * @return array
  149. */
  150. public function getTags(): array;
  151. /**
  152. * Add a meta tag to the list.
  153. *
  154. * @since 15.0.0
  155. *
  156. * @param string $tag
  157. *
  158. * @return IIndexDocument
  159. */
  160. public function addMetaTag(string $tag): IIndexDocument;
  161. /**
  162. * Set the list of meta tags assigned to the original document.
  163. *
  164. * @since 15.0.0
  165. *
  166. * @param array $tags
  167. *
  168. * @return IIndexDocument
  169. */
  170. public function setMetaTags(array $tags): IIndexDocument;
  171. /**
  172. * Get the list of meta tags assigned to the original document.
  173. *
  174. * @since 15.0.0
  175. *
  176. * @return array
  177. */
  178. public function getMetaTags(): array;
  179. /**
  180. * Add a sub tag to the list.
  181. *
  182. * @since 15.0.0
  183. *
  184. * @param string $sub
  185. * @param string $tag
  186. *
  187. * @return IIndexDocument
  188. */
  189. public function addSubTag(string $sub, string $tag): IIndexDocument;
  190. /**
  191. * Set the list of sub tags assigned to the original document.
  192. *
  193. * @since 15.0.0
  194. *
  195. * @param array $tags
  196. *
  197. * @return IIndexDocument
  198. */
  199. public function setSubTags(array $tags): IIndexDocument;
  200. /**
  201. * Get the list of sub tags assigned to the original document.
  202. * If $formatted is true, the result will be formatted in a one
  203. * dimensional array.
  204. *
  205. * @since 15.0.0
  206. *
  207. * @param bool $formatted
  208. *
  209. * @return array
  210. */
  211. public function getSubTags(bool $formatted = false): array;
  212. /**
  213. * Set the source of the original document.
  214. *
  215. * @since 15.0.0
  216. *
  217. * @param string $source
  218. *
  219. * @return IIndexDocument
  220. */
  221. public function setSource(string $source): IIndexDocument;
  222. /**
  223. * Get the source of the original document.
  224. *
  225. * @since 15.0.0
  226. *
  227. * @return string
  228. */
  229. public function getSource(): string;
  230. /**
  231. * Set the title of the original document.
  232. *
  233. * @since 15.0.0
  234. *
  235. * @param string $title
  236. *
  237. * @return IIndexDocument
  238. */
  239. public function setTitle(string $title): IIndexDocument;
  240. /**
  241. * Get the title of the original document.
  242. *
  243. * @since 15.0.0
  244. *
  245. * @return string
  246. */
  247. public function getTitle(): string;
  248. /**
  249. * Set the content of the document.
  250. * $encoded can be NOT_ENCODED or ENCODED_BASE64 if the content is raw or
  251. * encoded in base64.
  252. *
  253. * @since 15.0.0
  254. *
  255. * @param string $content
  256. * @param int $encoded
  257. *
  258. * @return IIndexDocument
  259. */
  260. public function setContent(string $content, int $encoded = 0): IIndexDocument;
  261. /**
  262. * Get the content of the original document.
  263. *
  264. * @since 15.0.0
  265. *
  266. * @return string
  267. */
  268. public function getContent(): string;
  269. /**
  270. * Returns the type of the encoding on the content.
  271. *
  272. * @since 15.0.0
  273. *
  274. * @return int
  275. */
  276. public function isContentEncoded(): int;
  277. /**
  278. * Return the size of the content.
  279. *
  280. * @since 15.0.0
  281. *
  282. * @return int
  283. */
  284. public function getContentSize(): int;
  285. /**
  286. * Generate an hash, based on the content of the original document.
  287. *
  288. * @since 15.0.0
  289. *
  290. * @return IIndexDocument
  291. */
  292. public function initHash(): IIndexDocument;
  293. /**
  294. * Set the hash of the original document.
  295. *
  296. * @since 15.0.0
  297. *
  298. * @param string $hash
  299. *
  300. * @return IIndexDocument
  301. */
  302. public function setHash(string $hash): IIndexDocument;
  303. /**
  304. * Get the hash of the original document.
  305. *
  306. * @since 15.0.0
  307. *
  308. * @return string
  309. */
  310. public function getHash(): string;
  311. /**
  312. * Add a part, identified by a string, and its content.
  313. *
  314. * It is strongly advised to use alphanumerical chars with no space in the
  315. * $part string.
  316. *
  317. * @since 15.0.0
  318. *
  319. * @param string $part
  320. * @param string $content
  321. *
  322. * @return IIndexDocument
  323. */
  324. public function addPart(string $part, string $content): IIndexDocument;
  325. /**
  326. * Set all parts and their content.
  327. *
  328. * @since 15.0.0
  329. *
  330. * @param array $parts
  331. *
  332. * @return IIndexDocument
  333. */
  334. public function setParts(array $parts): IIndexDocument;
  335. /**
  336. * Get all parts of the IIndexDocument.
  337. *
  338. * @since 15.0.0
  339. *
  340. * @return array
  341. */
  342. public function getParts(): array;
  343. /**
  344. * Add a link, usable by the frontend.
  345. *
  346. * @since 15.0.0
  347. *
  348. * @param string $link
  349. *
  350. * @return IIndexDocument
  351. */
  352. public function setLink(string $link): IIndexDocument;
  353. /**
  354. * Get the link.
  355. *
  356. * @since 15.0.0
  357. *
  358. * @return string
  359. */
  360. public function getLink(): string;
  361. /**
  362. * Set more information that couldn't be set using other method.
  363. *
  364. * @since 15.0.0
  365. *
  366. * @param array $more
  367. *
  368. * @return IIndexDocument
  369. */
  370. public function setMore(array $more): IIndexDocument;
  371. /**
  372. * Get more information.
  373. *
  374. * @since 15.0.0
  375. *
  376. * @return array
  377. */
  378. public function getMore(): array;
  379. /**
  380. * Add some excerpt of the content of the original document, usually based
  381. * on the search request.
  382. *
  383. * @since 16.0.0
  384. *
  385. * @param string $source
  386. * @param string $excerpt
  387. *
  388. * @return IIndexDocument
  389. */
  390. public function addExcerpt(string $source, string $excerpt): IIndexDocument;
  391. /**
  392. * Set all excerpts of the content of the original document.
  393. *
  394. * @since 16.0.0
  395. *
  396. * @param array $excerpts
  397. *
  398. * @return IIndexDocument
  399. */
  400. public function setExcerpts(array $excerpts): IIndexDocument;
  401. /**
  402. * Get all excerpts of the content of the original document.
  403. *
  404. * @since 15.0.0
  405. *
  406. * @return array
  407. */
  408. public function getExcerpts(): array;
  409. /**
  410. * Set the score to the result assigned to this document during a search
  411. * request.
  412. *
  413. * @since 15.0.0
  414. *
  415. * @param string $score
  416. *
  417. * @return IIndexDocument
  418. */
  419. public function setScore(string $score): IIndexDocument;
  420. /**
  421. * Get the score.
  422. *
  423. * @since 15.0.0
  424. *
  425. * @return string
  426. */
  427. public function getScore(): string;
  428. /**
  429. * Set some information about the original document that will be available
  430. * to the front-end when displaying search result. (as string)
  431. * Because this information will not be indexed, this method can also be
  432. * used to manage some data while filling the IIndexDocument before its
  433. * indexing.
  434. *
  435. * @since 15.0.0
  436. *
  437. * @param string $info
  438. * @param string $value
  439. *
  440. * @return IIndexDocument
  441. */
  442. public function setInfo(string $info, string $value): IIndexDocument;
  443. /**
  444. * Get an information about a document. (string)
  445. *
  446. * @since 15.0.0
  447. *
  448. * @param string $info
  449. * @param string $default
  450. *
  451. * @return string
  452. */
  453. public function getInfo(string $info, string $default = ''): string;
  454. /**
  455. * Set some information about the original document that will be available
  456. * to the front-end when displaying search result. (as array)
  457. * Because this information will not be indexed, this method can also be
  458. * used to manage some data while filling the IIndexDocument before its
  459. * indexing.
  460. *
  461. * @since 15.0.0
  462. *
  463. * @param string $info
  464. * @param array $value
  465. *
  466. * @return IIndexDocument
  467. */
  468. public function setInfoArray(string $info, array $value): IIndexDocument;
  469. /**
  470. * Get an information about a document. (array)
  471. *
  472. * @since 15.0.0
  473. *
  474. * @param string $info
  475. * @param array $default
  476. *
  477. * @return array
  478. */
  479. public function getInfoArray(string $info, array $default = []): array;
  480. /**
  481. * Set some information about the original document that will be available
  482. * to the front-end when displaying search result. (as int)
  483. * Because this information will not be indexed, this method can also be
  484. * used to manage some data while filling the IIndexDocument before its
  485. * indexing.
  486. *
  487. * @since 15.0.0
  488. *
  489. * @param string $info
  490. * @param int $value
  491. *
  492. * @return IIndexDocument
  493. */
  494. public function setInfoInt(string $info, int $value): IIndexDocument;
  495. /**
  496. * Get an information about a document. (int)
  497. *
  498. * @since 15.0.0
  499. *
  500. * @param string $info
  501. * @param int $default
  502. *
  503. * @return int
  504. */
  505. public function getInfoInt(string $info, int $default = 0): int;
  506. /**
  507. * Set some information about the original document that will be available
  508. * to the front-end when displaying search result. (as bool)
  509. * Because this information will not be indexed, this method can also be
  510. * used to manage some data while filling the IIndexDocument before its
  511. * indexing.
  512. *
  513. * @since 15.0.0
  514. *
  515. * @param string $info
  516. * @param bool $value
  517. *
  518. * @return IIndexDocument
  519. */
  520. public function setInfoBool(string $info, bool $value): IIndexDocument;
  521. /**
  522. * Get an information about a document. (bool)
  523. *
  524. * @since 15.0.0
  525. *
  526. * @param string $info
  527. * @param bool $default
  528. *
  529. * @return bool
  530. */
  531. public function getInfoBool(string $info, bool $default = false): bool;
  532. /**
  533. * Get all info.
  534. *
  535. * @since 15.0.0
  536. *
  537. * @return array
  538. */
  539. public function getInfoAll(): array;
  540. }