Interface.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Search_Lucene
  17. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id$
  20. */
  21. /** Zend_Search_Lucene_Index_TermsStream_Interface */
  22. require_once 'Zend/Search/Lucene/Index/TermsStream/Interface.php';
  23. /** Classes used within Zend_Search_Lucene_Interface API */
  24. /** Zend_Search_Lucene_Document */
  25. require_once 'Zend/Search/Lucene/Document.php';
  26. /** Zend_Search_Lucene_Index_Term */
  27. require_once 'Zend/Search/Lucene/Index/Term.php';
  28. /** Zend_Search_Lucene_Index_DocsFilter */
  29. require_once 'Zend/Search/Lucene/Index/DocsFilter.php';
  30. /**
  31. * @category Zend
  32. * @package Zend_Search_Lucene
  33. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. */
  36. interface Zend_Search_Lucene_Interface extends Zend_Search_Lucene_Index_TermsStream_Interface
  37. {
  38. /**
  39. * Get current generation number
  40. *
  41. * Returns generation number
  42. * 0 means pre-2.1 index format
  43. * -1 means there are no segments files.
  44. *
  45. * @param Zend_Search_Lucene_Storage_Directory $directory
  46. * @return integer
  47. * @throws Zend_Search_Lucene_Exception
  48. */
  49. public static function getActualGeneration(Zend_Search_Lucene_Storage_Directory $directory);
  50. /**
  51. * Get segments file name
  52. *
  53. * @param integer $generation
  54. * @return string
  55. */
  56. public static function getSegmentFileName($generation);
  57. /**
  58. * Get index format version
  59. *
  60. * @return integer
  61. */
  62. public function getFormatVersion();
  63. /**
  64. * Set index format version.
  65. * Index is converted to this format at the nearest upfdate time
  66. *
  67. * @param int $formatVersion
  68. * @throws Zend_Search_Lucene_Exception
  69. */
  70. public function setFormatVersion($formatVersion);
  71. /**
  72. * Returns the Zend_Search_Lucene_Storage_Directory instance for this index.
  73. *
  74. * @return Zend_Search_Lucene_Storage_Directory
  75. */
  76. public function getDirectory();
  77. /**
  78. * Returns the total number of documents in this index (including deleted documents).
  79. *
  80. * @return integer
  81. */
  82. public function count();
  83. /**
  84. * Returns one greater than the largest possible document number.
  85. * This may be used to, e.g., determine how big to allocate a structure which will have
  86. * an element for every document number in an index.
  87. *
  88. * @return integer
  89. */
  90. public function maxDoc();
  91. /**
  92. * Returns the total number of non-deleted documents in this index.
  93. *
  94. * @return integer
  95. */
  96. public function numDocs();
  97. /**
  98. * Checks, that document is deleted
  99. *
  100. * @param integer $id
  101. * @return boolean
  102. * @throws Zend_Search_Lucene_Exception Exception is thrown if $id is out of the range
  103. */
  104. public function isDeleted($id);
  105. /**
  106. * Set default search field.
  107. *
  108. * Null means, that search is performed through all fields by default
  109. *
  110. * Default value is null
  111. *
  112. * @param string $fieldName
  113. */
  114. public static function setDefaultSearchField($fieldName);
  115. /**
  116. * Get default search field.
  117. *
  118. * Null means, that search is performed through all fields by default
  119. *
  120. * @return string
  121. */
  122. public static function getDefaultSearchField();
  123. /**
  124. * Set result set limit.
  125. *
  126. * 0 (default) means no limit
  127. *
  128. * @param integer $limit
  129. */
  130. public static function setResultSetLimit($limit);
  131. /**
  132. * Set result set limit.
  133. *
  134. * 0 means no limit
  135. *
  136. * @return integer
  137. */
  138. public static function getResultSetLimit();
  139. /**
  140. * Retrieve index maxBufferedDocs option
  141. *
  142. * maxBufferedDocs is a minimal number of documents required before
  143. * the buffered in-memory documents are written into a new Segment
  144. *
  145. * Default value is 10
  146. *
  147. * @return integer
  148. */
  149. public function getMaxBufferedDocs();
  150. /**
  151. * Set index maxBufferedDocs option
  152. *
  153. * maxBufferedDocs is a minimal number of documents required before
  154. * the buffered in-memory documents are written into a new Segment
  155. *
  156. * Default value is 10
  157. *
  158. * @param integer $maxBufferedDocs
  159. */
  160. public function setMaxBufferedDocs($maxBufferedDocs);
  161. /**
  162. * Retrieve index maxMergeDocs option
  163. *
  164. * maxMergeDocs is a largest number of documents ever merged by addDocument().
  165. * Small values (e.g., less than 10,000) are best for interactive indexing,
  166. * as this limits the length of pauses while indexing to a few seconds.
  167. * Larger values are best for batched indexing and speedier searches.
  168. *
  169. * Default value is PHP_INT_MAX
  170. *
  171. * @return integer
  172. */
  173. public function getMaxMergeDocs();
  174. /**
  175. * Set index maxMergeDocs option
  176. *
  177. * maxMergeDocs is a largest number of documents ever merged by addDocument().
  178. * Small values (e.g., less than 10,000) are best for interactive indexing,
  179. * as this limits the length of pauses while indexing to a few seconds.
  180. * Larger values are best for batched indexing and speedier searches.
  181. *
  182. * Default value is PHP_INT_MAX
  183. *
  184. * @param integer $maxMergeDocs
  185. */
  186. public function setMaxMergeDocs($maxMergeDocs);
  187. /**
  188. * Retrieve index mergeFactor option
  189. *
  190. * mergeFactor determines how often segment indices are merged by addDocument().
  191. * With smaller values, less RAM is used while indexing,
  192. * and searches on unoptimized indices are faster,
  193. * but indexing speed is slower.
  194. * With larger values, more RAM is used during indexing,
  195. * and while searches on unoptimized indices are slower,
  196. * indexing is faster.
  197. * Thus larger values (> 10) are best for batch index creation,
  198. * and smaller values (< 10) for indices that are interactively maintained.
  199. *
  200. * Default value is 10
  201. *
  202. * @return integer
  203. */
  204. public function getMergeFactor();
  205. /**
  206. * Set index mergeFactor option
  207. *
  208. * mergeFactor determines how often segment indices are merged by addDocument().
  209. * With smaller values, less RAM is used while indexing,
  210. * and searches on unoptimized indices are faster,
  211. * but indexing speed is slower.
  212. * With larger values, more RAM is used during indexing,
  213. * and while searches on unoptimized indices are slower,
  214. * indexing is faster.
  215. * Thus larger values (> 10) are best for batch index creation,
  216. * and smaller values (< 10) for indices that are interactively maintained.
  217. *
  218. * Default value is 10
  219. *
  220. * @param integer $maxMergeDocs
  221. */
  222. public function setMergeFactor($mergeFactor);
  223. /**
  224. * Performs a query against the index and returns an array
  225. * of Zend_Search_Lucene_Search_QueryHit objects.
  226. * Input is a string or Zend_Search_Lucene_Search_Query.
  227. *
  228. * @param mixed $query
  229. * @return array Zend_Search_Lucene_Search_QueryHit
  230. * @throws Zend_Search_Lucene_Exception
  231. */
  232. public function find($query);
  233. /**
  234. * Returns a list of all unique field names that exist in this index.
  235. *
  236. * @param boolean $indexed
  237. * @return array
  238. */
  239. public function getFieldNames($indexed = false);
  240. /**
  241. * Returns a Zend_Search_Lucene_Document object for the document
  242. * number $id in this index.
  243. *
  244. * @param integer|Zend_Search_Lucene_Search_QueryHit $id
  245. * @return Zend_Search_Lucene_Document
  246. */
  247. public function getDocument($id);
  248. /**
  249. * Returns true if index contain documents with specified term.
  250. *
  251. * Is used for query optimization.
  252. *
  253. * @param Zend_Search_Lucene_Index_Term $term
  254. * @return boolean
  255. */
  256. public function hasTerm(Zend_Search_Lucene_Index_Term $term);
  257. /**
  258. * Returns IDs of all the documents containing term.
  259. *
  260. * @param Zend_Search_Lucene_Index_Term $term
  261. * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
  262. * @return array
  263. */
  264. public function termDocs(Zend_Search_Lucene_Index_Term $term, $docsFilter = null);
  265. /**
  266. * Returns documents filter for all documents containing term.
  267. *
  268. * It performs the same operation as termDocs, but return result as
  269. * Zend_Search_Lucene_Index_DocsFilter object
  270. *
  271. * @param Zend_Search_Lucene_Index_Term $term
  272. * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
  273. * @return Zend_Search_Lucene_Index_DocsFilter
  274. */
  275. public function termDocsFilter(Zend_Search_Lucene_Index_Term $term, $docsFilter = null);
  276. /**
  277. * Returns an array of all term freqs.
  278. * Return array structure: array( docId => freq, ...)
  279. *
  280. * @param Zend_Search_Lucene_Index_Term $term
  281. * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
  282. * @return integer
  283. */
  284. public function termFreqs(Zend_Search_Lucene_Index_Term $term, $docsFilter = null);
  285. /**
  286. * Returns an array of all term positions in the documents.
  287. * Return array structure: array( docId => array( pos1, pos2, ...), ...)
  288. *
  289. * @param Zend_Search_Lucene_Index_Term $term
  290. * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
  291. * @return array
  292. */
  293. public function termPositions(Zend_Search_Lucene_Index_Term $term, $docsFilter = null);
  294. /**
  295. * Returns the number of documents in this index containing the $term.
  296. *
  297. * @param Zend_Search_Lucene_Index_Term $term
  298. * @return integer
  299. */
  300. public function docFreq(Zend_Search_Lucene_Index_Term $term);
  301. /**
  302. * Retrive similarity used by index reader
  303. *
  304. * @return Zend_Search_Lucene_Search_Similarity
  305. */
  306. public function getSimilarity();
  307. /**
  308. * Returns a normalization factor for "field, document" pair.
  309. *
  310. * @param integer $id
  311. * @param string $fieldName
  312. * @return float
  313. */
  314. public function norm($id, $fieldName);
  315. /**
  316. * Returns true if any documents have been deleted from this index.
  317. *
  318. * @return boolean
  319. */
  320. public function hasDeletions();
  321. /**
  322. * Deletes a document from the index.
  323. * $id is an internal document id
  324. *
  325. * @param integer|Zend_Search_Lucene_Search_QueryHit $id
  326. * @throws Zend_Search_Lucene_Exception
  327. */
  328. public function delete($id);
  329. /**
  330. * Adds a document to this index.
  331. *
  332. * @param Zend_Search_Lucene_Document $document
  333. */
  334. public function addDocument(Zend_Search_Lucene_Document $document);
  335. /**
  336. * Commit changes resulting from delete() or undeleteAll() operations.
  337. */
  338. public function commit();
  339. /**
  340. * Optimize index.
  341. *
  342. * Merges all segments into one
  343. */
  344. public function optimize();
  345. /**
  346. * Returns an array of all terms in this index.
  347. *
  348. * @return array
  349. */
  350. public function terms();
  351. /**
  352. * Undeletes all documents currently marked as deleted in this index.
  353. */
  354. public function undeleteAll();
  355. /**
  356. * Add reference to the index object
  357. *
  358. * @internal
  359. */
  360. public function addReference();
  361. /**
  362. * Remove reference from the index object
  363. *
  364. * When reference count becomes zero, index is closed and resources are cleaned up
  365. *
  366. * @internal
  367. */
  368. public function removeReference();
  369. }