From a275ca2bb5a5cf6eac711e7e3214733cf3c17e5c Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Thu, 5 Mar 2015 08:54:37 +0000 Subject: [PATCH] LUCENE-6338: s/skipTo/advance/ and removed duplicate assertion. git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1664279 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/lucene/search/AssertingScorer.java | 3 +-- .../org/apache/lucene/search/QueryUtils.java | 20 +++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/lucene/test-framework/src/java/org/apache/lucene/search/AssertingScorer.java b/lucene/test-framework/src/java/org/apache/lucene/search/AssertingScorer.java index 79cbd741a73..d29b63a6acd 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/search/AssertingScorer.java +++ b/lucene/test-framework/src/java/org/apache/lucene/search/AssertingScorer.java @@ -93,8 +93,7 @@ public class AssertingScorer extends Scorer { public float score() throws IOException { assert iterating(); final float score = in.score(); - assert !Float.isNaN(score); - assert !Float.isNaN(score); + assert !Float.isNaN(score) : "NaN score for in="+in; return score; } diff --git a/lucene/test-framework/src/java/org/apache/lucene/search/QueryUtils.java b/lucene/test-framework/src/java/org/apache/lucene/search/QueryUtils.java index 68e06f89902..aa53d17a597 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/search/QueryUtils.java +++ b/lucene/test-framework/src/java/org/apache/lucene/search/QueryUtils.java @@ -214,7 +214,7 @@ public class QueryUtils { return new AllDeletedFilterReader(LuceneTestCase.getOnlySegmentReader(reader)); } - /** alternate scorer skipTo(),skipTo(),next(),next(),skipTo(),skipTo(), etc + /** alternate scorer advance(),advance(),next(),next(),advance(),advance(), etc * and ensure a hitcollector receives same docs and scores */ public static void checkSkipTo(final Query q, final IndexSearcher s) throws IOException { @@ -319,7 +319,7 @@ public class QueryUtils { Scorer scorer = w.scorer(ctx, ctx.reader().getLiveDocs()); if (scorer != null) { boolean more = scorer.advance(lastDoc[0] + 1) != DocIdSetIterator.NO_MORE_DOCS; - Assert.assertFalse("query's last doc was "+ lastDoc[0] +" but skipTo("+(lastDoc[0]+1)+") got to "+scorer.docID(),more); + Assert.assertFalse("query's last doc was "+ lastDoc[0] +" but advance("+(lastDoc[0]+1)+") got to "+scorer.docID(),more); } leafPtr++; } @@ -341,7 +341,7 @@ public class QueryUtils { Scorer scorer = w.scorer(ctx, ctx.reader().getLiveDocs()); if (scorer != null) { boolean more = scorer.advance(lastDoc[0] + 1) != DocIdSetIterator.NO_MORE_DOCS; - Assert.assertFalse("query's last doc was "+ lastDoc[0] +" but skipTo("+(lastDoc[0]+1)+") got to "+scorer.docID(),more); + Assert.assertFalse("query's last doc was "+ lastDoc[0] +" but advance("+(lastDoc[0]+1)+") got to "+scorer.docID(),more); } } } @@ -370,11 +370,11 @@ public class QueryUtils { for (int i=lastDoc[0]+1; i<=doc; i++) { Weight w = s.createNormalizedWeight(q, true); Scorer scorer = w.scorer(context.get(leafPtr), liveDocs); - Assert.assertTrue("query collected "+doc+" but skipTo("+i+") says no more docs!",scorer.advance(i) != DocIdSetIterator.NO_MORE_DOCS); - Assert.assertEquals("query collected "+doc+" but skipTo("+i+") got to "+scorer.docID(),doc,scorer.docID()); - float skipToScore = scorer.score(); - Assert.assertEquals("unstable skipTo("+i+") score!",skipToScore,scorer.score(),maxDiff); - Assert.assertEquals("query assigned doc "+doc+" a score of <"+score+"> but skipTo("+i+") has <"+skipToScore+">!",score,skipToScore,maxDiff); + Assert.assertTrue("query collected "+doc+" but advance("+i+") says no more docs!",scorer.advance(i) != DocIdSetIterator.NO_MORE_DOCS); + Assert.assertEquals("query collected "+doc+" but advance("+i+") got to "+scorer.docID(),doc,scorer.docID()); + float advanceScore = scorer.score(); + Assert.assertEquals("unstable advance("+i+") score!",advanceScore,scorer.score(),maxDiff); + Assert.assertEquals("query assigned doc "+doc+" a score of <"+score+"> but advance("+i+") has <"+advanceScore+">!",score,advanceScore,maxDiff); // Hurry things along if they are going slow (eg // if you got SimpleText codec this will kick in): @@ -405,7 +405,7 @@ public class QueryUtils { Scorer scorer = w.scorer((LeafReaderContext)indexSearcher.getTopReaderContext(), previousReader.getLiveDocs()); if (scorer != null) { boolean more = scorer.advance(lastDoc[0] + 1) != DocIdSetIterator.NO_MORE_DOCS; - Assert.assertFalse("query's last doc was "+ lastDoc[0] +" but skipTo("+(lastDoc[0]+1)+") got to "+scorer.docID(),more); + Assert.assertFalse("query's last doc was "+ lastDoc[0] +" but advance("+(lastDoc[0]+1)+") got to "+scorer.docID(),more); } leafPtr++; } @@ -426,7 +426,7 @@ public class QueryUtils { Scorer scorer = w.scorer((LeafReaderContext)indexSearcher.getTopReaderContext(), previousReader.getLiveDocs()); if (scorer != null) { boolean more = scorer.advance(lastDoc[0] + 1) != DocIdSetIterator.NO_MORE_DOCS; - Assert.assertFalse("query's last doc was "+ lastDoc[0] +" but skipTo("+(lastDoc[0]+1)+") got to "+scorer.docID(),more); + Assert.assertFalse("query's last doc was "+ lastDoc[0] +" but advance("+(lastDoc[0]+1)+") got to "+scorer.docID(),more); } } }