lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r696013 - in /lucene/java/trunk/src: java/org/apache/lucene/search/spans/SpanScorer.java test/org/apache/lucene/search/spans/TestSpans.java
Date Tue, 16 Sep 2008 19:25:08 GMT
Author: mikemccand
Date: Tue Sep 16 12:25:07 2008
New Revision: 696013

URL: http://svn.apache.org/viewvc?rev=696013&view=rev
Log:
LUCENE-1379: fix corner case when Similarity.sloppyFreq() returns 0.0 the last matching doc
is skipped

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanScorer.java
    lucene/java/trunk/src/test/org/apache/lucene/search/spans/TestSpans.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanScorer.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanScorer.java?rev=696013&r1=696012&r2=696013&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanScorer.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanScorer.java Tue Sep 16 12:25:07
2008
@@ -77,12 +77,12 @@
     }
     doc = spans.doc();
     freq = 0.0f;
-    while (more && doc == spans.doc()) {
+    do {
       int matchLength = spans.end() - spans.start();
       freq += getSimilarity().sloppyFreq(matchLength);
       more = spans.next();
-    }
-    return more || (freq != 0);
+    } while (more && (doc == spans.doc()));
+    return true;
   }
 
   public int doc() { return doc; }

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/spans/TestSpans.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/spans/TestSpans.java?rev=696013&r1=696012&r2=696013&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/spans/TestSpans.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/spans/TestSpans.java Tue Sep 16 12:25:07
2008
@@ -20,6 +20,10 @@
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.CheckHits;
+import org.apache.lucene.search.Similarity;
+import org.apache.lucene.search.DefaultSimilarity;
+import org.apache.lucene.search.Scorer;
+import org.apache.lucene.search.Searcher;
 import org.apache.lucene.store.RAMDirectory;
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.Term;
@@ -355,4 +359,34 @@
     tstNextSpans(spans, 11, 5, 6);
     assertFalse("final next", spans.next());
   }
+
+  public void testSpanScorerZeroSloppyFreq() throws Exception {
+    boolean ordered = true;
+    int slop = 1;
+
+    final Similarity sim = new DefaultSimilarity() {
+      public float sloppyFreq(int distance) {
+        return 0.0f;
+      }
+    };
+
+    SpanNearQuery snq = new SpanNearQuery(
+                              new SpanQuery[] {
+                                makeSpanTermQuery("t1"),
+                                makeSpanTermQuery("t2") },
+                              slop,
+                              ordered) {
+      public Similarity getSimilarity(Searcher s) {
+        return sim;
+      }
+    };
+
+    Scorer spanScorer = snq.weight(searcher).scorer(searcher.getIndexReader());
+
+    assertTrue("first doc", spanScorer.next());
+    assertEquals("first doc number", spanScorer.doc(), 11);
+    float score = spanScorer.score();
+    assertTrue("first doc score should be zero, " + score, score == 0.0f);
+    assertTrue("no second doc", ! spanScorer.next());
+  }
 }



Mime
View raw message