Lucene.php 43 KB

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