List of usage examples for org.apache.lucene.document DoublePoint nextDown
public static double nextDown(double d)
From source file:org.apache.solr.schema.DoublePointField.java
License:Apache License
@Override public Query getPointRangeQuery(QParser parser, SchemaField field, String min, String max, boolean minInclusive, boolean maxInclusive) { double actualMin, actualMax; if (min == null) { actualMin = Double.NEGATIVE_INFINITY; } else {/* w ww . ja v a 2s. co m*/ actualMin = Double.parseDouble(min); if (!minInclusive) { actualMin = DoublePoint.nextUp(actualMin); } } if (max == null) { actualMax = Double.POSITIVE_INFINITY; } else { actualMax = Double.parseDouble(max); if (!maxInclusive) { actualMax = DoublePoint.nextDown(actualMax); } } return DoublePoint.newRangeQuery(field.getName(), actualMin, actualMax); }
From source file:org.janusgraph.diskstorage.lucene.LuceneIndex.java
License:Apache License
private static Query numericQuery(String key, Cmp relation, Number value) { switch (relation) { case EQUAL://from ww w . ja v a 2 s. c om return AttributeUtil.isWholeNumber(value) ? LongPoint.newRangeQuery(key, value.longValue(), value.longValue()) : DoublePoint.newRangeQuery(key, value.doubleValue(), value.doubleValue()); case NOT_EQUAL: final BooleanQuery.Builder q = new BooleanQuery.Builder(); if (AttributeUtil.isWholeNumber(value)) { q.add(LongPoint.newRangeQuery(key, Long.MIN_VALUE, Math.addExact(value.longValue(), -1)), BooleanClause.Occur.SHOULD); q.add(LongPoint.newRangeQuery(key, Math.addExact(value.longValue(), 1), Long.MAX_VALUE), BooleanClause.Occur.SHOULD); } else { q.add(DoublePoint.newRangeQuery(key, Double.MIN_VALUE, DoublePoint.nextDown(value.doubleValue())), BooleanClause.Occur.SHOULD); q.add(DoublePoint.newRangeQuery(key, DoublePoint.nextUp(value.doubleValue()), Double.MAX_VALUE), BooleanClause.Occur.SHOULD); } return q.build(); case LESS_THAN: return (AttributeUtil.isWholeNumber(value)) ? LongPoint.newRangeQuery(key, Long.MIN_VALUE, Math.addExact(value.longValue(), -1)) : DoublePoint.newRangeQuery(key, Double.MIN_VALUE, DoublePoint.nextDown(value.doubleValue())); case LESS_THAN_EQUAL: return (AttributeUtil.isWholeNumber(value)) ? LongPoint.newRangeQuery(key, Long.MIN_VALUE, value.longValue()) : DoublePoint.newRangeQuery(key, Double.MIN_VALUE, value.doubleValue()); case GREATER_THAN: return (AttributeUtil.isWholeNumber(value)) ? LongPoint.newRangeQuery(key, Math.addExact(value.longValue(), 1), Long.MAX_VALUE) : DoublePoint.newRangeQuery(key, DoublePoint.nextUp(value.doubleValue()), Double.MAX_VALUE); case GREATER_THAN_EQUAL: return (AttributeUtil.isWholeNumber(value)) ? LongPoint.newRangeQuery(key, value.longValue(), Long.MAX_VALUE) : DoublePoint.newRangeQuery(key, value.doubleValue(), Double.MAX_VALUE); default: throw new IllegalArgumentException("Unexpected relation: " + relation); } }
From source file:org.janusgraph.diskstorage.lucene.NumericTranslationQueryParser.java
License:Apache License
private Query getNumericRangeQuery(final String field, final Class<?> type, String start, String end, final boolean includeLower, final boolean includeUpper) { if (AttributeUtil.isWholeNumber(type)) { long min = isMatchAll(start) ? Long.MIN_VALUE : Long.parseLong(start); long max = isMatchAll(end) ? Long.MAX_VALUE : Long.parseLong(end); if (!includeLower) { min = Math.addExact(min, 1); }/*from w ww .j a v a2 s . co m*/ if (!includeUpper) { max = Math.addExact(max, -1); } return LongPoint.newRangeQuery(field, min, max); } else { double min = isMatchAll(start) ? Double.NEGATIVE_INFINITY : Double.parseDouble(start); double max = isMatchAll(end) ? Double.POSITIVE_INFINITY : Double.parseDouble(end); if (!includeLower) { min = DoublePoint.nextUp(min); } if (!includeUpper) { max = DoublePoint.nextDown(max); } return DoublePoint.newRangeQuery(field, min, max); } }