Mercurial Hosting > luan
comparison src/goodjava/queryparser/NumberFieldParser.java @ 1445:f6075d7a36f2
better range query
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 05 Feb 2020 18:06:26 -0700 |
parents | 5f038be65271 |
children |
comparison
equal
deleted
inserted
replaced
1444:b765f146f4dc | 1445:f6075d7a36f2 |
---|---|
34 | 34 |
35 | 35 |
36 public static final FieldParser INT = new NumberFieldParser() { | 36 public static final FieldParser INT = new NumberFieldParser() { |
37 | 37 |
38 @Override protected Query getRangeQuery(String field,String minQuery,String maxQuery,boolean includeMin,boolean includeMax) { | 38 @Override protected Query getRangeQuery(String field,String minQuery,String maxQuery,boolean includeMin,boolean includeMax) { |
39 int min = Integer.parseInt(minQuery); | 39 Integer min = minQuery.equals("*") ? null : Integer.valueOf(minQuery); |
40 int max = Integer.parseInt(maxQuery); | 40 Integer max = maxQuery.equals("*") ? null : Integer.valueOf(maxQuery); |
41 return NumericRangeQuery.newIntRange(field,min,max,includeMin,includeMax); | 41 return NumericRangeQuery.newIntRange(field,min,max,includeMin,includeMax); |
42 } | 42 } |
43 | 43 |
44 @Override protected SortField.Type sortType() { | 44 @Override protected SortField.Type sortType() { |
45 return SortField.Type.INT; | 45 return SortField.Type.INT; |
47 }; | 47 }; |
48 | 48 |
49 public static final FieldParser LONG = new NumberFieldParser() { | 49 public static final FieldParser LONG = new NumberFieldParser() { |
50 | 50 |
51 @Override protected Query getRangeQuery(String field,String minQuery,String maxQuery,boolean includeMin,boolean includeMax) { | 51 @Override protected Query getRangeQuery(String field,String minQuery,String maxQuery,boolean includeMin,boolean includeMax) { |
52 long min = Long.parseLong(minQuery); | 52 Long min = minQuery.equals("*") ? null : Long.valueOf(minQuery); |
53 long max = Long.parseLong(maxQuery); | 53 Long max = maxQuery.equals("*") ? null : Long.valueOf(maxQuery); |
54 return NumericRangeQuery.newLongRange(field,min,max,includeMin,includeMax); | 54 return NumericRangeQuery.newLongRange(field,min,max,includeMin,includeMax); |
55 } | 55 } |
56 | 56 |
57 @Override protected SortField.Type sortType() { | 57 @Override protected SortField.Type sortType() { |
58 return SortField.Type.LONG; | 58 return SortField.Type.LONG; |
60 }; | 60 }; |
61 | 61 |
62 public static final FieldParser FLOAT = new NumberFieldParser() { | 62 public static final FieldParser FLOAT = new NumberFieldParser() { |
63 | 63 |
64 @Override protected Query getRangeQuery(String field,String minQuery,String maxQuery,boolean includeMin,boolean includeMax) { | 64 @Override protected Query getRangeQuery(String field,String minQuery,String maxQuery,boolean includeMin,boolean includeMax) { |
65 float min = Float.parseFloat(minQuery); | 65 Float min = minQuery.equals("*") ? null : Float.valueOf(minQuery); |
66 float max = Float.parseFloat(maxQuery); | 66 Float max = maxQuery.equals("*") ? null : Float.valueOf(maxQuery); |
67 return NumericRangeQuery.newFloatRange(field,min,max,includeMin,includeMax); | 67 return NumericRangeQuery.newFloatRange(field,min,max,includeMin,includeMax); |
68 } | 68 } |
69 | 69 |
70 @Override protected SortField.Type sortType() { | 70 @Override protected SortField.Type sortType() { |
71 return SortField.Type.FLOAT; | 71 return SortField.Type.FLOAT; |
73 }; | 73 }; |
74 | 74 |
75 public static final FieldParser DOUBLE = new NumberFieldParser() { | 75 public static final FieldParser DOUBLE = new NumberFieldParser() { |
76 | 76 |
77 @Override protected Query getRangeQuery(String field,String minQuery,String maxQuery,boolean includeMin,boolean includeMax) { | 77 @Override protected Query getRangeQuery(String field,String minQuery,String maxQuery,boolean includeMin,boolean includeMax) { |
78 double min = Double.parseDouble(minQuery); | 78 Double min = minQuery.equals("*") ? null : Double.valueOf(minQuery); |
79 double max = Double.parseDouble(maxQuery); | 79 Double max = maxQuery.equals("*") ? null : Double.valueOf(maxQuery); |
80 return NumericRangeQuery.newDoubleRange(field,min,max,includeMin,includeMax); | 80 return NumericRangeQuery.newDoubleRange(field,min,max,includeMin,includeMax); |
81 } | 81 } |
82 | 82 |
83 @Override protected SortField.Type sortType() { | 83 @Override protected SortField.Type sortType() { |
84 return SortField.Type.DOUBLE; | 84 return SortField.Type.DOUBLE; |