Neo4j中使用Lucene查询语法的范围查询 [英] Range queries in Neo4j using Lucene query syntax

查看:358
本文介绍了Neo4j中使用Lucene查询语法的范围查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Lucene索引Neo4j数据库中的节点,并且我正在使用Lucene查询字符串来执行查询.当我执行两端都是排他性或包含性的范围查询时,一切都会按预期进行:

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}");

我了解可以使用QueryContext.numericRange()方法执行此查询,例如:

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));

为什么无法使用Lucene查询语法执行相同的操作?是我误解了语法还是在代码方面做了错误的事情?

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

参考文献:
http://docs.neo4j.org/chunked/stable/indexing-lucene -extras.html
http://lucene.apache.org/java/3_5_0/queryparsersyntax.html

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

推荐答案

为了使数字范围有效,您必须使用自定义解析器等对数据进行索引,因为lucene并未预料到这种用例,请参见

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 :)

这篇关于Neo4j中使用Lucene查询语法的范围查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