import v1.1.0_beta1 | 2009-08-21

This commit is contained in:
2019-07-17 22:16:19 +02:00
parent 2c1152f0d3
commit 8dee6b1a10
2306 changed files with 251360 additions and 23428 deletions

View File

@ -18,16 +18,21 @@
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Search_Lucene_Exception */
require_once 'Zend/Search/Lucene/Exception.php';
/** Zend_Search_Lucene_Document */
require_once 'Zend/Search/Lucene/Document.php';
/** Zend_Search_Lucene_Document_Html */
require_once 'Zend/Search/Lucene/Document/Html.php';
/** Zend_Search_Lucene_Document_Docx */
require_once 'Zend/Search/Lucene/Document/Docx.php';
/** Zend_Search_Lucene_Document_Pptx */
require_once 'Zend/Search/Lucene/Document/Pptx.php';
/** Zend_Search_Lucene_Document_Xlsx */
require_once 'Zend/Search/Lucene/Document/Xlsx.php';
/** Zend_Search_Lucene_Storage_Directory_Filesystem */
require_once 'Zend/Search/Lucene/Storage/Directory/Filesystem.php';
@ -58,8 +63,11 @@ require_once 'Zend/Search/Lucene/Search/QueryHit.php';
/** Zend_Search_Lucene_Search_Similarity */
require_once 'Zend/Search/Lucene/Search/Similarity.php';
/** Zend_Search_Lucene_Index_SegmentInfoPriorityQueue */
require_once 'Zend/Search/Lucene/Index/SegmentInfoPriorityQueue.php';
/** Zend_Search_Lucene_Index_TermsPriorityQueue */
require_once 'Zend/Search/Lucene/Index/TermsPriorityQueue.php';
/** Zend_Search_Lucene_TermStreamsPriorityQueue */
require_once 'Zend/Search/Lucene/TermStreamsPriorityQueue.php';
/** Zend_Search_Lucene_Index_DocsFilter */
require_once 'Zend/Search/Lucene/Index/DocsFilter.php';
@ -67,15 +75,12 @@ require_once 'Zend/Search/Lucene/Index/DocsFilter.php';
/** Zend_Search_Lucene_LockManager */
require_once 'Zend/Search/Lucene/LockManager.php';
/** Zend_Search_Lucene_Interface */
require_once 'Zend/Search/Lucene/Interface.php';
/** Zend_Search_Lucene_Proxy */
require_once 'Zend/Search/Lucene/Proxy.php';
/**
* @category Zend
* @package Zend_Search_Lucene
@ -102,6 +107,15 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
*/
private static $_resultSetLimit = 0;
/**
* Terms per query limit
*
* 0 means no limit
*
* @var integer
*/
private static $_termsPerQueryLimit = 1024;
/**
* File system adapter.
*
@ -170,6 +184,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
const FORMAT_2_1 = 1;
const FORMAT_2_3 = 2;
/**
* Index format version
*
@ -229,6 +244,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
* without performance problems
*/
require_once 'Zend/Search/Lucene/Exception.php';
try {
for ($count = 0; $count < self::GENERATION_RETRIEVE_COUNT; $count++) {
// Try to get generation file
@ -311,6 +327,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
if ($formatVersion != self::FORMAT_PRE_2_1 &&
$formatVersion != self::FORMAT_2_1 &&
$formatVersion != self::FORMAT_2_3) {
require_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Unsupported index format');
}
@ -329,12 +346,12 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
$format = $segmentsFile->readInt();
if ($format != (int)0xFFFFFFFF) {
require_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Wrong segments file format');
}
// read version
// $segmentsFile->readLong();
$segmentsFile->readInt(); $segmentsFile->readInt();
$segmentsFile->readLong();
// read segment name counter
$segmentsFile->readInt();
@ -375,12 +392,12 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
} else if ($format == (int)0xFFFFFFFD) {
$this->_formatVersion = self::FORMAT_2_1;
} else {
require_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Unsupported segments file format');
}
// read version
// $segmentsFile->readLong();
$segmentsFile->readInt(); $segmentsFile->readInt();
$segmentsFile->readLong();
// read segment name counter
$segmentsFile->readInt();
@ -395,19 +412,12 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
$segSize = $segmentsFile->readInt();
// 2.1+ specific properties
//$delGen = $segmentsFile->readLong();
$delGenHigh = $segmentsFile->readInt();
$delGenLow = $segmentsFile->readInt();
if ($delGenHigh == (int)0xFFFFFFFF && $delGenLow == (int)0xFFFFFFFF) {
$delGen = -1; // There are no deletes
} else {
$delGen = ($delGenHigh << 32) | $delGenLow;
}
$delGen = $segmentsFile->readLong();
if ($this->_formatVersion == self::FORMAT_2_3) {
$docStoreOffset = $segmentsFile->readInt();
if ($docStoreOffset != -1) {
if ($docStoreOffset != (int)0xFFFFFFFF) {
$docStoreSegment = $segmentsFile->readString();
$docStoreIsCompoundFile = $segmentsFile->readByte();
@ -430,6 +440,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
$normGens[] = $segmentsFile->readLong();
}
require_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Separate norm files are not supported. Optimize index to use it with Zend_Search_Lucene.');
}
@ -471,6 +482,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
public function __construct($directory = null, $create = false)
{
if ($directory === null) {
require_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Exception('No index directory specified');
}
@ -490,6 +502,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
$this->_generation = self::getActualGeneration($this->_directory);
if ($create) {
require_once 'Zend/Search/Lucene/Exception.php';
try {
Zend_Search_Lucene_LockManager::obtainWriteLock($this->_directory);
} catch (Zend_Search_Lucene_Exception $e) {
@ -521,6 +534,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
}
if ($this->_generation == -1) {
require_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Index doesn\'t exists in the specified directory.');
} else if ($this->_generation == 0) {
$this->_readPre21SegmentsFile();
@ -663,6 +677,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
public function isDeleted($id)
{
if ($id >= $this->_docCount) {
require_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Document id is out of the range.');
}
@ -717,7 +732,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
}
/**
* Set result set limit.
* Get result set limit.
*
* 0 means no limit
*
@ -728,6 +743,30 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
return self::$_resultSetLimit;
}
/**
* Set terms per query limit.
*
* 0 means no limit
*
* @param integer $limit
*/
public static function setTermsPerQueryLimit($limit)
{
self::$_termsPerQueryLimit = $limit;
}
/**
* Get result set limit.
*
* 0 (default) means no limit
*
* @return integer
*/
public static function getTermsPerQueryLimit()
{
return self::$_termsPerQueryLimit;
}
/**
* Retrieve index maxBufferedDocs option
*
@ -852,6 +891,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
}
if (!$query instanceof Zend_Search_Lucene_Search_Query) {
require_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Query must be a string or Zend_Search_Lucene_Search_Query object');
}
@ -911,6 +951,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
$fieldNames = $this->getFieldNames();
$sortArgs = array();
require_once 'Zend/Search/Lucene/Exception.php';
for ($count = 1; $count < count($argList); $count++) {
$fieldName = $argList[$count];
@ -997,6 +1038,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
*
* @param integer|Zend_Search_Lucene_Search_QueryHit $id
* @return Zend_Search_Lucene_Document
* @throws Zend_Search_Lucene_Exception Exception is thrown if $id is out of the range
*/
public function getDocument($id)
{
@ -1006,6 +1048,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
}
if ($id >= $this->_docCount) {
require_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Document id is out of the range.');
}
@ -1277,6 +1320,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
}
if ($id >= $this->_docCount) {
require_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Document id is out of the range.');
}
@ -1363,10 +1407,10 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
{
$result = array();
$segmentInfoQueue = new Zend_Search_Lucene_Index_SegmentInfoPriorityQueue();
$segmentInfoQueue = new Zend_Search_Lucene_Index_TermsPriorityQueue();
foreach ($this->_segmentInfos as $segmentInfo) {
$segmentInfo->reset();
$segmentInfo->resetTermsStream();
// Skip "empty" segments
if ($segmentInfo->currentTerm() !== null) {
@ -1393,36 +1437,22 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
/**
* Terms stream queue
* Terms stream priority queue object
*
* @var Zend_Search_Lucene_Index_SegmentInfoPriorityQueue
* @var Zend_Search_Lucene_TermStreamsPriorityQueue
*/
private $_termsStreamQueue = null;
/**
* Last Term in a terms stream
*
* @var Zend_Search_Lucene_Index_Term
*/
private $_lastTerm = null;
private $_termsStream = null;
/**
* Reset terms stream.
*/
public function resetTermsStream()
{
$this->_termsStreamQueue = new Zend_Search_Lucene_Index_SegmentInfoPriorityQueue();
foreach ($this->_segmentInfos as $segmentInfo) {
$segmentInfo->reset();
// Skip "empty" segments
if ($segmentInfo->currentTerm() !== null) {
$this->_termsStreamQueue->put($segmentInfo);
}
}
$this->nextTerm();
if ($this->_termsStream === null) {
$this->_termsStream = new Zend_Search_Lucene_TermStreamsPriorityQueue($this->_segmentInfos);
} else {
$this->_termsStream->resetTermsStream();
}
}
/**
@ -1434,21 +1464,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
*/
public function skipTo(Zend_Search_Lucene_Index_Term $prefix)
{
$segments = array();
while (($segmentInfo = $this->_termsStreamQueue->pop()) !== null) {
$segments[] = $segmentInfo;
}
foreach ($segments as $segmentInfo) {
$segmentInfo->skipTo($prefix);
if ($segmentInfo->currentTerm() !== null) {
$this->_termsStreamQueue->put($segmentInfo);
}
}
$this->nextTerm();
$this->_termsStream->skipTo($prefix);
}
/**
@ -1458,31 +1474,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
*/
public function nextTerm()
{
while (($segmentInfo = $this->_termsStreamQueue->pop()) !== null) {
if ($this->_termsStreamQueue->top() === null ||
$this->_termsStreamQueue->top()->currentTerm()->key() !=
$segmentInfo->currentTerm()->key()) {
// We got new term
$this->_lastTerm = $segmentInfo->currentTerm();
if ($segmentInfo->nextTerm() !== null) {
// Put segment back into the priority queue
$this->_termsStreamQueue->put($segmentInfo);
}
return $this->_lastTerm;
}
if ($segmentInfo->nextTerm() !== null) {
// Put segment back into the priority queue
$this->_termsStreamQueue->put($segmentInfo);
}
}
// End of stream
$this->_lastTerm = null;
return null;
return $this->_termsStream->nextTerm();
}
/**
@ -1492,7 +1484,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
*/
public function currentTerm()
{
return $this->_lastTerm;
return $this->_termsStream->currentTerm();
}
/**
@ -1502,12 +1494,8 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
*/
public function closeTermsStream()
{
while (($segmentInfo = $this->_termsStreamQueue->pop()) !== null) {
$segmentInfo->closeTermsStream();
}
$this->_termsStreamQueue = null;
$this->_lastTerm = null;
$this->_termsStream->closeTermsStream();
$this->_termsStream = null;
}