LUCENE-5879: fix corner case in auto-prefix intersect

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1672042 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2015-04-08 09:19:12 +00:00
parent a986e4099e
commit 2e1c25e6ce
2 changed files with 35 additions and 15 deletions

View File

@ -119,7 +119,7 @@ final class IntersectTermsEnumFrame {
} }
void loadNextFloorBlock() throws IOException { void loadNextFloorBlock() throws IOException {
assert numFollowFloorBlocks > 0; assert numFollowFloorBlocks > 0: "nextFloorLabel=" + nextFloorLabel;
//if (DEBUG) System.out.println(" loadNextFloorBlock transition.min=" + transition.min); //if (DEBUG) System.out.println(" loadNextFloorBlock transition.min=" + transition.min);
do { do {
@ -157,7 +157,7 @@ final class IntersectTermsEnumFrame {
//xif (DEBUG) System.out.println(" load fp=" + fp + " fpOrig=" + fpOrig + " frameIndexData=" + frameIndexData + " trans=" + (transitions.length != 0 ? transitions[0] : "n/a" + " state=" + state)); //xif (DEBUG) System.out.println(" load fp=" + fp + " fpOrig=" + fpOrig + " frameIndexData=" + frameIndexData + " trans=" + (transitions.length != 0 ? transitions[0] : "n/a" + " state=" + state));
if (frameIndexData != null && transitionCount != 0) { if (frameIndexData != null) {
// Floor frame // Floor frame
if (floorData.length < frameIndexData.length) { if (floorData.length < frameIndexData.length) {
this.floorData = new byte[ArrayUtil.oversize(frameIndexData.length, 1)]; this.floorData = new byte[ArrayUtil.oversize(frameIndexData.length, 1)];
@ -172,9 +172,9 @@ final class IntersectTermsEnumFrame {
nextFloorLabel = floorDataReader.readByte() & 0xff; nextFloorLabel = floorDataReader.readByte() & 0xff;
//if (DEBUG) System.out.println(" numFollowFloorBlocks=" + numFollowFloorBlocks + " nextFloorLabel=" + nextFloorLabel); //if (DEBUG) System.out.println(" numFollowFloorBlocks=" + numFollowFloorBlocks + " nextFloorLabel=" + nextFloorLabel);
// If current state is accept, we must process // If current state is not accept, and has transitions, we must process
// first block in case it has empty suffix: // first block in case it has empty suffix:
if (!ite.runAutomaton.isAccept(state)) { if (ite.runAutomaton.isAccept(state) == false && transitionCount != 0) {
// Maybe skip floor blocks: // Maybe skip floor blocks:
assert transitionIndex == 0: "transitionIndex=" + transitionIndex; assert transitionIndex == 0: "transitionIndex=" + transitionIndex;
while (numFollowFloorBlocks != 0 && nextFloorLabel <= transition.min) { while (numFollowFloorBlocks != 0 && nextFloorLabel <= transition.min) {

View File

@ -399,9 +399,11 @@ public class TestTermRangeQuery extends LuceneTestCase {
} }
} }
//System.out.println("start " + startTerm + " inclusive? " + startInclusive); if (VERBOSE) {
//System.out.println("end " + endTerm + " inclusive? " + endInclusive); System.out.println("start " + startTerm + " inclusive? " + startInclusive);
//System.out.println("actual count " + actualCount); System.out.println("end " + endTerm + " inclusive? " + endInclusive);
System.out.println("actual count " + actualCount);
}
Directory dir = newDirectory(); Directory dir = newDirectory();
IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random())); IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random()));
@ -411,37 +413,52 @@ public class TestTermRangeQuery extends LuceneTestCase {
int minTermsAutoPrefix = TestUtil.nextInt(random(), 2, 100); int minTermsAutoPrefix = TestUtil.nextInt(random(), 2, 100);
int maxTermsAutoPrefix = random().nextBoolean() ? Math.max(2, (minTermsAutoPrefix-1)*2 + random().nextInt(100)) : Integer.MAX_VALUE; int maxTermsAutoPrefix = random().nextBoolean() ? Math.max(2, (minTermsAutoPrefix-1)*2 + random().nextInt(100)) : Integer.MAX_VALUE;
//System.out.println("minTermsAutoPrefix " + minTermsAutoPrefix); if (VERBOSE) {
//System.out.println("maxTermsAutoPrefix " + maxTermsAutoPrefix); System.out.println("minTermsAutoPrefix " + minTermsAutoPrefix);
System.out.println("maxTermsAutoPrefix " + maxTermsAutoPrefix);
}
iwc.setCodec(TestUtil.alwaysPostingsFormat(new AutoPrefixPostingsFormat(minTermsInBlock, maxTermsInBlock, iwc.setCodec(TestUtil.alwaysPostingsFormat(new AutoPrefixPostingsFormat(minTermsInBlock, maxTermsInBlock,
minTermsAutoPrefix, maxTermsAutoPrefix))); minTermsAutoPrefix, maxTermsAutoPrefix)));
RandomIndexWriter w = new RandomIndexWriter(random(), dir, iwc); RandomIndexWriter w = new RandomIndexWriter(random(), dir, iwc);
//System.out.println("TEST: index terms"); if (VERBOSE) {
System.out.println("TEST: index terms");
}
for (String term : randomTerms) { for (String term : randomTerms) {
Document doc = new Document(); Document doc = new Document();
doc.add(new StringField("field", term, Field.Store.NO)); doc.add(new StringField("field", term, Field.Store.NO));
w.addDocument(doc); w.addDocument(doc);
//System.out.println(" " + term); if (VERBOSE) {
System.out.println(" " + term);
}
}
if (VERBOSE) {
System.out.println("TEST: now force merge");
} }
//System.out.println("TEST: now force merge");
w.forceMerge(1); w.forceMerge(1);
IndexReader r = w.getReader(); IndexReader r = w.getReader();
final Terms terms = MultiFields.getTerms(r, "field"); final Terms terms = MultiFields.getTerms(r, "field");
IndexSearcher s = new IndexSearcher(r); IndexSearcher s = new IndexSearcher(r);
final int finalActualCount = actualCount; final int finalActualCount = actualCount;
//System.out.println("start=" + startTerm + " end=" + endTerm + " startIncl=" + startInclusive + " endIncl=" + endInclusive); if (VERBOSE) {
System.out.println("start=" + startTerm + " end=" + endTerm + " startIncl=" + startInclusive + " endIncl=" + endInclusive);
}
TermRangeQuery q = new TermRangeQuery("field", new BytesRef(startTerm), new BytesRef(endTerm), startInclusive, endInclusive) { TermRangeQuery q = new TermRangeQuery("field", new BytesRef(startTerm), new BytesRef(endTerm), startInclusive, endInclusive) {
public TermRangeQuery checkTerms() throws IOException { public TermRangeQuery checkTerms() throws IOException {
TermsEnum termsEnum = getTermsEnum(terms, new AttributeSource()); TermsEnum termsEnum = getTermsEnum(terms, new AttributeSource());
int count = 0; int count = 0;
while (termsEnum.next() != null) { while (termsEnum.next() != null) {
//System.out.println("got term: " + termsEnum.term().utf8ToString()); if (VERBOSE) {
System.out.println("got term: " + termsEnum.term().utf8ToString());
}
count++; count++;
} }
//System.out.println("count " + count + " vs finalActualCount=" + finalActualCount); if (VERBOSE) {
System.out.println("count " + count + " vs finalActualCount=" + finalActualCount);
}
// Auto-prefix term(s) should have kicked in, so we should have visited fewer than the total number of aa* terms: // Auto-prefix term(s) should have kicked in, so we should have visited fewer than the total number of aa* terms:
assertTrue(count < finalActualCount); assertTrue(count < finalActualCount);
@ -456,6 +473,9 @@ public class TestTermRangeQuery extends LuceneTestCase {
q.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_BOOLEAN_REWRITE); q.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_BOOLEAN_REWRITE);
} }
if (VERBOSE) {
System.out.println("TEST: use rewrite method " + q.getRewriteMethod());
}
assertEquals(actualCount, s.search(q, 1).totalHits); assertEquals(actualCount, s.search(q, 1).totalHits);
// Test when min == max: // Test when min == max: