Lucene.php 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521
  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_Document */
  21. require_once 'Zend/Search/Lucene/Document.php';
  22. /** Zend_Search_Lucene_Document_Html */
  23. require_once 'Zend/Search/Lucene/Document/Html.php';
  24. /** Zend_Search_Lucene_Document_Docx */
  25. require_once 'Zend/Search/Lucene/Document/Docx.php';
  26. /** Zend_Search_Lucene_Document_Pptx */
  27. require_once 'Zend/Search/Lucene/Document/Pptx.php';
  28. /** Zend_Search_Lucene_Document_Xlsx */
  29. require_once 'Zend/Search/Lucene/Document/Xlsx.php';
  30. /** Zend_Search_Lucene_Storage_Directory_Filesystem */
  31. require_once 'Zend/Search/Lucene/Storage/Directory/Filesystem.php';
  32. /** Zend_Search_Lucene_Storage_File_Memory */
  33. require_once 'Zend/Search/Lucene/Storage/File/Memory.php';
  34. /** Zend_Search_Lucene_Index_Term */
  35. require_once 'Zend/Search/Lucene/Index/Term.php';
  36. /** Zend_Search_Lucene_Index_TermInfo */
  37. require_once 'Zend/Search/Lucene/Index/TermInfo.php';
  38. /** Zend_Search_Lucene_Index_SegmentInfo */
  39. require_once 'Zend/Search/Lucene/Index/SegmentInfo.php';
  40. /** Zend_Search_Lucene_Index_FieldInfo */
  41. require_once 'Zend/Search/Lucene/Index/FieldInfo.php';
  42. /** Zend_Search_Lucene_Index_Writer */
  43. require_once 'Zend/Search/Lucene/Index/Writer.php';
  44. /** Zend_Search_Lucene_Search_QueryParser */
  45. require_once 'Zend/Search/Lucene/Search/QueryParser.php';
  46. /** Zend_Search_Lucene_Search_QueryHit */
  47. require_once 'Zend/Search/Lucene/Search/QueryHit.php';
  48. /** Zend_Search_Lucene_Search_Similarity */
  49. require_once 'Zend/Search/Lucene/Search/Similarity.php';
  50. /** Zend_Search_Lucene_Index_TermsPriorityQueue */
  51. require_once 'Zend/Search/Lucene/Index/TermsPriorityQueue.php';
  52. /** Zend_Search_Lucene_TermStreamsPriorityQueue */
  53. require_once 'Zend/Search/Lucene/TermStreamsPriorityQueue.php';
  54. /** Zend_Search_Lucene_Index_DocsFilter */
  55. require_once 'Zend/Search/Lucene/Index/DocsFilter.php';
  56. /** Zend_Search_Lucene_LockManager */
  57. require_once 'Zend/Search/Lucene/LockManager.php';
  58. /** Zend_Search_Lucene_Interface */
  59. require_once 'Zend/Search/Lucene/Interface.php';
  60. /** Zend_Search_Lucene_Proxy */
  61. require_once 'Zend/Search/Lucene/Proxy.php';
  62. /**
  63. * @category Zend
  64. * @package Zend_Search_Lucene
  65. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  66. * @license http://framework.zend.com/license/new-bsd New BSD License
  67. */
  68. class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
  69. {
  70. /**
  71. * Default field name for search
  72. *
  73. * Null means search through all fields
  74. *
  75. * @var string
  76. */
  77. private static $_defaultSearchField = null;
  78. /**
  79. * Result set limit
  80. *
  81. * 0 means no limit
  82. *
  83. * @var integer
  84. */
  85. private static $_resultSetLimit = 0;
  86. /**
  87. * Terms per query limit
  88. *
  89. * 0 means no limit
  90. *
  91. * @var integer
  92. */
  93. private static $_termsPerQueryLimit = 1024;
  94. /**
  95. * File system adapter.
  96. *
  97. * @var Zend_Search_Lucene_Storage_Directory
  98. */
  99. private $_directory = null;
  100. /**
  101. * File system adapter closing option
  102. *
  103. * @var boolean
  104. */
  105. private $_closeDirOnExit = true;
  106. /**
  107. * Writer for this index, not instantiated unless required.
  108. *
  109. * @var Zend_Search_Lucene_Index_Writer
  110. */
  111. private $_writer = null;
  112. /**
  113. * Array of Zend_Search_Lucene_Index_SegmentInfo objects for this index.
  114. *
  115. * @var array Zend_Search_Lucene_Index_SegmentInfo
  116. */
  117. private $_segmentInfos = array();
  118. /**
  119. * Number of documents in this index.
  120. *
  121. * @var integer
  122. */
  123. private $_docCount = 0;
  124. /**
  125. * Flag for index changes
  126. *
  127. * @var boolean
  128. */
  129. private $_hasChanges = false;
  130. /**
  131. * Signal, that index is already closed, changes are fixed and resources are cleaned up
  132. *
  133. * @var boolean
  134. */
  135. private $_closed = false;
  136. /**
  137. * Number of references to the index object
  138. *
  139. * @var integer
  140. */
  141. private $_refCount = 0;
  142. /**
  143. * Current segment generation
  144. *
  145. * @var integer
  146. */
  147. private $_generation;
  148. const FORMAT_PRE_2_1 = 0;
  149. const FORMAT_2_1 = 1;
  150. const FORMAT_2_3 = 2;
  151. /**
  152. * Index format version
  153. *
  154. * @var integer
  155. */
  156. private $_formatVersion;
  157. /**
  158. * Create index
  159. *
  160. * @param mixed $directory
  161. * @return Zend_Search_Lucene_Interface
  162. */
  163. public static function create($directory)
  164. {
  165. return new Zend_Search_Lucene_Proxy(new Zend_Search_Lucene($directory, true));
  166. }
  167. /**
  168. * Open index
  169. *
  170. * @param mixed $directory
  171. * @return Zend_Search_Lucene_Interface
  172. */
  173. public static function open($directory)
  174. {
  175. return new Zend_Search_Lucene_Proxy(new Zend_Search_Lucene($directory, false));
  176. }
  177. /** Generation retrieving counter */
  178. const GENERATION_RETRIEVE_COUNT = 10;
  179. /** Pause between generation retrieving attempts in milliseconds */
  180. const GENERATION_RETRIEVE_PAUSE = 50;
  181. /**
  182. * Get current generation number
  183. *
  184. * Returns generation number
  185. * 0 means pre-2.1 index format
  186. * -1 means there are no segments files.
  187. *
  188. * @param Zend_Search_Lucene_Storage_Directory $directory
  189. * @return integer
  190. * @throws Zend_Search_Lucene_Exception
  191. */
  192. public static function getActualGeneration(Zend_Search_Lucene_Storage_Directory $directory)
  193. {
  194. /**
  195. * Zend_Search_Lucene uses segments.gen file to retrieve current generation number
  196. *
  197. * Apache Lucene index format documentation mentions this method only as a fallback method
  198. *
  199. * Nevertheless we use it according to the performance considerations
  200. *
  201. * @todo check if we can use some modification of Apache Lucene generation determination algorithm
  202. * without performance problems
  203. */
  204. require_once 'Zend/Search/Lucene/Exception.php';
  205. try {
  206. for ($count = 0; $count < self::GENERATION_RETRIEVE_COUNT; $count++) {
  207. // Try to get generation file
  208. $genFile = $directory->getFileObject('segments.gen', false);
  209. $format = $genFile->readInt();
  210. if ($format != (int)0xFFFFFFFE) {
  211. throw new Zend_Search_Lucene_Exception('Wrong segments.gen file format');
  212. }
  213. $gen1 = $genFile->readLong();
  214. $gen2 = $genFile->readLong();
  215. if ($gen1 == $gen2) {
  216. return $gen1;
  217. }
  218. usleep(self::GENERATION_RETRIEVE_PAUSE * 1000);
  219. }
  220. // All passes are failed
  221. throw new Zend_Search_Lucene_Exception('Index is under processing now');
  222. } catch (Zend_Search_Lucene_Exception $e) {
  223. if (strpos($e->getMessage(), 'is not readable') !== false) {
  224. try {
  225. // Try to open old style segments file
  226. $segmentsFile = $directory->getFileObject('segments', false);
  227. // It's pre-2.1 index
  228. return 0;
  229. } catch (Zend_Search_Lucene_Exception $e) {
  230. if (strpos($e->getMessage(), 'is not readable') !== false) {
  231. return -1;
  232. } else {
  233. throw $e;
  234. }
  235. }
  236. } else {
  237. throw $e;
  238. }
  239. }
  240. return -1;
  241. }
  242. /**
  243. * Get segments file name
  244. *
  245. * @param integer $generation
  246. * @return string
  247. */
  248. public static function getSegmentFileName($generation)
  249. {
  250. if ($generation == 0) {
  251. return 'segments';
  252. }
  253. return 'segments_' . base_convert($generation, 10, 36);
  254. }
  255. /**
  256. * Get index format version
  257. *
  258. * @return integer
  259. */
  260. public function getFormatVersion()
  261. {
  262. return $this->_formatVersion;
  263. }
  264. /**
  265. * Set index format version.
  266. * Index is converted to this format at the nearest upfdate time
  267. *
  268. * @param int $formatVersion
  269. * @throws Zend_Search_Lucene_Exception
  270. */
  271. public function setFormatVersion($formatVersion)
  272. {
  273. if ($formatVersion != self::FORMAT_PRE_2_1 &&
  274. $formatVersion != self::FORMAT_2_1 &&
  275. $formatVersion != self::FORMAT_2_3) {
  276. require_once 'Zend/Search/Lucene/Exception.php';
  277. throw new Zend_Search_Lucene_Exception('Unsupported index format');
  278. }
  279. $this->_formatVersion = $formatVersion;
  280. }
  281. /**
  282. * Read segments file for pre-2.1 Lucene index format
  283. *
  284. * @throws Zend_Search_Lucene_Exception
  285. */
  286. private function _readPre21SegmentsFile()
  287. {
  288. $segmentsFile = $this->_directory->getFileObject('segments');
  289. $format = $segmentsFile->readInt();
  290. if ($format != (int)0xFFFFFFFF) {
  291. require_once 'Zend/Search/Lucene/Exception.php';
  292. throw new Zend_Search_Lucene_Exception('Wrong segments file format');
  293. }
  294. // read version
  295. // $segmentsFile->readLong();
  296. $segmentsFile->readInt(); $segmentsFile->readInt();
  297. // read segment name counter
  298. $segmentsFile->readInt();
  299. $segments = $segmentsFile->readInt();
  300. $this->_docCount = 0;
  301. // read segmentInfos
  302. for ($count = 0; $count < $segments; $count++) {
  303. $segName = $segmentsFile->readString();
  304. $segSize = $segmentsFile->readInt();
  305. $this->_docCount += $segSize;
  306. $this->_segmentInfos[$segName] =
  307. new Zend_Search_Lucene_Index_SegmentInfo($this->_directory,
  308. $segName,
  309. $segSize);
  310. }
  311. // Use 2.1 as a target version. Index will be reorganized at update time.
  312. $this->_formatVersion = self::FORMAT_2_1;
  313. }
  314. /**
  315. * Read segments file
  316. *
  317. * @throws Zend_Search_Lucene_Exception
  318. */
  319. private function _readSegmentsFile()
  320. {
  321. $segmentsFile = $this->_directory->getFileObject(self::getSegmentFileName($this->_generation));
  322. $format = $segmentsFile->readInt();
  323. if ($format == (int)0xFFFFFFFC) {
  324. $this->_formatVersion = self::FORMAT_2_3;
  325. } else if ($format == (int)0xFFFFFFFD) {
  326. $this->_formatVersion = self::FORMAT_2_1;
  327. } else {
  328. require_once 'Zend/Search/Lucene/Exception.php';
  329. throw new Zend_Search_Lucene_Exception('Unsupported segments file format');
  330. }
  331. // read version
  332. // $segmentsFile->readLong();
  333. $segmentsFile->readInt(); $segmentsFile->readInt();
  334. // read segment name counter
  335. $segmentsFile->readInt();
  336. $segments = $segmentsFile->readInt();
  337. $this->_docCount = 0;
  338. // read segmentInfos
  339. for ($count = 0; $count < $segments; $count++) {
  340. $segName = $segmentsFile->readString();
  341. $segSize = $segmentsFile->readInt();
  342. // 2.1+ specific properties
  343. //$delGen = $segmentsFile->readLong();
  344. $delGenHigh = $segmentsFile->readInt();
  345. $delGenLow = $segmentsFile->readInt();
  346. if ($delGenHigh == (int)0xFFFFFFFF && $delGenLow == (int)0xFFFFFFFF) {
  347. $delGen = -1; // There are no deletes
  348. } else {
  349. $delGen = ($delGenHigh << 32) | $delGenLow;
  350. }
  351. if ($this->_formatVersion == self::FORMAT_2_3) {
  352. $docStoreOffset = $segmentsFile->readInt();
  353. if ($docStoreOffset != -1) {
  354. $docStoreSegment = $segmentsFile->readString();
  355. $docStoreIsCompoundFile = $segmentsFile->readByte();
  356. $docStoreOptions = array('offset' => $docStoreOffset,
  357. 'segment' => $docStoreSegment,
  358. 'isCompound' => ($docStoreIsCompoundFile == 1));
  359. } else {
  360. $docStoreOptions = null;
  361. }
  362. } else {
  363. $docStoreOptions = null;
  364. }
  365. $hasSingleNormFile = $segmentsFile->readByte();
  366. $numField = $segmentsFile->readInt();
  367. $normGens = array();
  368. if ($numField != (int)0xFFFFFFFF) {
  369. for ($count1 = 0; $count1 < $numField; $count1++) {
  370. $normGens[] = $segmentsFile->readLong();
  371. }
  372. require_once 'Zend/Search/Lucene/Exception.php';
  373. throw new Zend_Search_Lucene_Exception('Separate norm files are not supported. Optimize index to use it with Zend_Search_Lucene.');
  374. }
  375. $isCompoundByte = $segmentsFile->readByte();
  376. if ($isCompoundByte == 0xFF) {
  377. // The segment is not a compound file
  378. $isCompound = false;
  379. } else if ($isCompoundByte == 0x00) {
  380. // The status is unknown
  381. $isCompound = null;
  382. } else if ($isCompoundByte == 0x01) {
  383. // The segment is a compound file
  384. $isCompound = true;
  385. }
  386. $this->_docCount += $segSize;
  387. $this->_segmentInfos[$segName] =
  388. new Zend_Search_Lucene_Index_SegmentInfo($this->_directory,
  389. $segName,
  390. $segSize,
  391. $delGen,
  392. $docStoreOptions,
  393. $hasSingleNormFile,
  394. $isCompound);
  395. }
  396. }
  397. /**
  398. * Opens the index.
  399. *
  400. * IndexReader constructor needs Directory as a parameter. It should be
  401. * a string with a path to the index folder or a Directory object.
  402. *
  403. * @param mixed $directory
  404. * @throws Zend_Search_Lucene_Exception
  405. */
  406. public function __construct($directory = null, $create = false)
  407. {
  408. if ($directory === null) {
  409. require_once 'Zend/Search/Lucene/Exception.php';
  410. throw new Zend_Search_Exception('No index directory specified');
  411. }
  412. if ($directory instanceof Zend_Search_Lucene_Storage_Directory_Filesystem) {
  413. $this->_directory = $directory;
  414. $this->_closeDirOnExit = false;
  415. } else {
  416. $this->_directory = new Zend_Search_Lucene_Storage_Directory_Filesystem($directory);
  417. $this->_closeDirOnExit = true;
  418. }
  419. $this->_segmentInfos = array();
  420. // Mark index as "under processing" to prevent other processes from premature index cleaning
  421. Zend_Search_Lucene_LockManager::obtainReadLock($this->_directory);
  422. $this->_generation = self::getActualGeneration($this->_directory);
  423. if ($create) {
  424. require_once 'Zend/Search/Lucene/Exception.php';
  425. try {
  426. Zend_Search_Lucene_LockManager::obtainWriteLock($this->_directory);
  427. } catch (Zend_Search_Lucene_Exception $e) {
  428. Zend_Search_Lucene_LockManager::releaseReadLock($this->_directory);
  429. if (strpos($e->getMessage(), 'Can\'t obtain exclusive index lock') === false) {
  430. throw $e;
  431. } else {
  432. throw new Zend_Search_Lucene_Exception('Can\'t create index. It\'s under processing now');
  433. }
  434. }
  435. if ($this->_generation == -1) {
  436. // Directory doesn't contain existing index, start from 1
  437. $this->_generation = 1;
  438. $nameCounter = 0;
  439. } else {
  440. // Directory contains existing index
  441. $segmentsFile = $this->_directory->getFileObject(self::getSegmentFileName($this->_generation));
  442. $segmentsFile->seek(12); // 12 = 4 (int, file format marker) + 8 (long, index version)
  443. $nameCounter = $segmentsFile->readInt();
  444. $this->_generation++;
  445. }
  446. Zend_Search_Lucene_Index_Writer::createIndex($this->_directory, $this->_generation, $nameCounter);
  447. Zend_Search_Lucene_LockManager::releaseWriteLock($this->_directory);
  448. }
  449. if ($this->_generation == -1) {
  450. require_once 'Zend/Search/Lucene/Exception.php';
  451. throw new Zend_Search_Lucene_Exception('Index doesn\'t exists in the specified directory.');
  452. } else if ($this->_generation == 0) {
  453. $this->_readPre21SegmentsFile();
  454. } else {
  455. $this->_readSegmentsFile();
  456. }
  457. }
  458. /**
  459. * Close current index and free resources
  460. */
  461. private function _close()
  462. {
  463. if ($this->_closed) {
  464. // index is already closed and resources are cleaned up
  465. return;
  466. }
  467. $this->commit();
  468. // Release "under processing" flag
  469. Zend_Search_Lucene_LockManager::releaseReadLock($this->_directory);
  470. if ($this->_closeDirOnExit) {
  471. $this->_directory->close();
  472. }
  473. $this->_directory = null;
  474. $this->_writer = null;
  475. $this->_segmentInfos = null;
  476. $this->_closed = true;
  477. }
  478. /**
  479. * Add reference to the index object
  480. *
  481. * @internal
  482. */
  483. public function addReference()
  484. {
  485. $this->_refCount++;
  486. }
  487. /**
  488. * Remove reference from the index object
  489. *
  490. * When reference count becomes zero, index is closed and resources are cleaned up
  491. *
  492. * @internal
  493. */
  494. public function removeReference()
  495. {
  496. $this->_refCount--;
  497. if ($this->_refCount == 0) {
  498. $this->_close();
  499. }
  500. }
  501. /**
  502. * Object destructor
  503. */
  504. public function __destruct()
  505. {
  506. $this->_close();
  507. }
  508. /**
  509. * Returns an instance of Zend_Search_Lucene_Index_Writer for the index
  510. *
  511. * @return Zend_Search_Lucene_Index_Writer
  512. */
  513. private function _getIndexWriter()
  514. {
  515. if (!$this->_writer instanceof Zend_Search_Lucene_Index_Writer) {
  516. $this->_writer = new Zend_Search_Lucene_Index_Writer($this->_directory, $this->_segmentInfos, $this->_formatVersion);
  517. }
  518. return $this->_writer;
  519. }
  520. /**
  521. * Returns the Zend_Search_Lucene_Storage_Directory instance for this index.
  522. *
  523. * @return Zend_Search_Lucene_Storage_Directory
  524. */
  525. public function getDirectory()
  526. {
  527. return $this->_directory;
  528. }
  529. /**
  530. * Returns the total number of documents in this index (including deleted documents).
  531. *
  532. * @return integer
  533. */
  534. public function count()
  535. {
  536. return $this->_docCount;
  537. }
  538. /**
  539. * Returns one greater than the largest possible document number.
  540. * This may be used to, e.g., determine how big to allocate a structure which will have
  541. * an element for every document number in an index.
  542. *
  543. * @return integer
  544. */
  545. public function maxDoc()
  546. {
  547. return $this->count();
  548. }
  549. /**
  550. * Returns the total number of non-deleted documents in this index.
  551. *
  552. * @return integer
  553. */
  554. public function numDocs()
  555. {
  556. $numDocs = 0;
  557. foreach ($this->_segmentInfos as $segmentInfo) {
  558. $numDocs += $segmentInfo->numDocs();
  559. }
  560. return $numDocs;
  561. }
  562. /**
  563. * Checks, that document is deleted
  564. *
  565. * @param integer $id
  566. * @return boolean
  567. * @throws Zend_Search_Lucene_Exception Exception is thrown if $id is out of the range
  568. */
  569. public function isDeleted($id)
  570. {
  571. if ($id >= $this->_docCount) {
  572. require_once 'Zend/Search/Lucene/Exception.php';
  573. throw new Zend_Search_Lucene_Exception('Document id is out of the range.');
  574. }
  575. $segmentStartId = 0;
  576. foreach ($this->_segmentInfos as $segmentInfo) {
  577. if ($segmentStartId + $segmentInfo->count() > $id) {
  578. break;
  579. }
  580. $segmentStartId += $segmentInfo->count();
  581. }
  582. return $segmentInfo->isDeleted($id - $segmentStartId);
  583. }
  584. /**
  585. * Set default search field.
  586. *
  587. * Null means, that search is performed through all fields by default
  588. *
  589. * Default value is null
  590. *
  591. * @param string $fieldName
  592. */
  593. public static function setDefaultSearchField($fieldName)
  594. {
  595. self::$_defaultSearchField = $fieldName;
  596. }
  597. /**
  598. * Get default search field.
  599. *
  600. * Null means, that search is performed through all fields by default
  601. *
  602. * @return string
  603. */
  604. public static function getDefaultSearchField()
  605. {
  606. return self::$_defaultSearchField;
  607. }
  608. /**
  609. * Set result set limit.
  610. *
  611. * 0 (default) means no limit
  612. *
  613. * @param integer $limit
  614. */
  615. public static function setResultSetLimit($limit)
  616. {
  617. self::$_resultSetLimit = $limit;
  618. }
  619. /**
  620. * Get result set limit.
  621. *
  622. * 0 means no limit
  623. *
  624. * @return integer
  625. */
  626. public static function getResultSetLimit()
  627. {
  628. return self::$_resultSetLimit;
  629. }
  630. /**
  631. * Set terms per query limit.
  632. *
  633. * 0 means no limit
  634. *
  635. * @param integer $limit
  636. */
  637. public static function setTermsPerQueryLimit($limit)
  638. {
  639. self::$_termsPerQueryLimit = $limit;
  640. }
  641. /**
  642. * Get result set limit.
  643. *
  644. * 0 (default) means no limit
  645. *
  646. * @return integer
  647. */
  648. public static function getTermsPerQueryLimit()
  649. {
  650. return self::$_termsPerQueryLimit;
  651. }
  652. /**
  653. * Retrieve index maxBufferedDocs option
  654. *
  655. * maxBufferedDocs is a minimal number of documents required before
  656. * the buffered in-memory documents are written into a new Segment
  657. *
  658. * Default value is 10
  659. *
  660. * @return integer
  661. */
  662. public function getMaxBufferedDocs()
  663. {
  664. return $this->_getIndexWriter()->maxBufferedDocs;
  665. }
  666. /**
  667. * Set index maxBufferedDocs option
  668. *
  669. * maxBufferedDocs is a minimal number of documents required before
  670. * the buffered in-memory documents are written into a new Segment
  671. *
  672. * Default value is 10
  673. *
  674. * @param integer $maxBufferedDocs
  675. */
  676. public function setMaxBufferedDocs($maxBufferedDocs)
  677. {
  678. $this->_getIndexWriter()->maxBufferedDocs = $maxBufferedDocs;
  679. }
  680. /**
  681. * Retrieve index maxMergeDocs option
  682. *
  683. * maxMergeDocs is a largest number of documents ever merged by addDocument().
  684. * Small values (e.g., less than 10,000) are best for interactive indexing,
  685. * as this limits the length of pauses while indexing to a few seconds.
  686. * Larger values are best for batched indexing and speedier searches.
  687. *
  688. * Default value is PHP_INT_MAX
  689. *
  690. * @return integer
  691. */
  692. public function getMaxMergeDocs()
  693. {
  694. return $this->_getIndexWriter()->maxMergeDocs;
  695. }
  696. /**
  697. * Set index maxMergeDocs option
  698. *
  699. * maxMergeDocs is a largest number of documents ever merged by addDocument().
  700. * Small values (e.g., less than 10,000) are best for interactive indexing,
  701. * as this limits the length of pauses while indexing to a few seconds.
  702. * Larger values are best for batched indexing and speedier searches.
  703. *
  704. * Default value is PHP_INT_MAX
  705. *
  706. * @param integer $maxMergeDocs
  707. */
  708. public function setMaxMergeDocs($maxMergeDocs)
  709. {
  710. $this->_getIndexWriter()->maxMergeDocs = $maxMergeDocs;
  711. }
  712. /**
  713. * Retrieve index mergeFactor option
  714. *
  715. * mergeFactor determines how often segment indices are merged by addDocument().
  716. * With smaller values, less RAM is used while indexing,
  717. * and searches on unoptimized indices are faster,
  718. * but indexing speed is slower.
  719. * With larger values, more RAM is used during indexing,
  720. * and while searches on unoptimized indices are slower,
  721. * indexing is faster.
  722. * Thus larger values (> 10) are best for batch index creation,
  723. * and smaller values (< 10) for indices that are interactively maintained.
  724. *
  725. * Default value is 10
  726. *
  727. * @return integer
  728. */
  729. public function getMergeFactor()
  730. {
  731. return $this->_getIndexWriter()->mergeFactor;
  732. }
  733. /**
  734. * Set index mergeFactor option
  735. *
  736. * mergeFactor determines how often segment indices are merged by addDocument().
  737. * With smaller values, less RAM is used while indexing,
  738. * and searches on unoptimized indices are faster,
  739. * but indexing speed is slower.
  740. * With larger values, more RAM is used during indexing,
  741. * and while searches on unoptimized indices are slower,
  742. * indexing is faster.
  743. * Thus larger values (> 10) are best for batch index creation,
  744. * and smaller values (< 10) for indices that are interactively maintained.
  745. *
  746. * Default value is 10
  747. *
  748. * @param integer $maxMergeDocs
  749. */
  750. public function setMergeFactor($mergeFactor)
  751. {
  752. $this->_getIndexWriter()->mergeFactor = $mergeFactor;
  753. }
  754. /**
  755. * Performs a query against the index and returns an array
  756. * of Zend_Search_Lucene_Search_QueryHit objects.
  757. * Input is a string or Zend_Search_Lucene_Search_Query.
  758. *
  759. * @param mixed $query
  760. * @return array Zend_Search_Lucene_Search_QueryHit
  761. * @throws Zend_Search_Lucene_Exception
  762. */
  763. public function find($query)
  764. {
  765. if (is_string($query)) {
  766. $query = Zend_Search_Lucene_Search_QueryParser::parse($query);
  767. }
  768. if (!$query instanceof Zend_Search_Lucene_Search_Query) {
  769. require_once 'Zend/Search/Lucene/Exception.php';
  770. throw new Zend_Search_Lucene_Exception('Query must be a string or Zend_Search_Lucene_Search_Query object');
  771. }
  772. $this->commit();
  773. $hits = array();
  774. $scores = array();
  775. $ids = array();
  776. $query = $query->rewrite($this)->optimize($this);
  777. $query->execute($this);
  778. $topScore = 0;
  779. foreach ($query->matchedDocs() as $id => $num) {
  780. $docScore = $query->score($id, $this);
  781. if( $docScore != 0 ) {
  782. $hit = new Zend_Search_Lucene_Search_QueryHit($this);
  783. $hit->id = $id;
  784. $hit->score = $docScore;
  785. $hits[] = $hit;
  786. $ids[] = $id;
  787. $scores[] = $docScore;
  788. if ($docScore > $topScore) {
  789. $topScore = $docScore;
  790. }
  791. }
  792. if (self::$_resultSetLimit != 0 && count($hits) >= self::$_resultSetLimit) {
  793. break;
  794. }
  795. }
  796. if (count($hits) == 0) {
  797. // skip sorting, which may cause a error on empty index
  798. return array();
  799. }
  800. if ($topScore > 1) {
  801. foreach ($hits as $hit) {
  802. $hit->score /= $topScore;
  803. }
  804. }
  805. if (func_num_args() == 1) {
  806. // sort by scores
  807. array_multisort($scores, SORT_DESC, SORT_NUMERIC,
  808. $ids, SORT_ASC, SORT_NUMERIC,
  809. $hits);
  810. } else {
  811. // sort by given field names
  812. $argList = func_get_args();
  813. $fieldNames = $this->getFieldNames();
  814. $sortArgs = array();
  815. require_once 'Zend/Search/Lucene/Exception.php';
  816. for ($count = 1; $count < count($argList); $count++) {
  817. $fieldName = $argList[$count];
  818. if (!is_string($fieldName)) {
  819. throw new Zend_Search_Lucene_Exception('Field name must be a string.');
  820. }
  821. if (!in_array($fieldName, $fieldNames)) {
  822. throw new Zend_Search_Lucene_Exception('Wrong field name.');
  823. }
  824. $valuesArray = array();
  825. foreach ($hits as $hit) {
  826. try {
  827. $value = $hit->getDocument()->getFieldValue($fieldName);
  828. } catch (Zend_Search_Lucene_Exception $e) {
  829. if (strpos($e->getMessage(), 'not found') === false) {
  830. throw $e;
  831. } else {
  832. $value = null;
  833. }
  834. }
  835. $valuesArray[] = $value;
  836. }
  837. $sortArgs[] = $valuesArray;
  838. if ($count + 1 < count($argList) && is_integer($argList[$count+1])) {
  839. $count++;
  840. $sortArgs[] = $argList[$count];
  841. if ($count + 1 < count($argList) && is_integer($argList[$count+1])) {
  842. $count++;
  843. $sortArgs[] = $argList[$count];
  844. } else {
  845. if ($argList[$count] == SORT_ASC || $argList[$count] == SORT_DESC) {
  846. $sortArgs[] = SORT_REGULAR;
  847. } else {
  848. $sortArgs[] = SORT_ASC;
  849. }
  850. }
  851. } else {
  852. $sortArgs[] = SORT_ASC;
  853. $sortArgs[] = SORT_REGULAR;
  854. }
  855. }
  856. // Sort by id's if values are equal
  857. $sortArgs[] = $ids;
  858. $sortArgs[] = SORT_ASC;
  859. $sortArgs[] = SORT_NUMERIC;
  860. // Array to be sorted
  861. $sortArgs[] = &$hits;
  862. // Do sort
  863. call_user_func_array('array_multisort', $sortArgs);
  864. }
  865. return $hits;
  866. }
  867. /**
  868. * Returns a list of all unique field names that exist in this index.
  869. *
  870. * @param boolean $indexed
  871. * @return array
  872. */
  873. public function getFieldNames($indexed = false)
  874. {
  875. $result = array();
  876. foreach( $this->_segmentInfos as $segmentInfo ) {
  877. $result = array_merge($result, $segmentInfo->getFields($indexed));
  878. }
  879. return $result;
  880. }
  881. /**
  882. * Returns a Zend_Search_Lucene_Document object for the document
  883. * number $id in this index.
  884. *
  885. * @param integer|Zend_Search_Lucene_Search_QueryHit $id
  886. * @return Zend_Search_Lucene_Document
  887. * @throws Zend_Search_Lucene_Exception Exception is thrown if $id is out of the range
  888. */
  889. public function getDocument($id)
  890. {
  891. if ($id instanceof Zend_Search_Lucene_Search_QueryHit) {
  892. /* @var $id Zend_Search_Lucene_Search_QueryHit */
  893. $id = $id->id;
  894. }
  895. if ($id >= $this->_docCount) {
  896. require_once 'Zend/Search/Lucene/Exception.php';
  897. throw new Zend_Search_Lucene_Exception('Document id is out of the range.');
  898. }
  899. $segmentStartId = 0;
  900. foreach ($this->_segmentInfos as $segmentInfo) {
  901. if ($segmentStartId + $segmentInfo->count() > $id) {
  902. break;
  903. }
  904. $segmentStartId += $segmentInfo->count();
  905. }
  906. $fdxFile = $segmentInfo->openCompoundFile('.fdx');
  907. $fdxFile->seek(($id-$segmentStartId)*8, SEEK_CUR);
  908. $fieldValuesPosition = $fdxFile->readLong();
  909. $fdtFile = $segmentInfo->openCompoundFile('.fdt');
  910. $fdtFile->seek($fieldValuesPosition, SEEK_CUR);
  911. $fieldCount = $fdtFile->readVInt();
  912. $doc = new Zend_Search_Lucene_Document();
  913. for ($count = 0; $count < $fieldCount; $count++) {
  914. $fieldNum = $fdtFile->readVInt();
  915. $bits = $fdtFile->readByte();
  916. $fieldInfo = $segmentInfo->getField($fieldNum);
  917. if (!($bits & 2)) { // Text data
  918. $field = new Zend_Search_Lucene_Field($fieldInfo->name,
  919. $fdtFile->readString(),
  920. 'UTF-8',
  921. true,
  922. $fieldInfo->isIndexed,
  923. $bits & 1 );
  924. } else { // Binary data
  925. $field = new Zend_Search_Lucene_Field($fieldInfo->name,
  926. $fdtFile->readBinary(),
  927. '',
  928. true,
  929. $fieldInfo->isIndexed,
  930. $bits & 1,
  931. true );
  932. }
  933. $doc->addField($field);
  934. }
  935. return $doc;
  936. }
  937. /**
  938. * Returns true if index contain documents with specified term.
  939. *
  940. * Is used for query optimization.
  941. *
  942. * @param Zend_Search_Lucene_Index_Term $term
  943. * @return boolean
  944. */
  945. public function hasTerm(Zend_Search_Lucene_Index_Term $term)
  946. {
  947. foreach ($this->_segmentInfos as $segInfo) {
  948. if ($segInfo->getTermInfo($term) instanceof Zend_Search_Lucene_Index_TermInfo) {
  949. return true;
  950. }
  951. }
  952. return false;
  953. }
  954. /**
  955. * Returns IDs of all documents containing term.
  956. *
  957. * @param Zend_Search_Lucene_Index_Term $term
  958. * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
  959. * @return array
  960. */
  961. public function termDocs(Zend_Search_Lucene_Index_Term $term, $docsFilter = null)
  962. {
  963. $subResults = array();
  964. $segmentStartDocId = 0;
  965. foreach ($this->_segmentInfos as $segmentInfo) {
  966. $subResults[] = $segmentInfo->termDocs($term, $segmentStartDocId, $docsFilter);
  967. $segmentStartDocId += $segmentInfo->count();
  968. }
  969. if (count($subResults) == 0) {
  970. return array();
  971. } else if (count($subResults) == 0) {
  972. // Index is optimized (only one segment)
  973. // Do not perform array reindexing
  974. return reset($subResults);
  975. } else {
  976. $result = call_user_func_array('array_merge', $subResults);
  977. }
  978. return $result;
  979. }
  980. /**
  981. * Returns documents filter for all documents containing term.
  982. *
  983. * It performs the same operation as termDocs, but return result as
  984. * Zend_Search_Lucene_Index_DocsFilter object
  985. *
  986. * @param Zend_Search_Lucene_Index_Term $term
  987. * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
  988. * @return Zend_Search_Lucene_Index_DocsFilter
  989. */
  990. public function termDocsFilter(Zend_Search_Lucene_Index_Term $term, $docsFilter = null)
  991. {
  992. $segmentStartDocId = 0;
  993. $result = new Zend_Search_Lucene_Index_DocsFilter();
  994. foreach ($this->_segmentInfos as $segmentInfo) {
  995. $subResults[] = $segmentInfo->termDocs($term, $segmentStartDocId, $docsFilter);
  996. $segmentStartDocId += $segmentInfo->count();
  997. }
  998. if (count($subResults) == 0) {
  999. return array();
  1000. } else if (count($subResults) == 0) {
  1001. // Index is optimized (only one segment)
  1002. // Do not perform array reindexing
  1003. return reset($subResults);
  1004. } else {
  1005. $result = call_user_func_array('array_merge', $subResults);
  1006. }
  1007. return $result;
  1008. }
  1009. /**
  1010. * Returns an array of all term freqs.
  1011. * Result array structure: array(docId => freq, ...)
  1012. *
  1013. * @param Zend_Search_Lucene_Index_Term $term
  1014. * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
  1015. * @return integer
  1016. */
  1017. public function termFreqs(Zend_Search_Lucene_Index_Term $term, $docsFilter = null)
  1018. {
  1019. $result = array();
  1020. $segmentStartDocId = 0;
  1021. foreach ($this->_segmentInfos as $segmentInfo) {
  1022. $result += $segmentInfo->termFreqs($term, $segmentStartDocId, $docsFilter);
  1023. $segmentStartDocId += $segmentInfo->count();
  1024. }
  1025. return $result;
  1026. }
  1027. /**
  1028. * Returns an array of all term positions in the documents.
  1029. * Result array structure: array(docId => array(pos1, pos2, ...), ...)
  1030. *
  1031. * @param Zend_Search_Lucene_Index_Term $term
  1032. * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
  1033. * @return array
  1034. */
  1035. public function termPositions(Zend_Search_Lucene_Index_Term $term, $docsFilter = null)
  1036. {
  1037. $result = array();
  1038. $segmentStartDocId = 0;
  1039. foreach ($this->_segmentInfos as $segmentInfo) {
  1040. $result += $segmentInfo->termPositions($term, $segmentStartDocId, $docsFilter);
  1041. $segmentStartDocId += $segmentInfo->count();
  1042. }
  1043. return $result;
  1044. }
  1045. /**
  1046. * Returns the number of documents in this index containing the $term.
  1047. *
  1048. * @param Zend_Search_Lucene_Index_Term $term
  1049. * @return integer
  1050. */
  1051. public function docFreq(Zend_Search_Lucene_Index_Term $term)
  1052. {
  1053. $result = 0;
  1054. foreach ($this->_segmentInfos as $segInfo) {
  1055. $termInfo = $segInfo->getTermInfo($term);
  1056. if ($termInfo !== null) {
  1057. $result += $termInfo->docFreq;
  1058. }
  1059. }
  1060. return $result;
  1061. }
  1062. /**
  1063. * Retrive similarity used by index reader
  1064. *
  1065. * @return Zend_Search_Lucene_Search_Similarity
  1066. */
  1067. public function getSimilarity()
  1068. {
  1069. return Zend_Search_Lucene_Search_Similarity::getDefault();
  1070. }
  1071. /**
  1072. * Returns a normalization factor for "field, document" pair.
  1073. *
  1074. * @param integer $id
  1075. * @param string $fieldName
  1076. * @return float
  1077. */
  1078. public function norm($id, $fieldName)
  1079. {
  1080. if ($id >= $this->_docCount) {
  1081. return null;
  1082. }
  1083. $segmentStartId = 0;
  1084. foreach ($this->_segmentInfos as $segInfo) {
  1085. if ($segmentStartId + $segInfo->count() > $id) {
  1086. break;
  1087. }
  1088. $segmentStartId += $segInfo->count();
  1089. }
  1090. if ($segInfo->isDeleted($id - $segmentStartId)) {
  1091. return 0;
  1092. }
  1093. return $segInfo->norm($id - $segmentStartId, $fieldName);
  1094. }
  1095. /**
  1096. * Returns true if any documents have been deleted from this index.
  1097. *
  1098. * @return boolean
  1099. */
  1100. public function hasDeletions()
  1101. {
  1102. foreach ($this->_segmentInfos as $segmentInfo) {
  1103. if ($segmentInfo->hasDeletions()) {
  1104. return true;
  1105. }
  1106. }
  1107. return false;
  1108. }
  1109. /**
  1110. * Deletes a document from the index.
  1111. * $id is an internal document id
  1112. *
  1113. * @param integer|Zend_Search_Lucene_Search_QueryHit $id
  1114. * @throws Zend_Search_Lucene_Exception
  1115. */
  1116. public function delete($id)
  1117. {
  1118. if ($id instanceof Zend_Search_Lucene_Search_QueryHit) {
  1119. /* @var $id Zend_Search_Lucene_Search_QueryHit */
  1120. $id = $id->id;
  1121. }
  1122. if ($id >= $this->_docCount) {
  1123. require_once 'Zend/Search/Lucene/Exception.php';
  1124. throw new Zend_Search_Lucene_Exception('Document id is out of the range.');
  1125. }
  1126. $segmentStartId = 0;
  1127. foreach ($this->_segmentInfos as $segmentInfo) {
  1128. if ($segmentStartId + $segmentInfo->count() > $id) {
  1129. break;
  1130. }
  1131. $segmentStartId += $segmentInfo->count();
  1132. }
  1133. $segmentInfo->delete($id - $segmentStartId);
  1134. $this->_hasChanges = true;
  1135. }
  1136. /**
  1137. * Adds a document to this index.
  1138. *
  1139. * @param Zend_Search_Lucene_Document $document
  1140. */
  1141. public function addDocument(Zend_Search_Lucene_Document $document)
  1142. {
  1143. $this->_getIndexWriter()->addDocument($document);
  1144. $this->_docCount++;
  1145. $this->_hasChanges = true;
  1146. }
  1147. /**
  1148. * Update document counter
  1149. */
  1150. private function _updateDocCount()
  1151. {
  1152. $this->_docCount = 0;
  1153. foreach ($this->_segmentInfos as $segInfo) {
  1154. $this->_docCount += $segInfo->count();
  1155. }
  1156. }
  1157. /**
  1158. * Commit changes resulting from delete() or undeleteAll() operations.
  1159. *
  1160. * @todo undeleteAll processing.
  1161. */
  1162. public function commit()
  1163. {
  1164. if ($this->_hasChanges) {
  1165. $this->_getIndexWriter()->commit();
  1166. $this->_updateDocCount();
  1167. $this->_hasChanges = false;
  1168. }
  1169. }
  1170. /**
  1171. * Optimize index.
  1172. *
  1173. * Merges all segments into one
  1174. */
  1175. public function optimize()
  1176. {
  1177. // Commit changes if any changes have been made
  1178. $this->commit();
  1179. if (count($this->_segmentInfos) > 1 || $this->hasDeletions()) {
  1180. $this->_getIndexWriter()->optimize();
  1181. $this->_updateDocCount();
  1182. }
  1183. }
  1184. /**
  1185. * Returns an array of all terms in this index.
  1186. *
  1187. * @return array
  1188. */
  1189. public function terms()
  1190. {
  1191. $result = array();
  1192. $segmentInfoQueue = new Zend_Search_Lucene_Index_TermsPriorityQueue();
  1193. foreach ($this->_segmentInfos as $segmentInfo) {
  1194. $segmentInfo->resetTermsStream();
  1195. // Skip "empty" segments
  1196. if ($segmentInfo->currentTerm() !== null) {
  1197. $segmentInfoQueue->put($segmentInfo);
  1198. }
  1199. }
  1200. while (($segmentInfo = $segmentInfoQueue->pop()) !== null) {
  1201. if ($segmentInfoQueue->top() === null ||
  1202. $segmentInfoQueue->top()->currentTerm()->key() !=
  1203. $segmentInfo->currentTerm()->key()) {
  1204. // We got new term
  1205. $result[] = $segmentInfo->currentTerm();
  1206. }
  1207. if ($segmentInfo->nextTerm() !== null) {
  1208. // Put segment back into the priority queue
  1209. $segmentInfoQueue->put($segmentInfo);
  1210. }
  1211. }
  1212. return $result;
  1213. }
  1214. /**
  1215. * Terms stream priority queue object
  1216. *
  1217. * @var Zend_Search_Lucene_TermStreamsPriorityQueue
  1218. */
  1219. private $_termsStream = null;
  1220. /**
  1221. * Reset terms stream.
  1222. */
  1223. public function resetTermsStream()
  1224. {
  1225. if ($this->_termsStream === null) {
  1226. $this->_termsStream = new Zend_Search_Lucene_TermStreamsPriorityQueue($this->_segmentInfos);
  1227. } else {
  1228. $this->_termsStream->resetTermsStream();
  1229. }
  1230. }
  1231. /**
  1232. * Skip terms stream up to specified term preffix.
  1233. *
  1234. * Prefix contains fully specified field info and portion of searched term
  1235. *
  1236. * @param Zend_Search_Lucene_Index_Term $prefix
  1237. */
  1238. public function skipTo(Zend_Search_Lucene_Index_Term $prefix)
  1239. {
  1240. $this->_termsStream->skipTo($prefix);
  1241. }
  1242. /**
  1243. * Scans terms dictionary and returns next term
  1244. *
  1245. * @return Zend_Search_Lucene_Index_Term|null
  1246. */
  1247. public function nextTerm()
  1248. {
  1249. return $this->_termsStream->nextTerm();
  1250. }
  1251. /**
  1252. * Returns term in current position
  1253. *
  1254. * @return Zend_Search_Lucene_Index_Term|null
  1255. */
  1256. public function currentTerm()
  1257. {
  1258. return $this->_termsStream->currentTerm();
  1259. }
  1260. /**
  1261. * Close terms stream
  1262. *
  1263. * Should be used for resources clean up if stream is not read up to the end
  1264. */
  1265. public function closeTermsStream()
  1266. {
  1267. $this->_termsStream->closeTermsStream();
  1268. $this->_termsStream = null;
  1269. }
  1270. /*************************************************************************
  1271. @todo UNIMPLEMENTED
  1272. *************************************************************************/
  1273. /**
  1274. * Undeletes all documents currently marked as deleted in this index.
  1275. *
  1276. * @todo Implementation
  1277. */
  1278. public function undeleteAll()
  1279. {}
  1280. }