lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Otis Gospodnetic <otis_gospodne...@yahoo.com>
Subject Re: svn commit: r475435 - in /lucene/java/trunk/src: java/org/apache/lucene/queryParser/QueryParser.java java/org/apache/lucene/queryParser/QueryParser.jj java/org/apache/lucene/search/RangeQuery.java test/org/apache/lucene/queryParser/TestQueryParser.java
Date Wed, 15 Nov 2006 23:25:12 GMT
It looks like you forgot CHANGES.txt.

Otis

----- Original Message ----
From: "mharwood@apache.org" <mharwood@apache.org>
To: java-commits@lucene.apache.org
Sent: Wednesday, November 15, 2006 4:26:10 PM
Subject: svn commit: r475435 - in /lucene/java/trunk/src: java/org/apache/lucene/queryParser/QueryParser.java
java/org/apache/lucene/queryParser/QueryParser.jj java/org/apache/lucene/search/RangeQuery.java
test/org/apache/lucene/queryParser/TestQueryParser.java

Author: mharwood
Date: Wed Nov 15 13:26:09 2006
New Revision: 475435

URL: http://svn.apache.org/viewvc?view=rev&rev=475435
Log:
QueryParser changed to default to use of ConstantScoreRangeQuery for range queries. 
Added useOldRangeQuery property to QueryParser to allow selection of old RangeQuery class
if required.
Updated Junit tests. 
Updated javadocs for RangeQuery to reflect the new default behaviour in QueryParser

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/queryParser/QueryParser.java
    lucene/java/trunk/src/java/org/apache/lucene/queryParser/QueryParser.jj
    lucene/java/trunk/src/java/org/apache/lucene/search/RangeQuery.java
    lucene/java/trunk/src/test/org/apache/lucene/queryParser/TestQueryParser.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/queryParser/QueryParser.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/queryParser/QueryParser.java?view=diff&rev=475435&r1=475434&r2=475435
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/queryParser/QueryParser.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/queryParser/QueryParser.java Wed Nov 15 13:26:09
2006
@@ -82,6 +82,7 @@
   private Operator operator = OR_OPERATOR;
 
   boolean lowercaseExpandedTerms = true;
+  boolean useOldRangeQuery= false;
   boolean allowLeadingWildcard = false;
 
   Analyzer analyzer;
@@ -250,6 +251,28 @@
   }
 
   /**
+   * By default QueryParser uses new ConstantScoreRangeQuery in preference to RangeQuery
+   * for range queries. This implementation is generally preferable because it 
+   * a) Runs faster b) Does not have the scarcity of range terms unduly influence score 
+   * c) avoids any "TooManyBooleanClauses" exception.
+   * However, if your application really needs to use the old-fashioned RangeQuery and the
above
+   * points are not required then set this option to <code>true</code>
+   * Default is <code>false</code>.
+   */
+  public void setUseOldRangeQuery(boolean useOldRangeQuery) {
+    this.useOldRangeQuery = useOldRangeQuery;
+  }
+
+
+  /**
+   * @see #setUseOldRangeQuery(boolean)
+   */
+  public boolean getUseOldRangeQuery() {
+    return useOldRangeQuery;
+  }
+
+
+  /**
    * Set locale used by date range parsing.
    */
   public void setLocale(Locale locale) {
@@ -454,9 +477,16 @@
     }
     catch (Exception e) { }
 
