You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by sh...@apache.org on 2009/03/12 07:24:14 UTC

svn commit: r752785 - in /lucene/solr/trunk/src/java/org/apache/solr: schema/FieldType.java schema/TrieField.java search/SolrQueryParser.java

Author: shalin
Date: Thu Mar 12 06:24:13 2009
New Revision: 752785

URL: http://svn.apache.org/viewvc?rev=752785&view=rev
Log:
SOLR-940 followup -- Changing API, implementation and javadocs per Hoss's suggestions

Modified:
    lucene/solr/trunk/src/java/org/apache/solr/schema/FieldType.java
    lucene/solr/trunk/src/java/org/apache/solr/schema/TrieField.java
    lucene/solr/trunk/src/java/org/apache/solr/search/SolrQueryParser.java

Modified: lucene/solr/trunk/src/java/org/apache/solr/schema/FieldType.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/schema/FieldType.java?rev=752785&r1=752784&r2=752785&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/schema/FieldType.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/schema/FieldType.java Thu Mar 12 06:24:13 2009
@@ -427,20 +427,30 @@
   }
 
   /**
-   * Returns a Query instance for doing range searches on this field type
+   * Returns a Query instance for doing range searches on this field type. {@link org.apache.solr.search.SolrQueryParser}
+   * currently passes part1 and part2 as null if they are '*' respectively. minInclusive and maxInclusive are both true
+   * currently by SolrQueryParser but that may change in the future. Also, other QueryParser implementations may have
+   * different semantics.
+   * <p/>
+   * Sub-classes should override this method to provide their own range query implementation. They should strive to
+   * handle nulls in part1 and/or part2 as well as unequal minInclusive and maxInclusive parameters gracefully.
+   *
+   * @param field        the name of the field
+   * @param part1        the lower boundary of the range, nulls are allowed.
+   * @param part2        the upper boundary of the range, nulls are allowed
+   * @param minInclusive whether the minimum of the range is inclusive or not
+   * @param maxInclusive whether the maximum of the range is inclusive or not
    *
-   * @param field the name of the field
-   * @param part1 the lower boundary of the range
-   * @param part2 the upper boundary of the range
-   * @param inclusive whether the range is inclusive or not
    * @return a Query instance to perform range search according to given parameters
+   *
+   * @see org.apache.solr.search.SolrQueryParser#getRangeQuery(String, String, String, boolean)
    */
-  public Query getRangeQuery(String field, String part1, String part2, boolean inclusive) {
+  public Query getRangeQuery(String field, String part1, String part2, boolean minInclusive, boolean maxInclusive) {
     RangeQuery rangeQuery = new RangeQuery(
             field,
-            "*".equals(part1) ? null : toInternal(part1),
-            "*".equals(part2) ? null : toInternal(part2),
-            inclusive, inclusive);
+            part1 == null ? null : toInternal(part1),
+            part2 == null ? null : toInternal(part2),
+            minInclusive, maxInclusive);
     rangeQuery.setConstantScoreRewrite(true);
     return rangeQuery;
   }

Modified: lucene/solr/trunk/src/java/org/apache/solr/schema/TrieField.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/schema/TrieField.java?rev=752785&r1=752784&r2=752785&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/schema/TrieField.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/schema/TrieField.java Thu Mar 12 06:24:13 2009
@@ -148,38 +148,38 @@
   }
 
   @Override
-  public Query getRangeQuery(String field, String min, String max, boolean inclusive) {
+  public Query getRangeQuery(String field, String min, String max, boolean minInclusive, boolean maxInclusive) {
     Filter filter = null;
     switch (type) {
       case INTEGER:
         filter = new IntTrieRangeFilter(field, field, precisionStep,
-                "*".equals(min) ? null : Integer.parseInt(min),
-                "*".equals(max) ? null : Integer.parseInt(max),
-                inclusive, inclusive);
+                min == null ? null : Integer.parseInt(min),
+                max == null ? null : Integer.parseInt(max),
+                minInclusive, maxInclusive);
         break;
       case FLOAT:
         filter = new IntTrieRangeFilter(field, field, precisionStep,
-                "*".equals(min) ? null : TrieUtils.floatToSortableInt(Float.parseFloat(min)),
-                "*".equals(max) ? null : TrieUtils.floatToSortableInt(Float.parseFloat(max)),
-                inclusive, inclusive);
+                min == null ? null : TrieUtils.floatToSortableInt(Float.parseFloat(min)),
+                max == null ? null : TrieUtils.floatToSortableInt(Float.parseFloat(max)),
+                minInclusive, maxInclusive);
         break;
       case LONG:
         filter = new LongTrieRangeFilter(field, field, precisionStep,
-                "*".equals(min) ? null : Long.parseLong(min),
-                "*".equals(max) ? null : Long.parseLong(max),
-                inclusive, inclusive);
+                min == null ? null : Long.parseLong(min),
+                max == null ? null : Long.parseLong(max),
+                minInclusive, maxInclusive);
         break;
       case DOUBLE:
         filter = new LongTrieRangeFilter(field, field, precisionStep,
-                "*".equals(min) ? null : TrieUtils.doubleToSortableLong(Double.parseDouble(min)),
-                "*".equals(max) ? null : TrieUtils.doubleToSortableLong(Double.parseDouble(max)),
-                inclusive, inclusive);
+                min == null ? null : TrieUtils.doubleToSortableLong(Double.parseDouble(min)),
+                max == null ? null : TrieUtils.doubleToSortableLong(Double.parseDouble(max)),
+                minInclusive, maxInclusive);
         break;
       case DATE:
         filter = new LongTrieRangeFilter(field, field, precisionStep,
-                "*".equals(min) ? null : dateField.parseMath(null, min).getTime(),
-                "*".equals(max) ? null : dateField.parseMath(null, max).getTime(),
-                inclusive, inclusive);
+                min == null ? null : dateField.parseMath(null, min).getTime(),
+                max == null ? null : dateField.parseMath(null, max).getTime(),
+                minInclusive, maxInclusive);
         break;
       default:
         throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field");

Modified: lucene/solr/trunk/src/java/org/apache/solr/search/SolrQueryParser.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/search/SolrQueryParser.java?rev=752785&r1=752784&r2=752785&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/search/SolrQueryParser.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/search/SolrQueryParser.java Thu Mar 12 06:24:13 2009
@@ -119,7 +119,10 @@
   protected Query getRangeQuery(String field, String part1, String part2, boolean inclusive) throws ParseException {
     checkNullField(field);
     FieldType ft = schema.getFieldType(field);
-    return ft.getRangeQuery(field, part1, part2, inclusive);
+    return ft.getRangeQuery(field,
+            "*".equals(part1) ? null : part1,
+            "*".equals(part2) ? null : part2,
+            inclusive, inclusive);
   }
 
   protected Query getPrefixQuery(String field, String termStr) throws ParseException {