2013-05-02 35 views
2

我想知道如何使用自动索引进行范围查找。如果我查询类似Neo4j CYPHER用于范围查找的node_auto_index

START age=node:node_auto_index(age<20 and age>10) RETURN age;

返回

Exception in thread "main" string literal or parameter expected. 

我也尝试过类似

START age=node:node_auto_index(age = range(10,20)) 
RETURN age; 

但它看起来像它需要只是age = "15"或类似的东西。

任何想法请做什么?

回答

3

状态Lucene documentation该范围语法如下:

age:[10 TO 20] 

所得查询(但没有测试此):

START age=node:node_auto_index("age:[10 TO 20]") 
RETURN age; 

以下读取可能也有有趣的你:Range queries in Neo4j using Lucene query syntax

编辑:不知道它是否会工作为你;看看这个github issue

+0

谢谢,语法现在可以,但是它不会返回任何结果,即使我只有1个节点创建了适当的年龄。 – JustUser 2013-05-02 07:52:06

+0

剔除github问题。这可能正是你正在经历的。 – tstorms 2013-05-02 08:00:34

+0

你有这个工作吗?我很高兴看到你的解决方案。如果这对你有帮助,也请随时批准这个答案。 – tstorms 2013-05-03 08:16:27

0

为什么不使用where子句,如下所示?

START node=node:node_auto_index(name='PersonName') 
where node.age > 20 and node.age <20 
RETURN node.age; 
+0

由于'*'符号 – JustUser 2013-05-02 07:49:27

+0

应该是'START node:node(*)'这个返回错误。 – tstorms 2013-05-02 08:01:18

+0

但是,它不使用索引,我需要使用,它呢? – JustUser 2013-05-02 08:17:45

0

在与Neo4J Technologies的Stefan Armbruster进行了一次研讨会之后,出现了同样的话题。

我们想出的最基本的解决方案是确保为numeric属性存储的所有值具有相同的长度。因此,人们需要填充年龄属性值如下,011,099,103 ......并且这些值被存储为字符串而不是数值。

做这一切应该从索引工作。