mirror of https://github.com/apache/lucene.git
ParallelTermEnum.next() fails to advance properly to new fields: LUCENE-607
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@415793 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
20240390e3
commit
c81983524f
|
@ -45,6 +45,9 @@ Bug fixes
|
||||||
Explanations match up with the real scores.
|
Explanations match up with the real scores.
|
||||||
(Chris Hostetter)
|
(Chris Hostetter)
|
||||||
|
|
||||||
|
8. LUCENE-607: ParallelReader's TermEnum fails to advance properly to
|
||||||
|
new fields (Chuck Williams, Christian Kohlschuetter via Yonik Seeley)
|
||||||
|
|
||||||
Optimizations
|
Optimizations
|
||||||
|
|
||||||
1. LUCENE-586: TermDocs.skipTo() is now more efficient for multi-segment
|
1. LUCENE-586: TermDocs.skipTo() is now more efficient for multi-segment
|
||||||
|
|
|
@ -261,6 +261,7 @@ public class ParallelReader extends IndexReader {
|
||||||
|
|
||||||
private class ParallelTermEnum extends TermEnum {
|
private class ParallelTermEnum extends TermEnum {
|
||||||
private String field;
|
private String field;
|
||||||
|
private Iterator fieldIterator;
|
||||||
private TermEnum termEnum;
|
private TermEnum termEnum;
|
||||||
|
|
||||||
public ParallelTermEnum() throws IOException {
|
public ParallelTermEnum() throws IOException {
|
||||||
|
@ -277,26 +278,31 @@ public class ParallelReader extends IndexReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean next() throws IOException {
|
public boolean next() throws IOException {
|
||||||
if (termEnum == null)
|
if (termEnum==null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
boolean next = termEnum.next();
|
// another term in this field?
|
||||||
|
if (termEnum.next() && termEnum.term().field()==field)
|
||||||
// still within field?
|
|
||||||
if (next && termEnum.term().field() == field)
|
|
||||||
return true; // yes, keep going
|
return true; // yes, keep going
|
||||||
|
|
||||||
termEnum.close(); // close old termEnum
|
termEnum.close(); // close old termEnum
|
||||||
|
|
||||||
// find the next field, if any
|
// find the next field with terms, if any
|
||||||
field = (String)fieldToReader.tailMap(field).firstKey();
|
if (fieldIterator==null) {
|
||||||
if (field != null) {
|
fieldIterator = fieldToReader.tailMap(field).keySet().iterator();
|
||||||
termEnum = ((IndexReader)fieldToReader.get(field)).terms();
|
fieldIterator.next(); // Skip field to get next one
|
||||||
return true;
|
}
|
||||||
|
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
|
return false; // no more fields
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Term term() {
|
public Term term() {
|
||||||
|
|
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue