【问题标题】:Neo4j CYPHER node_auto_index for range lookupNeo4j CYPHER node_auto_index 用于范围查找
【发布时间】:2013-05-02 01:21:48
【问题描述】:

我想知道是否有任何方法可以使用自动索引进行范围查找。如果我查询类似

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" 或类似的东西。

有什么想法吗?

【问题讨论】:

    标签: indexing neo4j cypher


    【解决方案1】:

    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

    【讨论】:

    • 谢谢,现在语法没问题,但它不返回任何结果,即使我只创建了 1 个具有适当年龄的节点。
    • 查看 github 问题。这可能正是您正在经历的。
    • 你让它工作了吗?看到你的解决方案我会很有趣。如果对您有帮助,也请随时批准此答案。
    • 抱歉回复晚了,我是通过 Java API 管理的,我在其中使用了QueryContext.numericRange(property_name,from,to) QueryContext.numericRange(age,10,20) 查询,如此处所述docs.neo4j.org/chunked/milestone/…
    【解决方案2】:

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

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

    【讨论】:

    • 应该是START node:node(*)
    • 但是它不使用我需要使用的索引,是吗?
    • 确实如此,但这可能是你最后的手段。 :-)
    • START node=node:node_auto_index(name="startNodeName") where node.age > 20 and node.age
    • name - 可以是节点的任何索引属性,is value 可以是任何起点值。
    【解决方案3】:

    在与 Neo4J Technologies 的 Stefan Armbruster 进行的研讨会之后,出现了相同的主题。

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

    这样做一切都应该从索引开始。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-01
      相关资源
      最近更新 更多