diff --git a/src/java/org/apache/lucene/search/SloppyPhraseScorer.java b/src/java/org/apache/lucene/search/SloppyPhraseScorer.java --- a/src/java/org/apache/lucene/search/SloppyPhraseScorer.java +++ b/src/java/org/apache/lucene/search/SloppyPhraseScorer.java @@ -69,7 +69,7 @@ done = true; // ran out of a term -- done break; } - tpsDiffer = !pp.repeats || (pp = termPositionsDiffer(pp))==null; + tpsDiffer = !pp.repeats || termPositionsDiffer(pp)==null; } int matchLength = end - start; diff --git a/src/test/org/apache/lucene/search/TestSloppyPhraseQuery.java b/src/test/org/apache/lucene/search/TestSloppyPhraseQuery.java --- a/src/test/org/apache/lucene/search/TestSloppyPhraseQuery.java +++ b/src/test/org/apache/lucene/search/TestSloppyPhraseQuery.java @@ -36,6 +36,7 @@ private static final Document DOC_1 = makeDocument("X " + S_1 + " Y"); private static final Document DOC_2 = makeDocument("X " + S_2 + " Y"); + private static final Document DOC_3 = makeDocument("X " + S_1 + " A Y"); private static final PhraseQuery QUERY_1 = makePhraseQuery( S_1 ); private static final PhraseQuery QUERY_2 = makePhraseQuery( S_2 ); @@ -72,6 +73,16 @@ public void testDoc2_Query2_All_Slops_Should_match() throws Exception { for (int slop=0; slop<30; slop++) { checkPhraseQuery(DOC_2, QUERY_2, slop, 1); + } + } + + /** + * Test DOC_3 and QUERY_1. + * QUERY_1 has an exact match to DOC_3, so all slop values should succeed. + */ + public void testDoc3_Query1_All_Slops_Should_match() throws Exception { + for (int slop=0; slop<30; slop++) { + checkPhraseQuery(DOC_3, QUERY_1, slop, 1); } }