lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r415793 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/index/ParallelReader.java src/test/org/apache/lucene/index/TestParallelTermEnum.java
Date Tue, 20 Jun 2006 20:40:06 GMT
Author: yonik
Date: Tue Jun 20 13:40:06 2006
New Revision: 415793

URL: http://svn.apache.org/viewvc?rev=415793&view=rev
Log:
ParallelTermEnum.next() fails to advance properly to new fields: LUCENE-607

Added:
    lucene/java/trunk/src/test/org/apache/lucene/index/TestParallelTermEnum.java   (with props)
Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/index/ParallelReader.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?rev=415793&r1=415792&r2=415793&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Tue Jun 20 13:40:06 2006
@@ -44,6 +44,9 @@
  7. LUCENE-557: Fixes to BooleanQuery and FilteredQuery so that the score
     Explanations match up with the real scores.
     (Chris Hostetter)
+
+ 8. LUCENE-607: ParallelReader's TermEnum fails to advance properly to
+    new fields (Chuck Williams, Christian Kohlschuetter via Yonik Seeley)
         
 Optimizations
 

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/ParallelReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/ParallelReader.java?rev=415793&r1=415792&r2=415793&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/ParallelReader.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/ParallelReader.java Tue Jun 20 13:40:06
2006
@@ -261,6 +261,7 @@
 
   private class ParallelTermEnum extends TermEnum {
     private String field;
+    private Iterator fieldIterator;
     private TermEnum termEnum;
 
     public ParallelTermEnum() throws IOException {
@@ -277,26 +278,31 @@
     }
 
     public boolean next() throws IOException {
-      if (termEnum == null)
+      if (termEnum==null)
         return false;
 
-      boolean next = termEnum.next();
-
-      // still within field?
-      if (next && termEnum.term().field() == field)
+      // another term in this field?
+      if (termEnum.next() && termEnum.term().field()==field)
         return true;                              // yes, keep going
 
       termEnum.close();                           // close old termEnum
 
-      // find the next field, if any
-      field = (String)fieldToReader.tailMap(field).firstKey();
-      if (field != null) {
-        termEnum = ((IndexReader)fieldToReader.get(field)).terms();
-        return true;
+      // find the next field with terms, if any
+      if (fieldIterator==null) {
+        fieldIterator = fieldToReader.tailMap(field).keySet().iterator();
+        fieldIterator.next();                     // Skip field to get next one
       }
-
+      while (fieldIterator.hasNext()) {
+        field = (String) fieldIterator.next();
+        termEnum = ((IndexReader)fieldToReader.get(field)).terms(new Term(field, ""));
+        Term term = termEnum.term();
+        if (term!=null && term.field()==field)
+          return true;
+        else
+          termEnum.close();
+      }
+ 
       return false;                               // no more fields
-
     }
 
     public Term term() {

Added: lucene/java/trunk/src/test/org/apache/lucene/index/TestParallelTermEnum.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestParallelTermEnum.java?rev=415793&view=auto
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestParallelTermEnum.java (added)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestParallelTermEnum.java Tue Jun 20
13:40:06 2006
@@ -0,0 +1,164 @@
+package org.apache.lucene.index;
+
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.apache.lucene.analysis.SimpleAnalyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.document.Field.Index;
+import org.apache.lucene.document.Field.Store;
+import org.apache.lucene.store.RAMDirectory;
+
+public class TestParallelTermEnum extends TestCase {
+    private IndexReader ir1;
+    private IndexReader ir2;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        Document doc;
+
+        RAMDirectory rd1 = new RAMDirectory();
+        IndexWriter iw1 = new IndexWriter(rd1, new SimpleAnalyzer(), true);
+
+        doc = new Document();
+        doc.add(new Field("field1", "the quick brown fox jumps", Store.YES,
+            Index.TOKENIZED));
+        doc.add(new Field("field2", "the quick brown fox jumps", Store.YES,
+            Index.TOKENIZED));
+        doc.add(new Field("field4", "", Store.NO, Index.TOKENIZED));
+        iw1.addDocument(doc);
+
+        iw1.close();
+        RAMDirectory rd2 = new RAMDirectory();
+        IndexWriter iw2 = new IndexWriter(rd2, new SimpleAnalyzer(), true);
+
+        doc = new Document();
+        doc.add(new Field("field0", "", Store.NO, Index.TOKENIZED));
+        doc.add(new Field("field1", "the fox jumps over the lazy dog",
+            Store.YES, Index.TOKENIZED));
+        doc.add(new Field("field3", "the fox jumps over the lazy dog",
+            Store.YES, Index.TOKENIZED));
+        iw2.addDocument(doc);
+
+        iw2.close();
+
+        this.ir1 = IndexReader.open(rd1);
+        this.ir2 = IndexReader.open(rd2);
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+
+        ir1.close();
+        ir2.close();
+    }
+
+    public void test1() throws IOException {
+        ParallelReader pr = new ParallelReader();
+        pr.add(ir1);
+        pr.add(ir2);
+
+        TermDocs td = pr.termDocs();
+
+        TermEnum te = pr.terms();
+        assertTrue(te.next());
+        assertEquals("field1:brown", te.term().toString());
+        td.seek(te.term());
+        assertTrue(td.next());
+        assertEquals(0, td.doc());
+        assertFalse(td.next());
+        assertTrue(te.next());
+        assertEquals("field1:fox", te.term().toString());
+        td.seek(te.term());
+        assertTrue(td.next());
+        assertEquals(0, td.doc());
+        assertFalse(td.next());
+        assertTrue(te.next());
+        assertEquals("field1:jumps", te.term().toString());
+        td.seek(te.term());
+        assertTrue(td.next());
+        assertEquals(0, td.doc());
+        assertFalse(td.next());
+        assertTrue(te.next());
+        assertEquals("field1:quick", te.term().toString());
+        td.seek(te.term());
+        assertTrue(td.next());
+        assertEquals(0, td.doc());
+        assertFalse(td.next());
+        assertTrue(te.next());
+        assertEquals("field1:the", te.term().toString());
+        td.seek(te.term());
+        assertTrue(td.next());
+        assertEquals(0, td.doc());
+        assertFalse(td.next());
+        assertTrue(te.next());
+        assertEquals("field2:brown", te.term().toString());
+        td.seek(te.term());
+        assertTrue(td.next());
+        assertEquals(0, td.doc());
+        assertFalse(td.next());
+        assertTrue(te.next());
+        assertEquals("field2:fox", te.term().toString());
+        td.seek(te.term());
+        assertTrue(td.next());
+        assertEquals(0, td.doc());
+        assertFalse(td.next());
+        assertTrue(te.next());
+        assertEquals("field2:jumps", te.term().toString());
+        td.seek(te.term());
+        assertTrue(td.next());
+        assertEquals(0, td.doc());
+        assertFalse(td.next());
+        assertTrue(te.next());
+        assertEquals("field2:quick", te.term().toString());
+        td.seek(te.term());
+        assertTrue(td.next());
+        assertEquals(0, td.doc());
+        assertFalse(td.next());
+        assertTrue(te.next());
+        assertEquals("field2:the", te.term().toString());
+        td.seek(te.term());
+        assertTrue(td.next());
+        assertEquals(0, td.doc());
+        assertFalse(td.next());
+        assertTrue(te.next());
+        assertEquals("field3:dog", te.term().toString());
+        td.seek(te.term());
+        assertTrue(td.next());
+        assertEquals(0, td.doc());
+        assertFalse(td.next());
+        assertTrue(te.next());
+        assertEquals("field3:fox", te.term().toString());
+        td.seek(te.term());
+        assertTrue(td.next());
+        assertEquals(0, td.doc());
+        assertFalse(td.next());
+        assertTrue(te.next());
+        assertEquals("field3:jumps", te.term().toString());
+        td.seek(te.term());
+        assertTrue(td.next());
+        assertEquals(0, td.doc());
+        assertFalse(td.next());
+        assertTrue(te.next());
+        assertEquals("field3:lazy", te.term().toString());
+        td.seek(te.term());
+        assertTrue(td.next());
+        assertEquals(0, td.doc());
+        assertFalse(td.next());
+        assertTrue(te.next());
+        assertEquals("field3:over", te.term().toString());
+        td.seek(te.term());
+        assertTrue(td.next());
+        assertEquals(0, td.doc());
+        assertFalse(td.next());
+        assertTrue(te.next());
+        assertEquals("field3:the", te.term().toString());
+        td.seek(te.term());
+        assertTrue(td.next());
+        assertEquals(0, td.doc());
+        assertFalse(td.next());
+        assertFalse(te.next());
+    }
+}

Propchange: lucene/java/trunk/src/test/org/apache/lucene/index/TestParallelTermEnum.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lucene/java/trunk/src/test/org/apache/lucene/index/TestParallelTermEnum.java
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message