Interface.php 11 KB

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