*prechod na novsiu verziu ZF
[sport-group.git] / library / Zend / Search / Lucene / Proxy.php
blob5164968b0e4df29b6cd1069ca157e5e0d3ae84a8
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
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.
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: Proxy.php 16971 2009-07-22 18:05:45Z mikaelkael $
22 /** Zend_Search_Lucene_Interface */
23 require_once 'Zend/Search/Lucene/Interface.php';
26 /**
27 * Proxy class intended to be used in userland.
29 * It tracks, when index object goes out of scope and forces ndex closing
31 * @category Zend
32 * @package Zend_Search_Lucene
33 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
34 * @license http://framework.zend.com/license/new-bsd New BSD License
36 class Zend_Search_Lucene_Proxy implements Zend_Search_Lucene_Interface
38 /**
39 * Index object
41 * @var Zend_Search_Lucene_Interface
43 private $_index;
45 /**
46 * Object constructor
48 * @param Zend_Search_Lucene_Interface $index
50 public function __construct(Zend_Search_Lucene_Interface $index)
52 $this->_index = $index;
53 $this->_index->addReference();
56 /**
57 * Object destructor
59 public function __destruct()
61 if ($this->_index !== null) {
62 // This code is invoked if Zend_Search_Lucene_Interface object constructor throws an exception
63 $this->_index->removeReference();
65 $this->_index = null;
68 /**
69 * Get current generation number
71 * Returns generation number
72 * 0 means pre-2.1 index format
73 * -1 means there are no segments files.
75 * @param Zend_Search_Lucene_Storage_Directory $directory
76 * @return integer
77 * @throws Zend_Search_Lucene_Exception
79 public static function getActualGeneration(Zend_Search_Lucene_Storage_Directory $directory)
81 Zend_Search_Lucene::getActualGeneration($directory);
84 /**
85 * Get segments file name
87 * @param integer $generation
88 * @return string
90 public static function getSegmentFileName($generation)
92 Zend_Search_Lucene::getSegmentFileName($generation);
95 /**
96 * Get index format version
98 * @return integer
100 public function getFormatVersion()
102 return $this->_index->getFormatVersion();
106 * Set index format version.
107 * Index is converted to this format at the nearest upfdate time
109 * @param int $formatVersion
110 * @throws Zend_Search_Lucene_Exception
112 public function setFormatVersion($formatVersion)
114 $this->_index->setFormatVersion($formatVersion);
118 * Returns the Zend_Search_Lucene_Storage_Directory instance for this index.
120 * @return Zend_Search_Lucene_Storage_Directory
122 public function getDirectory()
124 return $this->_index->getDirectory();
128 * Returns the total number of documents in this index (including deleted documents).
130 * @return integer
132 public function count()
134 return $this->_index->count();
138 * Returns one greater than the largest possible document number.
139 * This may be used to, e.g., determine how big to allocate a structure which will have
140 * an element for every document number in an index.
142 * @return integer
144 public function maxDoc()
146 return $this->_index->maxDoc();
150 * Returns the total number of non-deleted documents in this index.
152 * @return integer
154 public function numDocs()
156 return $this->_index->numDocs();
160 * Checks, that document is deleted
162 * @param integer $id
163 * @return boolean
164 * @throws Zend_Search_Lucene_Exception Exception is thrown if $id is out of the range
166 public function isDeleted($id)
168 return $this->_index->isDeleted($id);
172 * Set default search field.
174 * Null means, that search is performed through all fields by default
176 * Default value is null
178 * @param string $fieldName
180 public static function setDefaultSearchField($fieldName)
182 Zend_Search_Lucene::setDefaultSearchField($fieldName);
186 * Get default search field.
188 * Null means, that search is performed through all fields by default
190 * @return string
192 public static function getDefaultSearchField()
194 return Zend_Search_Lucene::getDefaultSearchField();
198 * Set result set limit.
200 * 0 (default) means no limit
202 * @param integer $limit
204 public static function setResultSetLimit($limit)
206 Zend_Search_Lucene::setResultSetLimit($limit);
210 * Set result set limit.
212 * 0 means no limit
214 * @return integer
216 public static function getResultSetLimit()
218 return Zend_Search_Lucene::getResultSetLimit();
222 * Retrieve index maxBufferedDocs option
224 * maxBufferedDocs is a minimal number of documents required before
225 * the buffered in-memory documents are written into a new Segment
227 * Default value is 10
229 * @return integer
231 public function getMaxBufferedDocs()
233 return $this->_index->getMaxBufferedDocs();
237 * Set index maxBufferedDocs option
239 * maxBufferedDocs is a minimal number of documents required before
240 * the buffered in-memory documents are written into a new Segment
242 * Default value is 10
244 * @param integer $maxBufferedDocs
246 public function setMaxBufferedDocs($maxBufferedDocs)
248 $this->_index->setMaxBufferedDocs($maxBufferedDocs);
253 * Retrieve index maxMergeDocs option
255 * maxMergeDocs is a largest number of documents ever merged by addDocument().
256 * Small values (e.g., less than 10,000) are best for interactive indexing,
257 * as this limits the length of pauses while indexing to a few seconds.
258 * Larger values are best for batched indexing and speedier searches.
260 * Default value is PHP_INT_MAX
262 * @return integer
264 public function getMaxMergeDocs()
266 return $this->_index->getMaxMergeDocs();
270 * Set index maxMergeDocs option
272 * maxMergeDocs is a largest number of documents ever merged by addDocument().
273 * Small values (e.g., less than 10,000) are best for interactive indexing,
274 * as this limits the length of pauses while indexing to a few seconds.
275 * Larger values are best for batched indexing and speedier searches.
277 * Default value is PHP_INT_MAX
279 * @param integer $maxMergeDocs
281 public function setMaxMergeDocs($maxMergeDocs)
283 $this->_index->setMaxMergeDocs($maxMergeDocs);
288 * Retrieve index mergeFactor option
290 * mergeFactor determines how often segment indices are merged by addDocument().
291 * With smaller values, less RAM is used while indexing,
292 * and searches on unoptimized indices are faster,
293 * but indexing speed is slower.
294 * With larger values, more RAM is used during indexing,
295 * and while searches on unoptimized indices are slower,
296 * indexing is faster.
297 * Thus larger values (> 10) are best for batch index creation,
298 * and smaller values (< 10) for indices that are interactively maintained.
300 * Default value is 10
302 * @return integer
304 public function getMergeFactor()
306 return $this->_index->getMergeFactor();
310 * Set index mergeFactor option
312 * mergeFactor determines how often segment indices are merged by addDocument().
313 * With smaller values, less RAM is used while indexing,
314 * and searches on unoptimized indices are faster,
315 * but indexing speed is slower.
316 * With larger values, more RAM is used during indexing,
317 * and while searches on unoptimized indices are slower,
318 * indexing is faster.
319 * Thus larger values (> 10) are best for batch index creation,
320 * and smaller values (< 10) for indices that are interactively maintained.
322 * Default value is 10
324 * @param integer $maxMergeDocs
326 public function setMergeFactor($mergeFactor)
328 $this->_index->setMergeFactor($mergeFactor);
332 * Performs a query against the index and returns an array
333 * of Zend_Search_Lucene_Search_QueryHit objects.
334 * Input is a string or Zend_Search_Lucene_Search_Query.
336 * @param mixed $query
337 * @return array Zend_Search_Lucene_Search_QueryHit
338 * @throws Zend_Search_Lucene_Exception
340 public function find($query)
342 // actual parameter list
343 $parameters = func_get_args();
345 // invoke $this->_index->find() method with specified parameters
346 return call_user_func_array(array(&$this->_index, 'find'), $parameters);
350 * Returns a list of all unique field names that exist in this index.
352 * @param boolean $indexed
353 * @return array
355 public function getFieldNames($indexed = false)
357 return $this->_index->getFieldNames($indexed);
361 * Returns a Zend_Search_Lucene_Document object for the document
362 * number $id in this index.
364 * @param integer|Zend_Search_Lucene_Search_QueryHit $id
365 * @return Zend_Search_Lucene_Document
367 public function getDocument($id)
369 return $this->_index->getDocument($id);
373 * Returns true if index contain documents with specified term.
375 * Is used for query optimization.
377 * @param Zend_Search_Lucene_Index_Term $term
378 * @return boolean
380 public function hasTerm(Zend_Search_Lucene_Index_Term $term)
382 return $this->_index->hasTerm($term);
386 * Returns IDs of all the documents containing term.
388 * @param Zend_Search_Lucene_Index_Term $term
389 * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
390 * @return array
392 public function termDocs(Zend_Search_Lucene_Index_Term $term, $docsFilter = null)
394 return $this->_index->termDocs($term, $docsFilter);
398 * Returns documents filter for all documents containing term.
400 * It performs the same operation as termDocs, but return result as
401 * Zend_Search_Lucene_Index_DocsFilter object
403 * @param Zend_Search_Lucene_Index_Term $term
404 * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
405 * @return Zend_Search_Lucene_Index_DocsFilter
407 public function termDocsFilter(Zend_Search_Lucene_Index_Term $term, $docsFilter = null)
409 return $this->_index->termDocsFilter($term, $docsFilter);
413 * Returns an array of all term freqs.
414 * Return array structure: array( docId => freq, ...)
416 * @param Zend_Search_Lucene_Index_Term $term
417 * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
418 * @return integer
420 public function termFreqs(Zend_Search_Lucene_Index_Term $term, $docsFilter = null)
422 return $this->_index->termFreqs($term, $docsFilter);
426 * Returns an array of all term positions in the documents.
427 * Return array structure: array( docId => array( pos1, pos2, ...), ...)
429 * @param Zend_Search_Lucene_Index_Term $term
430 * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
431 * @return array
433 public function termPositions(Zend_Search_Lucene_Index_Term $term, $docsFilter = null)
435 return $this->_index->termPositions($term, $docsFilter);
439 * Returns the number of documents in this index containing the $term.
441 * @param Zend_Search_Lucene_Index_Term $term
442 * @return integer
444 public function docFreq(Zend_Search_Lucene_Index_Term $term)
446 return $this->_index->docFreq($term);
450 * Retrive similarity used by index reader
452 * @return Zend_Search_Lucene_Search_Similarity
454 public function getSimilarity()
456 return $this->_index->getSimilarity();
460 * Returns a normalization factor for "field, document" pair.
462 * @param integer $id
463 * @param string $fieldName
464 * @return float
466 public function norm($id, $fieldName)
468 return $this->_index->norm($id, $fieldName);
472 * Returns true if any documents have been deleted from this index.
474 * @return boolean
476 public function hasDeletions()
478 return $this->_index->hasDeletions();
482 * Deletes a document from the index.
483 * $id is an internal document id
485 * @param integer|Zend_Search_Lucene_Search_QueryHit $id
486 * @throws Zend_Search_Lucene_Exception
488 public function delete($id)
490 return $this->_index->delete($id);
494 * Adds a document to this index.
496 * @param Zend_Search_Lucene_Document $document
498 public function addDocument(Zend_Search_Lucene_Document $document)
500 $this->_index->addDocument($document);
504 * Commit changes resulting from delete() or undeleteAll() operations.
506 public function commit()
508 $this->_index->commit();
512 * Optimize index.
514 * Merges all segments into one
516 public function optimize()
518 $this->_index->optimize();
522 * Returns an array of all terms in this index.
524 * @return array
526 public function terms()
528 return $this->_index->terms();
533 * Reset terms stream.
535 public function resetTermsStream()
537 $this->_index->resetTermsStream();
541 * Skip terms stream up to specified term preffix.
543 * Prefix contains fully specified field info and portion of searched term
545 * @param Zend_Search_Lucene_Index_Term $prefix
547 public function skipTo(Zend_Search_Lucene_Index_Term $prefix)
549 return $this->_index->skipTo($prefix);
553 * Scans terms dictionary and returns next term
555 * @return Zend_Search_Lucene_Index_Term|null
557 public function nextTerm()
559 return $this->_index->nextTerm();
563 * Returns term in current position
565 * @return Zend_Search_Lucene_Index_Term|null
567 public function currentTerm()
569 return $this->_index->currentTerm();
573 * Close terms stream
575 * Should be used for resources clean up if stream is not read up to the end
577 public function closeTermsStream()
579 $this->_index->closeTermsStream();
584 * Undeletes all documents currently marked as deleted in this index.
586 public function undeleteAll()
588 return $this->_index->undeleteAll();
592 * Add reference to the index object
594 * @internal
596 public function addReference()
598 return $this->_index->addReference();
602 * Remove reference from the index object
604 * When reference count becomes zero, index is closed and resources are cleaned up
606 * @internal
608 public function removeReference()
610 return $this->_index->removeReference();