Indexes are exact lookups.
db.index().forNodes("member_age").add(node,"birth_year",ValueContext.numeric(node.get("birth_year"));
db.index().forNodes("member_age").query(NumericRangeQuery.newIntRange("birth_year", from , to, true, true));
@Override
public EndResult<T> findAllByRange(final String indexName, final String property, final Number from, final Number to) {
return queryResult(indexName, new Query<S>() {
public IndexHits<S> query(ReadableIndex<S> index) {
return index.query(property, createInclusiveRangeQuery(property, from, to));
}
});
}
@SuppressWarnings("unchecked")
protected <T extends Number> NumericRangeQuery<T> createInclusiveRangeQuery(String property, Number from, Number to) {
if (from instanceof Long) return (NumericRangeQuery<T>) NumericRangeQuery.newLongRange(property, from.longValue(),to.longValue(),true,true);
if (from instanceof Integer) return (NumericRangeQuery<T>) NumericRangeQuery.newIntRange(property, from.intValue(), to.intValue(), true, true);
if (from instanceof Double) return (NumericRangeQuery<T>) NumericRangeQuery.newDoubleRange(property, from.doubleValue(), to.doubleValue(), true, true);
if (from instanceof Float) return (NumericRangeQuery<T>) NumericRangeQuery.newFloatRange(property, from.floatValue(), to.floatValue(), true, true);
return (NumericRangeQuery<T>) NumericRangeQuery.newIntRange(property, from.intValue(), to.intValue(), true, true);
}