Neo4j manual/explicit indexes and non-string range

2019-08-15 06:26发布

问题:

I was able to port my Neo4j 3.4.0 application to use manual indexes and APOC procedures instead of queries over the indexles relationship properties. Everything is working like a charm except one last thing - I ran into the issue with non-string Lucene range queries.

They are not working as expected Lucene query language and numeric range

For example:

I'm applying the following Lucene query predicate in order to get all inclusive numbers in 2 to 6 range:

value:[2 TO 6]

and receive the documents with the following values:

567986400000
567986400000
567986400000
536450400000
536450400000
599608800000
536450400000
567986400000

that is obviously not the something that was expected.

Is there anything in Neo4j/APOC that I can do in order to get it working properly?

回答1:

If you read the docs, it says

'Sorting is done lexicographically'

See 'Range queries' under: https://lucene.apache.org/core/6_4_1/queryparser/org/apache/lucene/queryparser/classic/package-summary.html

You should index the data into, for example a DoubleDocValuesField instead of a StringField/TextField and use a appropriate Lucene query, like PointRangeQuery