lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r358089 - /lucene/java/trunk/src/java/org/apache/lucene/search/MatchAllDocsQuery.java
Date Tue, 20 Dec 2005 20:14:33 GMT
Author: yonik
Date: Tue Dec 20 12:14:30 2005
New Revision: 358089

URL: http://svn.apache.org/viewcvs?rev=358089&view=rev
Log:
fix score to include boost and query normalization: LUCENE-450

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/search/MatchAllDocsQuery.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/MatchAllDocsQuery.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/java/org/apache/lucene/search/MatchAllDocsQuery.java?rev=358089&r1=358088&r2=358089&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/MatchAllDocsQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/MatchAllDocsQuery.java Tue Dec 20
12:14:30 2005
@@ -37,32 +37,31 @@
 
   private class MatchAllScorer extends Scorer {
 
-    IndexReader reader;
-    int count;
-    int maxDoc;
+    final IndexReader reader;
+    int id;
+    final int maxId;
+    final float score;
 
-    MatchAllScorer(IndexReader reader, Similarity similarity) {
+    MatchAllScorer(IndexReader reader, Similarity similarity, Weight w) {
       super(similarity);
       this.reader = reader;
-      count = -1;
-      maxDoc = reader.maxDoc();
+      id = -1;
+      maxId = reader.maxDoc() - 1;
+      score = w.getValue();
     }
 
-    public int doc() {
-      return count;
+    public Explanation explain(int doc) {
+      return null; // not called... see MatchAllDocsWeight.explain()
     }
 
-    public Explanation explain(int doc) {
-      Explanation explanation = new Explanation();
-      explanation.setValue(1.0f);
-      explanation.setDescription("MatchAllDocsQuery");
-      return explanation;
+    public int doc() {
+      return id;
     }
 
     public boolean next() {
-      while (count < (maxDoc - 1)) {
-        count++;
-        if (!reader.isDeleted(count)) {
+      while (id < maxId) {
+        id++;
+        if (!reader.isDeleted(id)) {
           return true;
         }
       }
@@ -70,11 +69,11 @@
     }
 
     public float score() {
-      return 1.0f;
+      return score;
     }
 
     public boolean skipTo(int target) {
-      count = target - 1;
+      id = target - 1;
       return next();
     }
 
@@ -82,6 +81,8 @@
 
   private class MatchAllDocsWeight implements Weight {
     private Searcher searcher;
+    private float queryWeight;
+    private float queryNorm;
 
     public MatchAllDocsWeight(Searcher searcher) {
       this.searcher = searcher;
@@ -96,29 +97,32 @@
     }
 
     public float getValue() {
-      return 1.0f;
+      return queryWeight;
     }
 
     public float sumOfSquaredWeights() {
-      return 1.0f;
+      queryWeight = getBoost();
+      return queryWeight * queryWeight;
     }
 
     public void normalize(float queryNorm) {
+      this.queryNorm = queryNorm;
+      queryWeight *= this.queryNorm;
     }
 
     public Scorer scorer(IndexReader reader) {
-      return new MatchAllScorer(reader, getSimilarity(searcher));
+      return new MatchAllScorer(reader, getSimilarity(searcher), this);
     }
 
     public Explanation explain(IndexReader reader, int doc) {
       // explain query weight
       Explanation queryExpl = new Explanation();
-      queryExpl.setDescription("MatchAllDocsQuery:");
-
-      Explanation boostExpl = new Explanation(getBoost(), "boost");
-      if (getBoost() != 1.0f)
-        queryExpl.addDetail(boostExpl);
-      queryExpl.setValue(boostExpl.getValue());
+      queryExpl.setDescription("MatchAllDocsQuery, product of:");
+      queryExpl.setValue(getValue());
+      if (getBoost() != 1.0f) {
+        queryExpl.addDetail(new Explanation(getBoost(),"boost"));
+      }
+      queryExpl.addDetail(new Explanation(queryNorm,"queryNorm"));
 
       return queryExpl;
     }



Mime
View raw message