changeset 1445:f6075d7a36f2

better range query
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 05 Feb 2020 18:06:26 -0700
parents b765f146f4dc
children f2082e9aeaa9
files src/goodjava/queryparser/NumberFieldParser.java src/goodjava/queryparser/StringFieldParser.java
diffstat 2 files changed, 10 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/goodjava/queryparser/NumberFieldParser.java	Wed Feb 05 08:16:15 2020 -0700
+++ b/src/goodjava/queryparser/NumberFieldParser.java	Wed Feb 05 18:06:26 2020 -0700
@@ -36,8 +36,8 @@
 	public static final FieldParser INT = new NumberFieldParser() {
 
 		@Override protected Query getRangeQuery(String field,String minQuery,String maxQuery,boolean includeMin,boolean includeMax) {
-			int min = Integer.parseInt(minQuery);
-			int max = Integer.parseInt(maxQuery);
+			Integer min = minQuery.equals("*") ? null : Integer.valueOf(minQuery);
+			Integer max = maxQuery.equals("*") ? null : Integer.valueOf(maxQuery);
 			return NumericRangeQuery.newIntRange(field,min,max,includeMin,includeMax);
 		}
 
@@ -49,8 +49,8 @@
 	public static final FieldParser LONG = new NumberFieldParser() {
 
 		@Override protected Query getRangeQuery(String field,String minQuery,String maxQuery,boolean includeMin,boolean includeMax) {
-			long min = Long.parseLong(minQuery);
-			long max = Long.parseLong(maxQuery);
+			Long min = minQuery.equals("*") ? null : Long.valueOf(minQuery);
+			Long max = maxQuery.equals("*") ? null : Long.valueOf(maxQuery);
 			return NumericRangeQuery.newLongRange(field,min,max,includeMin,includeMax);
 		}
 
@@ -62,8 +62,8 @@
 	public static final FieldParser FLOAT = new NumberFieldParser() {
 
 		@Override protected Query getRangeQuery(String field,String minQuery,String maxQuery,boolean includeMin,boolean includeMax) {
-			float min = Float.parseFloat(minQuery);
-			float max = Float.parseFloat(maxQuery);
+			Float min = minQuery.equals("*") ? null : Float.valueOf(minQuery);
+			Float max = maxQuery.equals("*") ? null : Float.valueOf(maxQuery);
 			return NumericRangeQuery.newFloatRange(field,min,max,includeMin,includeMax);
 		}
 
@@ -75,8 +75,8 @@
 	public static final FieldParser DOUBLE = new NumberFieldParser() {
 
 		@Override protected Query getRangeQuery(String field,String minQuery,String maxQuery,boolean includeMin,boolean includeMax) {
-			double min = Double.parseDouble(minQuery);
-			double max = Double.parseDouble(maxQuery);
+			Double min = minQuery.equals("*") ? null : Double.valueOf(minQuery);
+			Double max = maxQuery.equals("*") ? null : Double.valueOf(maxQuery);
 			return NumericRangeQuery.newDoubleRange(field,min,max,includeMin,includeMax);
 		}
 
--- a/src/goodjava/queryparser/StringFieldParser.java	Wed Feb 05 08:16:15 2020 -0700
+++ b/src/goodjava/queryparser/StringFieldParser.java	Wed Feb 05 18:06:26 2020 -0700
@@ -55,8 +55,8 @@
 	}
 
 	@Override public Query getRangeQuery(SaneQueryParser qp,String field,String minQuery,String maxQuery,boolean includeMin,boolean includeMax) throws ParseException {
-		minQuery = escape(qp,minQuery);
-		maxQuery = escape(qp,maxQuery);
+		minQuery = minQuery.equals("*") ? null : escape(qp,minQuery);
+		maxQuery = maxQuery.equals("*") ? null : escape(qp,maxQuery);
 		return TermRangeQuery.newStringRange(field,minQuery,maxQuery,includeMin,includeMax);
 	}