2
0

Interface.php 11 KB

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