Esempio n. 1
0
 public function testAddFieldMethodChaining()
 {
     $document = new Document\Document();
     $this->assertTrue($document->addField(Document\Field::Text('title', 'Title')) instanceof Document\Document);
     $document = new Document\Document();
     $document->addField(Document\Field::Text('title', 'Title'))->addField(Document\Field::Text('annotation', 'Annotation'))->addField(Document\Field::Text('body', 'Document body, document body, document body...'));
 }
Esempio n. 2
0
 public function testTermsStreamInterfaceSkipToTermsRetrievingTwoTermsCase()
 {
     $index = Lucene\Lucene::create(dirname(__FILE__) . '/_index/_files');
     // Zero terms
     $doc = new Document\Document();
     $doc->addField(Document\Field::Text('contents', 'someterm word'));
     $index->addDocument($doc);
     unset($index);
     $index = Lucene\Lucene::open(dirname(__FILE__) . '/_index/_files');
     $index->resetTermsStream();
     $index->skipTo(new Index\Term('term', 'contents'));
     $this->assertTrue($index->currentTerm() == new Index\Term('word', 'contents'));
     $index->closeTermsStream();
     $this->_clearDirectory(dirname(__FILE__) . '/_index/_files');
 }
Esempio n. 3
0
File: Index.php Progetto: stunti/zf2
 /**
  * Returns a Zend_Search_Lucene_Document object for the document
  * number $id in this index.
  *
  * @param integer|\Zend\Search\Lucene\Search\QueryHit $id
  * @return \Zend\Search\Lucene\Document\Document
  * @throws \Zend\Search\Lucene\Exception    Exception is thrown if $id is out of the range
  */
 public function getDocument($id)
 {
     if ($id instanceof Search\QueryHit) {
         /* @var $id Zend_Search_Lucene_Search_QueryHit */
         $id = $id->id;
     }
     if ($id >= $this->_docCount) {
         throw new Exception('Document id is out of the range.');
     }
     $segmentStartId = 0;
     foreach ($this->_segmentInfos as $segmentInfo) {
         if ($segmentStartId + $segmentInfo->count() > $id) {
             break;
         }
         $segmentStartId += $segmentInfo->count();
     }
     $fdxFile = $segmentInfo->openCompoundFile('.fdx');
     $fdxFile->seek(($id - $segmentStartId) * 8, SEEK_CUR);
     $fieldValuesPosition = $fdxFile->readLong();
     $fdtFile = $segmentInfo->openCompoundFile('.fdt');
     $fdtFile->seek($fieldValuesPosition, SEEK_CUR);
     $fieldCount = $fdtFile->readVInt();
     $doc = new Document\Document();
     for ($count = 0; $count < $fieldCount; $count++) {
         $fieldNum = $fdtFile->readVInt();
         $bits = $fdtFile->readByte();
         $fieldInfo = $segmentInfo->getField($fieldNum);
         if (!($bits & 2)) {
             // Text data
             $field = new Document\Field($fieldInfo->name, $fdtFile->readString(), 'UTF-8', true, $fieldInfo->isIndexed, $bits & 1);
         } else {
             // Binary data
             $field = new Document\Field($fieldInfo->name, $fdtFile->readBinary(), '', true, $fieldInfo->isIndexed, $bits & 1, true);
         }
         $doc->addField($field);
     }
     return $doc;
 }