예제 #1
0
 /**
  * @returns \Zend\Search\Lucene\SearchIndexInterface
  */
 public function get()
 {
     if (!$this->checkEsists()) {
         return Lucene::create($this->path);
     } else {
         return Lucene::open($this->path);
     }
 }
예제 #2
0
 /**
  * @covers Zend\Search\Lucene\MultiSearcher::find
  * @covers Zend\Search\Lucene\Search\QueryHit::getDocument
  */
 public function testFind()
 {
     $index = new Lucene\MultiSearcher(array(Lucene\Lucene::open(__DIR__ . '/_indexSample/_files'), Lucene\Lucene::open(__DIR__ . '/_indexSample/_files')));
     $hits = $index->find('submitting');
     $this->assertEquals(count($hits), 2 * 3);
     foreach ($hits as $hit) {
         $document = $hit->getDocument();
         $this->assertTrue($document instanceof Lucene\Document);
     }
 }
예제 #3
0
    /**
     * Transforms given objects into a bulk add operation directive
     *
     * @param ClassMetadata $metadata
     * @param array $objects
     * @param array bulk commands
     */
    public function run(ClassMetadata $metadata, array $objects)
    {
        $index = $metadata->getIndex()->getName();

        $index = Lucene::open("/tmp/index_$index");

        foreach ($objects as $object) {
            $document = $this->exportObject($metadata, $object);
            $index->addDocument($document);
        }
    }
예제 #4
0
    /**
     * (non-PHPdoc)
     * @see Ariadne\Engine.Engine::search()
     */
    public function run(ClassMetadata $metadata, Query $query)
    {
        $index = $metadata->getIndex()->getName();

        $type = $metadata->getClassName();

        $arguments = $this->mapQuery($query);

        $index = Lucene::open("/tmp/index_$index");

        $result = call_user_func_array(array($index, 'find'), $arguments);

        return $this->mapResult($result, $metadata, $query);
    }
예제 #5
0
 public function testLimitingResult()
 {
     $index = Lucene\Lucene::open(dirname(__FILE__) . '/_index23Sample/_files');
     $storedResultSetLimit = Lucene\Lucene::getResultSetLimit();
     Lucene\Lucene::setResultSetLimit(3);
     $hits = $index->find('"reporting bugs"', 'path');
     $this->assertEquals(count($hits), 3);
     $expectedResultset = array(array(7, 0.212395, 'IndexSource/contributing.bugs.html'), array(0, 0.247795, 'IndexSource/contributing.documentation.html'), array(2, 0.176996, 'IndexSource/contributing.patches.html'));
     foreach ($hits as $resId => $hit) {
         $this->assertEquals($hit->id, $expectedResultset[$resId][0]);
         $this->assertTrue(abs($hit->score - $expectedResultset[$resId][1]) < 1.0E-6);
         $this->assertEquals($hit->path, $expectedResultset[$resId][2]);
     }
     Lucene\Lucene::setResultSetLimit($storedResultSetLimit);
 }
예제 #6
0
파일: IndexTest.php 프로젝트: rikaix/zf2
 public function testTermsStreamInterfaceSkipToTermsRetrievingTwoTermsCase()
 {
     $index = Lucene\Lucene::create(__DIR__ . '/_index/_files');
     // Zero terms
     $doc = new Document();
     $doc->addField(Document\Field::Text('contents', 'someterm word'));
     $index->addDocument($doc);
     unset($index);
     $index = Lucene\Lucene::open(__DIR__ . '/_index/_files');
     $index->resetTermsStream();
     $index->skipTo(new Index\Term('term', 'contents'));
     $this->assertTrue($index->currentTerm() == new Index\Term('word', 'contents'));
     $index->closeTermsStream();
 }