support for exact matches of numeric indexed values
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
.DS_Store
|
||||
target
|
||||
.springBeans
|
||||
.ant-targets-build.xml
|
||||
|
||||
@@ -81,7 +81,10 @@ public abstract class AbstractFinder<S extends PropertyContainer, T extends Grap
|
||||
}
|
||||
|
||||
private IndexHits<S> getIndexHits(String indexName, String property, Object value) {
|
||||
if (value instanceof Number) value = ValueContext.numeric((Number) value);
|
||||
if (value instanceof Number) {
|
||||
Number number = (Number) value;
|
||||
return getIndex(indexName).query(createInclusiveRangeQuery(property, number,number));
|
||||
}
|
||||
return getIndex(indexName).get(property, value);
|
||||
}
|
||||
|
||||
@@ -146,12 +149,12 @@ public abstract class AbstractFinder<S extends PropertyContainer, T extends Grap
|
||||
public Iterable<T> findAllByRange(final String indexName, final String property, final Number from, final Number to) {
|
||||
return query(indexName, new Query<S>() {
|
||||
public IndexHits<S> query(Index<S> index) {
|
||||
return index.query(property, createRangeQuery(property, from, to));
|
||||
return index.query(property, createInclusiveRangeQuery(property, from, to));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected <T extends Number> NumericRangeQuery<T> createRangeQuery(String property, Number from, Number to) {
|
||||
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);
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.junit.runner.RunWith;
|
||||
import org.neo4j.graphdb.DynamicRelationshipType;
|
||||
import org.neo4j.graphdb.Node;
|
||||
import org.neo4j.graphdb.Relationship;
|
||||
import org.neo4j.graphdb.Transaction;
|
||||
import org.neo4j.graphdb.index.Index;
|
||||
import org.neo4j.helpers.collection.IteratorUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -219,6 +220,14 @@ public class IndexTest {
|
||||
assertEquals(person, found);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findsPersonByIndexOnAnnotatedIntFieldInSeparateTransactions() {
|
||||
Person person = persistedPerson(NAME_VALUE, 35);
|
||||
final NodeFinder<Person> finder = finderFactory.createNodeEntityFinder(Person.class);
|
||||
final Person found = finder.findByPropertyValue(null, "Person.age", 35);
|
||||
assertEquals("person found inside range", person, found);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void testRangeQueryPersonByIndexOnAnnotatedField() {
|
||||
|
||||
Reference in New Issue
Block a user