Range queries in Neo4j using Lucene query syntax

2019-06-25 04:38发布

I'm using Lucene to index nodes in a Neo4j database and I'm using Lucene query strings to perform queries. Everything behaves as expected when I perform range queries that are either exclusive or inclusive on both ends:

Index.query("value:[1 TO 10]");  // Inclusive range query
Index.query("value:{1 TO 10}");  // Exclusive range query

However, it doesn't seem to work if I specify one end of the range query to be exclusive and the other to be inclusive, for example:

Index.query("value:[1 TO 10}");

I understand that it is possible to perform this query using the QueryContext.numericRange() method, for example:

Index.query(QueryContext.numericRange("value", 1, 10, true, false));

Why is it not possible to do the same using Lucene query syntax? Am I misunderstanding the syntax or doing something incorrectly code-wise?

References:
http://docs.neo4j.org/chunked/stable/indexing-lucene-extras.html
http://lucene.apache.org/java/3_5_0/queryparsersyntax.html

2条回答
forever°为你锁心
2楼-- · 2019-06-25 04:48

Plain schema index in Neo4j 2.3 now supports range queries

http://neo4j.com/release-notes/neo4j-2-3-0/

查看更多
三岁会撩人
3楼-- · 2019-06-25 05:14

in order for numeric ranges to work, you have to index your data with custom parsers etc, since lucene did not anticipate this usecase, see http://wiki.apache.org/lucene-java/SearchNumericalFields and the related issues. I think you can do it better in Lucene 3.5 which is part of Neo4j 1.6.GA though, but you will have to pull some tricks here :)

查看更多
登录 后发表回答