jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r941752 - /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ParentAxisQuery.java
Date Thu, 06 May 2010 14:24:57 GMT
Author: mreutegg
Date: Thu May  6 14:24:57 2010
New Revision: 941752

URL: http://svn.apache.org/viewvc?rev=941752&view=rev
Log:
JCR-2624: Reduce memory usage of ParentAxisScorer

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ParentAxisQuery.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ParentAxisQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ParentAxisQuery.java?rev=941752&r1=941751&r2=941752&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ParentAxisQuery.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ParentAxisQuery.java
Thu May  6 14:24:57 2010
@@ -16,35 +16,30 @@
  */
 package org.apache.jackrabbit.core.query.lucene;
 
-import org.apache.lucene.search.Query;
-import org.apache.lucene.search.Scorer;
-import org.apache.lucene.search.Weight;
-import org.apache.lucene.search.Searcher;
-import org.apache.lucene.search.Explanation;
-import org.apache.lucene.search.Similarity;
-import org.apache.lucene.search.HitCollector;
-import org.apache.lucene.index.IndexReader;
-import org.apache.jackrabbit.spi.Name;
-import org.apache.jackrabbit.core.query.lucene.hits.ScorerHits;
-import org.apache.jackrabbit.core.query.lucene.hits.Hits;
-
 import java.io.IOException;
 import java.util.BitSet;
-import java.util.Map;
 import java.util.HashMap;
+import java.util.Map;
 import java.util.Set;
 
+import org.apache.jackrabbit.core.query.lucene.hits.Hits;
+import org.apache.jackrabbit.core.query.lucene.hits.ScorerHits;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.search.Explanation;
+import org.apache.lucene.search.HitCollector;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.Scorer;
+import org.apache.lucene.search.Searcher;
+import org.apache.lucene.search.Similarity;
+import org.apache.lucene.search.Weight;
+
 /**
  * <code>ParentAxisQuery</code> selects the parent nodes of a context query.
  */
 class ParentAxisQuery extends Query {
 
     /**
-     * Default score is 1.0f.
-     */
-    private static final Float DEFAULT_SCORE = 1.0f;
-
-    /**
      * The context query
      */
     private final Query contextQuery;
@@ -235,8 +230,8 @@ class ParentAxisQuery extends Query {
 
         /**
          * Map that contains the scores from matching documents from the context
-         * query. To save memory only scores that are not equal to 1.0f are put
-         * to this map.
+         * query. To save memory only scores that are not equal to the score
+         * value of the first match are put to this map.
          * <p/>
          * key=[Integer] id of selected document from context query<br>
          * value=[Float] score for that document
@@ -249,6 +244,11 @@ class ParentAxisQuery extends Query {
         private int nextDoc = -1;
 
         /**
+         * The score of the first match.
+         */
+        private Float firstScore;
+
+        /**
          * Creates a new <code>ParentAxisScorer</code>.
          *
          * @param similarity the <code>Similarity</code> instance to use.
@@ -288,7 +288,7 @@ class ParentAxisQuery extends Query {
         public float score() throws IOException {
             Float score = scores.get(nextDoc);
             if (score == null) {
-                score = DEFAULT_SCORE;
+                score = firstScore;
             }
             return score;
         }
@@ -327,14 +327,18 @@ class ParentAxisQuery extends Query {
                             if (docs.length == 1) {
                                 // optimize single value
                                 hits.set(docs[0]);
-                                if (score != DEFAULT_SCORE) {
-                                    scores.put(docs[0], score);
+                                if (firstScore == null) {
+                                    firstScore = score;
+                                } else if (firstScore != score) {
+                                    scores.put(doc, score);
                                 }
                             } else {
                                 for (int docNum : docs) {
                                     hits.set(docNum);
-                                    if (score != DEFAULT_SCORE) {
-                                        scores.put(docNum, score);
+                                    if (firstScore == null) {
+                                        firstScore = score;
+                                    } else if (firstScore != score) {
+                                        scores.put(doc, score);
                                     }
                                 }
                             }



Mime
View raw message