jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r830246 - /jackrabbit/branches/1.6/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/RangeQuery.java
Date Tue, 27 Oct 2009 16:49:21 GMT
Author: mreutegg
Date: Tue Oct 27 16:49:21 2009
New Revision: 830246

URL: http://svn.apache.org/viewvc?rev=830246&view=rev
Log:
JCR-2353: Poor performance in range queries using dates
- reverting commit on branch

Modified:
    jackrabbit/branches/1.6/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/RangeQuery.java

Modified: jackrabbit/branches/1.6/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/RangeQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.6/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/RangeQuery.java?rev=830246&r1=830245&r2=830246&view=diff
==============================================================================
--- jackrabbit/branches/1.6/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/RangeQuery.java
(original)
+++ jackrabbit/branches/1.6/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/RangeQuery.java
Tue Oct 27 16:49:21 2009
@@ -16,43 +16,33 @@
  */
 package org.apache.jackrabbit.core.query.lucene;
 
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.Weight;
+import org.apache.lucene.search.Searcher;
+import org.apache.lucene.search.Scorer;
+import org.apache.lucene.search.Explanation;
+import org.apache.lucene.search.Similarity;
+import org.apache.lucene.search.ConstantScoreRangeQuery;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.TermEnum;
+import org.apache.lucene.index.TermDocs;
+
 import java.io.IOException;
-import java.util.ArrayList;
 import java.util.BitSet;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.HashMap;
 import java.util.Set;
 
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.Term;
-import org.apache.lucene.index.TermDocs;
-import org.apache.lucene.index.TermEnum;
-import org.apache.lucene.search.BooleanQuery;
-import org.apache.lucene.search.Explanation;
-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;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 /**
- * Implements a variant of the lucene class {@link org.apache.lucene.search.RangeQuery}.
- * This class does not rewrite to basic {@link org.apache.lucene.search.TermQuery}
- * but will calculate the matching documents itself. That way a
- * <code>TooManyClauses</code> can be avoided.
+ * Implements a lucene range query.
  */
 public class RangeQuery extends Query implements Transformable {
 
     /**
-     * Logger instance for this class.
-     */
-    private static final Logger log = LoggerFactory.getLogger(RangeQuery.class);
-
-    /**
      * The lower term. May be <code>null</code> if <code>upperTerm</code>
is not
      * <code>null</code>.
      */
@@ -76,12 +66,6 @@
     private int transform = TRANSFORM_NONE;
 
     /**
-     * The rewritten range query or <code>null</code> if the range spans more
-     * than {@link org.apache.lucene.search.BooleanQuery#maxClauseCount} terms.
-     */
-    private Query stdRangeQuery;
-
-    /**
      * Creates a new RangeQuery. The lower or the upper term may be
      * <code>null</code>, but not both!
      *
@@ -130,9 +114,8 @@
     }
 
     /**
-     * Tries to rewrite this query into a standard lucene RangeQuery.
-     * This rewrite might fail with a TooManyClauses exception. If that
-     * happens, we use our own implementation.
+     * Rewrites this query into a {@link ConstantScoreRangeQuery} if
+     * {@link #transform} is {@link #TRANSFORM_NONE}.
      *
      * @param reader the index reader.
      * @return the rewritten query or this query if rewriting is not possible.
@@ -140,16 +123,9 @@
      */
     public Query rewrite(IndexReader reader) throws IOException {
         if (transform == TRANSFORM_NONE) {
-            Query stdRangeQueryImpl
-                    = new org.apache.lucene.search.RangeQuery(lowerTerm, upperTerm, inclusive);
-            try {
-                stdRangeQuery = stdRangeQueryImpl.rewrite(reader);
-                return stdRangeQuery;
-            } catch (BooleanQuery.TooManyClauses e) {
-                log.debug("Too many terms to enumerate, using custom RangeQuery");
-                // failed, use own implementation
-                return this;
-            }
+            return new ConstantScoreRangeQuery(lowerTerm.field(),
+                    lowerTerm.text(), upperTerm.text(), inclusive,
+                    inclusive).rewrite(reader);
         } else {
             // always use our implementation when we need to transform the
             // term enum
@@ -194,9 +170,7 @@
      * {@inheritDoc}
      */
     public void extractTerms(Set terms) {
-        if (stdRangeQuery != null) {
-            stdRangeQuery.extractTerms(terms);
-        }
+        // cannot extract terms
     }
 
     /**



Mime
View raw message