Index: src/test/org/apache/lucene/search/QueryUtils.java =================================================================== --- src/test/org/apache/lucene/search/QueryUtils.java (revision 545026) +++ src/test/org/apache/lucene/search/QueryUtils.java (working copy) @@ -84,6 +84,7 @@ IndexSearcher is = (IndexSearcher)s; checkFirstSkipTo(q1,is); checkSkipTo(q1,is); + checkSkipToCurrent(q1,is); } checkExplanations(q1,s); } @@ -195,4 +196,28 @@ if (more) TestCase.assertFalse("query's last doc was "+lastDoc[0]+" but skipTo("+(lastDoc[0]+1)+") got to "+scorer.doc(),more); } + + // check that skipping always goes "beyond current" doc (by skipTo()'s specs). + private static void checkSkipToCurrent(final Query q, final IndexSearcher s) throws IOException { + //System.out.println("checkSkipToCurrent: "+q); + s.search(q,new HitCollector() { + public void collect(int doc, float score) { + //System.out.println("doc="+doc); + try { + Weight w = q.weight(s); + Scorer scorer = w.scorer(s.getIndexReader()); + TestCase.assertTrue("query collected doc "+doc+" but first skipTo("+doc+") says no more hits!",scorer.skipTo(doc)); + int sdoc = scorer.doc(); + TestCase.assertEquals("query collected doc "+doc+" but first skipTo("+doc+") found doc "+sdoc+"!",doc,sdoc); + if (scorer.skipTo(doc)) { + int sdoc2 = scorer.doc(); + TestCase.assertFalse("second call to skipTo("+doc+") found doc "+sdoc2+"!",doc==sdoc2); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + } + }); + } + }