IIndexDocument.php 12 KB

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