[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/search/Zend/Search/Lucene/ -> Proxy.php (source)

   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-2007 Zend Technologies USA Inc. (http://www.zend.com)
  18   * @license    http://framework.zend.com/license/new-bsd     New BSD License
  19   */
  20  
  21  /** Zend_Search_Lucene_Interface */
  22  require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Interface.php';
  23  
  24  
  25  /**
  26   * Proxy class intended to be used in userland.
  27   *
  28   * It tracks, when index object goes out of scope and forces ndex closing
  29   *
  30   * @category   Zend
  31   * @package    Zend_Search_Lucene
  32   * @copyright  Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
  33   * @license    http://framework.zend.com/license/new-bsd     New BSD License
  34   */
  35  class Zend_Search_Lucene_Proxy implements Zend_Search_Lucene_Interface
  36  {
  37      /**
  38       * Index object
  39       *
  40       * @var Zend_Search_Lucene_Interface
  41       */
  42      private $_index;
  43  
  44      /**
  45       * Object constructor
  46       *
  47       * @param Zend_Search_Lucene_Interface $index
  48       */
  49      public function __construct(Zend_Search_Lucene_Interface $index)
  50      {
  51          $this->_index = $index;
  52          $this->_index->addReference();
  53      }
  54  
  55      /**
  56       * Object destructor
  57       */
  58      public function __destruct()
  59      {
  60          if ($this->_index !== null) {
  61              // This code is invoked if Zend_Search_Lucene_Interface object constructor throws an exception
  62              $this->_index->removeReference();
  63          }
  64          $this->_index = null;
  65      }
  66  
  67      /**
  68       * Returns the Zend_Search_Lucene_Storage_Directory instance for this index.
  69       *
  70       * @return Zend_Search_Lucene_Storage_Directory
  71       */
  72      public function getDirectory()
  73      {
  74          return $this->_index->getDirectory();
  75      }
  76  
  77      /**
  78       * Returns the total number of documents in this index (including deleted documents).
  79       *
  80       * @return integer
  81       */
  82      public function count()
  83      {
  84          return $this->_index->count();
  85      }
  86  
  87      /**
  88       * Returns one greater than the largest possible document number.
  89       * This may be used to, e.g., determine how big to allocate a structure which will have
  90       * an element for every document number in an index.
  91       *
  92       * @return integer
  93       */
  94      public function maxDoc()
  95      {
  96          return $this->_index->maxDoc();
  97      }
  98  
  99      /**
 100       * Returns the total number of non-deleted documents in this index.
 101       *
 102       * @return integer
 103       */
 104      public function numDocs()
 105      {
 106          return $this->_index->numDocs();
 107      }
 108  
 109      /**
 110       * Checks, that document is deleted
 111       *
 112       * @param integer $id
 113       * @return boolean
 114       * @throws Zend_Search_Lucene_Exception    Exception is thrown if $id is out of the range
 115       */
 116      public function isDeleted($id)
 117      {
 118          return $this->_index->isDeleted($id);
 119      }
 120  
 121      /**
 122       * Set default search field.
 123       *
 124       * Null means, that search is performed through all fields by default
 125       *
 126       * Default value is null
 127       *
 128       * @param string $fieldName
 129       */
 130      public static function setDefaultSearchField($fieldName)
 131      {
 132          Zend_Search_Lucene::setDefaultSearchField($fieldName);
 133      }
 134  
 135      /**
 136       * Get default search field.
 137       *
 138       * Null means, that search is performed through all fields by default
 139       *
 140       * @return string
 141       */
 142      public static function getDefaultSearchField()
 143      {
 144          return Zend_Search_Lucene::getDefaultSearchField();
 145      }
 146  
 147      /**
 148       * Retrieve index maxBufferedDocs option
 149       *
 150       * maxBufferedDocs is a minimal number of documents required before
 151       * the buffered in-memory documents are written into a new Segment
 152       *
 153       * Default value is 10
 154       *
 155       * @return integer
 156       */
 157      public function getMaxBufferedDocs()
 158      {
 159          return $this->_index->getMaxBufferedDocs();
 160      }
 161  
 162      /**
 163       * Set index maxBufferedDocs option
 164       *
 165       * maxBufferedDocs is a minimal number of documents required before
 166       * the buffered in-memory documents are written into a new Segment
 167       *
 168       * Default value is 10
 169       *
 170       * @param integer $maxBufferedDocs
 171       */
 172      public function setMaxBufferedDocs($maxBufferedDocs)
 173      {
 174          $this->_index->setMaxBufferedDocs($maxBufferedDocs);
 175      }
 176  
 177  
 178      /**
 179       * Retrieve index maxMergeDocs option
 180       *
 181       * maxMergeDocs is a largest number of documents ever merged by addDocument().
 182       * Small values (e.g., less than 10,000) are best for interactive indexing,
 183       * as this limits the length of pauses while indexing to a few seconds.
 184       * Larger values are best for batched indexing and speedier searches.
 185       *
 186       * Default value is PHP_INT_MAX
 187       *
 188       * @return integer
 189       */
 190      public function getMaxMergeDocs()
 191      {
 192          return $this->_index->getMaxMergeDocs();
 193      }
 194  
 195      /**
 196       * Set index maxMergeDocs option
 197       *
 198       * maxMergeDocs is a largest number of documents ever merged by addDocument().
 199       * Small values (e.g., less than 10,000) are best for interactive indexing,
 200       * as this limits the length of pauses while indexing to a few seconds.
 201       * Larger values are best for batched indexing and speedier searches.
 202       *
 203       * Default value is PHP_INT_MAX
 204       *
 205       * @param integer $maxMergeDocs
 206       */
 207      public function setMaxMergeDocs($maxMergeDocs)
 208      {
 209          $this->_index->setMaxMergeDocs($maxMergeDocs);
 210      }
 211  
 212  
 213      /**
 214       * Retrieve index mergeFactor option
 215       *
 216       * mergeFactor determines how often segment indices are merged by addDocument().
 217       * With smaller values, less RAM is used while indexing,
 218       * and searches on unoptimized indices are faster,
 219       * but indexing speed is slower.
 220       * With larger values, more RAM is used during indexing,
 221       * and while searches on unoptimized indices are slower,
 222       * indexing is faster.
 223       * Thus larger values (> 10) are best for batch index creation,
 224       * and smaller values (< 10) for indices that are interactively maintained.
 225       *
 226       * Default value is 10
 227       *
 228       * @return integer
 229       */
 230      public function getMergeFactor()
 231      {
 232          return $this->_index->getMergeFactor();
 233      }
 234  
 235      /**
 236       * Set index mergeFactor option
 237       *
 238       * mergeFactor determines how often segment indices are merged by addDocument().
 239       * With smaller values, less RAM is used while indexing,
 240       * and searches on unoptimized indices are faster,
 241       * but indexing speed is slower.
 242       * With larger values, more RAM is used during indexing,
 243       * and while searches on unoptimized indices are slower,
 244       * indexing is faster.
 245       * Thus larger values (> 10) are best for batch index creation,
 246       * and smaller values (< 10) for indices that are interactively maintained.
 247       *
 248       * Default value is 10
 249       *
 250       * @param integer $maxMergeDocs
 251       */
 252      public function setMergeFactor($mergeFactor)
 253      {
 254          $this->_index->setMergeFactor($mergeFactor);
 255      }
 256  
 257      /**
 258       * Performs a query against the index and returns an array
 259       * of Zend_Search_Lucene_Search_QueryHit objects.
 260       * Input is a string or Zend_Search_Lucene_Search_Query.
 261       *
 262       * @param mixed $query
 263       * @return array Zend_Search_Lucene_Search_QueryHit
 264       * @throws Zend_Search_Lucene_Exception
 265       */
 266      public function find($query)
 267      {
 268          // actual parameter list
 269          $parameters = func_get_args();
 270  
 271          // invoke $this->_index->find() method with specified parameters
 272          return call_user_func_array(array(&$this->_index, 'find'), $parameters);
 273      }
 274  
 275      /**
 276       * Returns a list of all unique field names that exist in this index.
 277       *
 278       * @param boolean $indexed
 279       * @return array
 280       */
 281      public function getFieldNames($indexed = false)
 282      {
 283          return $this->_index->getFieldNames($indexed);
 284      }
 285  
 286      /**
 287       * Returns a Zend_Search_Lucene_Document object for the document
 288       * number $id in this index.
 289       *
 290       * @param integer|Zend_Search_Lucene_Search_QueryHit $id
 291       * @return Zend_Search_Lucene_Document
 292       */
 293      public function getDocument($id)
 294      {
 295          return $this->_index->getDocument($id);
 296      }
 297  
 298      /**
 299       * Returns true if index contain documents with specified term.
 300       *
 301       * Is used for query optimization.
 302       *
 303       * @param Zend_Search_Lucene_Index_Term $term
 304       * @return boolean
 305       */
 306      public function hasTerm(Zend_Search_Lucene_Index_Term $term)
 307      {
 308          return $this->_index->hasTerm($term);
 309      }
 310  
 311      /**
 312       * Returns IDs of all the documents containing term.
 313       *
 314       * @param Zend_Search_Lucene_Index_Term $term
 315       * @return array
 316       */
 317      public function termDocs(Zend_Search_Lucene_Index_Term $term)
 318      {
 319          return $this->_index->termDocs($term);
 320      }
 321  
 322      /**
 323       * Returns an array of all term freqs.
 324       * Return array structure: array( docId => freq, ...)
 325       *
 326       * @param Zend_Search_Lucene_Index_Term $term
 327       * @return integer
 328       */
 329      public function termFreqs(Zend_Search_Lucene_Index_Term $term)
 330      {
 331          return $this->_index->termFreqs($term);
 332      }
 333  
 334      /**
 335       * Returns an array of all term positions in the documents.
 336       * Return array structure: array( docId => array( pos1, pos2, ...), ...)
 337       *
 338       * @param Zend_Search_Lucene_Index_Term $term
 339       * @return array
 340       */
 341      public function termPositions(Zend_Search_Lucene_Index_Term $term)
 342      {
 343          return $this->_index->termPositions($term);
 344      }
 345  
 346      /**
 347       * Returns the number of documents in this index containing the $term.
 348       *
 349       * @param Zend_Search_Lucene_Index_Term $term
 350       * @return integer
 351       */
 352      public function docFreq(Zend_Search_Lucene_Index_Term $term)
 353      {
 354          return $this->_index->docFreq($term);
 355      }
 356  
 357      /**
 358       * Retrive similarity used by index reader
 359       *
 360       * @return Zend_Search_Lucene_Search_Similarity
 361       */
 362      public function getSimilarity()
 363      {
 364          return $this->_index->getSimilarity();
 365      }
 366  
 367      /**
 368       * Returns a normalization factor for "field, document" pair.
 369       *
 370       * @param integer $id
 371       * @param string $fieldName
 372       * @return float
 373       */
 374      public function norm($id, $fieldName)
 375      {
 376          return $this->_index->norm($id, $fieldName);
 377      }
 378  
 379      /**
 380       * Returns true if any documents have been deleted from this index.
 381       *
 382       * @return boolean
 383       */
 384      public function hasDeletions()
 385      {
 386          return $this->_index->hasDeletions();
 387      }
 388  
 389      /**
 390       * Deletes a document from the index.
 391       * $id is an internal document id
 392       *
 393       * @param integer|Zend_Search_Lucene_Search_QueryHit $id
 394       * @throws Zend_Search_Lucene_Exception
 395       */
 396      public function delete($id)
 397      {
 398          return $this->_index->delete($id);
 399      }
 400  
 401      /**
 402       * Adds a document to this index.
 403       *
 404       * @param Zend_Search_Lucene_Document $document
 405       */
 406      public function addDocument(Zend_Search_Lucene_Document $document)
 407      {
 408          $this->_index->addDocument($document);
 409      }
 410  
 411      /**
 412       * Commit changes resulting from delete() or undeleteAll() operations.
 413       */
 414      public function commit()
 415      {
 416          $this->_index->commit();
 417      }
 418  
 419      /**
 420       * Optimize index.
 421       *
 422       * Merges all segments into one
 423       */
 424      public function optimize()
 425      {
 426          $this->_index->optimize();
 427      }
 428  
 429      /**
 430       * Returns an array of all terms in this index.
 431       *
 432       * @return array
 433       */
 434      public function terms()
 435      {
 436          return $this->_index->terms();
 437      }
 438  
 439      /**
 440       * Undeletes all documents currently marked as deleted in this index.
 441       */
 442      public function undeleteAll()
 443      {
 444          return $this->_index->undeleteAll();
 445      }
 446  
 447      /**
 448       * Add reference to the index object
 449       *
 450       * @internal
 451       */
 452      public function addReference()
 453      {
 454          return $this->_index->addReference();
 455      }
 456  
 457      /**
 458       * Remove reference from the index object
 459       *
 460       * When reference count becomes zero, index is closed and resources are cleaned up
 461       *
 462       * @internal
 463       */
 464      public function removeReference()
 465      {
 466          return $this->_index->removeReference();
 467      }
 468  }


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7