-    return new RangeQuery(new Term(field, part1),
+    if(useOldRangeQuery)
+    {
+            return new RangeQuery(new Term(field, part1),
                           new Term(field, part2),
                           inclusive);
+    }
+    else
+    {
+      return new ConstantScoreRangeQuery(field,part1,part2,inclusive,inclusive);
+    }
   }
 
   /**

Modified: lucene/java/trunk/src/java/org/apache/lucene/queryParser/QueryParser.jj
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/queryParser/QueryParser.jj?view=diff&rev=475435&r1=475434&r2=475435
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/queryParser/QueryParser.jj (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/queryParser/QueryParser.jj Wed Nov 15 13:26:09
2006
@@ -106,6 +106,7 @@
   private Operator operator = OR_OPERATOR;
 
   boolean lowercaseExpandedTerms = true;
+  boolean useOldRangeQuery= false;  
   boolean allowLeadingWildcard = false;
 
   Analyzer analyzer;
@@ -272,6 +273,28 @@
   public boolean getLowercaseExpandedTerms() {
     return lowercaseExpandedTerms;
   }
+  
+  /**
+   * By default QueryParser uses new ConstantScoreRangeQuery in preference to RangeQuery
+   * for range queries. This implementation is generally preferable because it 
+   * a) Runs faster b) Does not have the scarcity of range terms unduly influence score 
+   * c) avoids any "TooManyBooleanClauses" exception.
+   * However, if your application really needs to use the old-fashioned RangeQuery and the
above
+   * points are not required then set this option to <code>true</code>
+   * Default is <code>false</code>.
+   */
+  public void setUseOldRangeQuery(boolean useOldRangeQuery) {
+    this.useOldRangeQuery = useOldRangeQuery;
+  }
+
+
+  /**
+   * @see #setUseOldRangeQuery(boolean)
+   */
+  public boolean getUseOldRangeQuery() {
+    return useOldRangeQuery;
+  }
+  
 
   /**
    * Set locale used by date range parsing.
@@ -478,9 +501,16 @@
     }
     catch (Exception e) { }
 
-    return new RangeQuery(new Term(field, part1),
+    if(useOldRangeQuery)
+    {
+        return new RangeQuery(new Term(field, part1),
                           new Term(field, part2),
                           inclusive);
+    }
+    else
+    {
+      return new ConstantScoreRangeQuery(field,part1,part2,inclusive,inclusive);
+    }
   }
 
   /**

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/RangeQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/RangeQuery.java?view=diff&rev=475435&r1=475434&r2=475435
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/RangeQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/RangeQuery.java Wed Nov 15 13:26:09
2006
@@ -26,7 +26,18 @@
 
 /**
  * A Query that matches documents within an exclusive range. A RangeQuery
- * is built by QueryParser for input like <code>[010 TO 120]</code>.
+ * is built by QueryParser for input like <code>[010 TO 120]</code> but only
if the QueryParser has 
+ * the useOldRangeQuery property set to true. The QueryParser default behaviour is to use
+ * the newer ConstantScoreRangeQuery class. This is generally preferable because:
+ * <ul>
+ *     <li>It is faster than RangeQuery</li>
+ *     <li>Unlike RangeQuery, it does not cause a BooleanQuery.TooManyClauses exception
if the range of values is large</li>
+ *     <li>Unlike RangeQuery it does not influence scoring based on the scarcity of
individual terms that may match</li>
+ * </ul>
+ * 
+ * 
+ * @see ConstantScoreRangeQuery
+ * 
  *
  * @version $Id$
  */

Modified: lucene/java/trunk/src/test/org/apache/lucene/queryParser/TestQueryParser.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/queryParser/TestQueryParser.java?view=diff&rev=475435&r1=475434&r2=475435
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/queryParser/TestQueryParser.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/queryParser/TestQueryParser.java Wed Nov
15 13:26:09 2006
@@ -31,6 +31,7 @@
 import org.apache.lucene.document.Field;
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.ConstantScoreRangeQuery;
 import org.apache.lucene.search.FuzzyQuery;
 import org.apache.lucene.search.Hits;
 import org.apache.lucene.search.IndexSearcher;
@@ -371,7 +372,12 @@
 
   public void testRange() throws Exception {
     assertQueryEquals("[ a TO z]", null, "[a TO z]");
-    assertTrue(getQuery("[ a TO z]", null) instanceof RangeQuery);
+    assertTrue(getQuery("[ a TO z]", null) instanceof ConstantScoreRangeQuery);
+
+    QueryParser qp = new QueryParser("field", new SimpleAnalyzer());
+    qp.setUseOldRangeQuery(true);
+    assertTrue(qp.parse("[ a TO z]") instanceof RangeQuery);
+    
     assertQueryEquals("[ a TO z ]", null, "[a TO z]");
     assertQueryEquals("{ a TO z}", null, "{a TO z}");
     assertQueryEquals("{ a TO z }", null, "{a TO z}");






---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org


Mime
View raw message