Ver Fonte

Zend_Search_Lucene: range query processing bug is fixed [ZF-7518].

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@22987 44c647ce-9c0f-0410-b52a-842ac1e357ba
alexander há 15 anos atrás
pai
commit
037ce89f91

+ 1 - 1
library/Zend/Search/Lucene.php

@@ -1523,7 +1523,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
     }
 
     /**
-     * Skip terms stream up to specified term preffix.
+     * Skip terms stream up to the specified term preffix.
      *
      * Prefix contains fully specified field info and portion of searched term
      *

+ 1 - 1
library/Zend/Search/Lucene/Index/SegmentInfo.php

@@ -1861,7 +1861,7 @@ class Zend_Search_Lucene_Index_SegmentInfo implements Zend_Search_Lucene_Index_T
 
 
     /**
-     * Skip terms stream up to specified term preffix.
+     * Skip terms stream up to the specified term preffix.
      *
      * Prefix contains fully specified field info and portion of searched term
      *

+ 1 - 1
library/Zend/Search/Lucene/Index/TermsStream/Interface.php

@@ -35,7 +35,7 @@ interface Zend_Search_Lucene_Index_TermsStream_Interface
     public function resetTermsStream();
 
     /**
-     * Skip terms stream up to specified term preffix.
+     * Skip terms stream up to the specified term preffix.
      *
      * Prefix contains fully specified field info and portion of searched term
      *

+ 1 - 1
library/Zend/Search/Lucene/Search/Query/Range.php

@@ -186,7 +186,7 @@ class Zend_Search_Lucene_Search_Query_Range extends Zend_Search_Lucene_Search_Qu
 
                 while ($index->currentTerm() !== null          &&
                        $index->currentTerm()->field == $field  &&
-                       $index->currentTerm()->text  <  $upperTerm->text) {
+                       strcmp($index->currentTerm()->text, $upperTerm->text) < 0) {
                     $this->_matches[] = $index->currentTerm();
 
                     if ($maxTerms != 0  &&  count($this->_matches) > $maxTerms) {

+ 4 - 8
library/Zend/Search/Lucene/TermStreamsPriorityQueue.php

@@ -90,7 +90,7 @@ class Zend_Search_Lucene_TermStreamsPriorityQueue implements Zend_Search_Lucene_
     }
 
     /**
-     * Skip terms stream up to specified term preffix.
+     * Skip terms stream up to the specified term preffix.
      *
      * Prefix contains fully specified field info and portion of searched term
      *
@@ -98,13 +98,9 @@ class Zend_Search_Lucene_TermStreamsPriorityQueue implements Zend_Search_Lucene_
      */
     public function skipTo(Zend_Search_Lucene_Index_Term $prefix)
     {
-        $termStreams = array();
-
-        while (($termStream = $this->_termsStreamQueue->pop()) !== null) {
-            $termStreams[] = $termStream;
-        }
+        $this->_termsStreamQueue = new Zend_Search_Lucene_Index_TermsPriorityQueue();
 
-        foreach ($termStreams as $termStream) {
+        foreach ($this->_termStreams as $termStream) {
             $termStream->skipTo($prefix);
 
             if ($termStream->currentTerm() !== null) {
@@ -112,7 +108,7 @@ class Zend_Search_Lucene_TermStreamsPriorityQueue implements Zend_Search_Lucene_
             }
         }
 
-        $this->nextTerm();
+        return $this->nextTerm();
     }
 
     /**

+ 39 - 1
tests/Zend/Search/Lucene/LuceneTest.php

@@ -69,8 +69,8 @@ class Zend_Search_Lucene_LuceneTest extends PHPUnit_Framework_TestCase
     public function testCreate()
     {
         $index = Zend_Search_Lucene::create(dirname(__FILE__) . '/_index/_files');
-
         $this->assertTrue($index instanceof Zend_Search_Lucene_Interface);
+        unset($index);
 
         $this->_clearDirectory(dirname(__FILE__) . '/_index/_files');
     }
@@ -323,6 +323,7 @@ class Zend_Search_Lucene_LuceneTest extends PHPUnit_Framework_TestCase
 
         $index1 = Zend_Search_Lucene::open(dirname(__FILE__) . '/_index/_files');
         $this->assertTrue($index1 instanceof Zend_Search_Lucene_Interface);
+        unset($index1);
 
         $this->_clearDirectory(dirname(__FILE__) . '/_index/_files');
     }
@@ -381,6 +382,7 @@ class Zend_Search_Lucene_LuceneTest extends PHPUnit_Framework_TestCase
 
         $hits = $index2->find('submitting');
         $this->assertEquals(count($hits), 3);
+        unset($index2);
 
         $this->_clearDirectory(dirname(__FILE__) . '/_index/_files');
     }
@@ -466,6 +468,7 @@ class Zend_Search_Lucene_LuceneTest extends PHPUnit_Framework_TestCase
         $this->assertTrue($index->currentTerm() === null);
 
         $index->closeTermsStream();
+        unset($index);
 
         $this->_clearDirectory(dirname(__FILE__) . '/_index/_files');
     }
@@ -490,6 +493,7 @@ class Zend_Search_Lucene_LuceneTest extends PHPUnit_Framework_TestCase
         $this->assertTrue($index->currentTerm() === null);
 
         $index->closeTermsStream();
+        unset($index);
 
         $this->_clearDirectory(dirname(__FILE__) . '/_index/_files');
     }
@@ -514,6 +518,39 @@ class Zend_Search_Lucene_LuceneTest extends PHPUnit_Framework_TestCase
         $this->assertTrue($index->currentTerm() == new Zend_Search_Lucene_Index_Term('word', 'contents'));
 
         $index->closeTermsStream();
+        unset($index);
+
+        $this->_clearDirectory(dirname(__FILE__) . '/_index/_files');
+    }
+
+    /**
+     * @group ZF-7518
+     */
+    public function testTermsStreamInterfaceSkipToMatchedTerm()
+    {
+        $index = Zend_Search_Lucene::create(dirname(__FILE__) . '/_index/_files');
+
+        $doc = new Zend_Search_Lucene_Document();
+        $doc->addField(Zend_Search_Lucene_Field::Keyword('test', 'f'));
+        $index->addDocument($doc);
+
+        unset($index);
+
+
+        $index = Zend_Search_Lucene::open(dirname(__FILE__) . '/_index/_files');
+
+        $hits = $index->find('test:[a TO t]');
+        $this->assertEquals(1, count($hits));
+        $this->assertEquals(0, reset($hits)->id);
+
+        $hits = $index->find('test:f');
+        $this->assertEquals(1, count($hits));
+        $this->assertEquals(0, reset($hits)->id);
+
+        $hits = $index->find('test:g');
+        $this->assertEquals(0, count($hits));
+
+        unset($index);
 
         $this->_clearDirectory(dirname(__FILE__) . '/_index/_files');
     }
@@ -533,6 +570,7 @@ class Zend_Search_Lucene_LuceneTest extends PHPUnit_Framework_TestCase
         $index->addDocument($document);
 
         $this->assertFalse($index->isDeleted(0));
+        unset($index);
 
         $this->_clearDirectory(dirname(__FILE__) . '/_index/_files');
     }