djkevincr commented on a change in pull request #158: GORA-555: Improve Lucene query implementation with NumericRangeQuery URL: https://github.com/apache/gora/pull/158#discussion_r272787885
########## File path: gora-lucene/src/main/java/org/apache/gora/lucene/query/LuceneQuery.java ########## @@ -51,22 +57,41 @@ public Query toLuceneQuery() { if (getKey() != null) { q = new TermQuery(new Term(pk, getKey().toString())); } else { - //TODO: Change this to a NumericRangeQuery when necessary (it's faster) - String lower = null; - String upper = null; - if (getStartKey() != null) { - //Do we need to escape the term? - lower = getStartKey().toString(); - } - if (getEndKey() != null) { - upper = getEndKey().toString(); - } - if (upper == null && lower == null) { - q = new MatchAllDocsQuery(); + if (getEndKey() == null && getStartKey() == null) { + return new MatchAllDocsQuery(); } else { - q = TermRangeQuery.newStringRange(pk, lower, upper, true, true); + q = inferType(pk, getStartKey(), getEndKey()); } } return q; } + + private <T> Query inferType(String pk, T lower, T upper) { + if (((lower != null && lower.getClass() == Integer.class) + || (upper != null && upper.getClass() == Integer.class))) { + int ilower = lower == null ? Integer.MIN_VALUE : Integer.valueOf(lower.toString()); Review comment: int ilower = lower == null ? Integer.MIN_VALUE : Integer.valueOf(lower.toString()); If the value here is in Integer class ( lower.getClass() == Integer.class ) Is it necessary to convert to String and take the Integer value using Integer.valueOf(lower.toString()) === int ilower = lower == null ? Integer.MIN_VALUE : (Integer) lower; This is the same for other cases in below for float, long, double. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services