【问题标题】:Neo4j and spring-data: numeric index cypher queries not working?Neo4j 和 spring-data:数字索引密码查询不起作用?
【发布时间】:2013-08-07 12:57:16
【问题描述】:

密码查询和数字索引存在一些问题

@Indexed(unique = true, numeric = false)
private Long accountId;

返回:

neo4j-sh (0)$ start n=node:Principal(accountId = '1') return n;      
+---------------------------------------------------------------------------------------------+
| n                                                                                           |
+---------------------------------------------------------------------------------------------+
| Node[41722]{__type__:"example.package.Principal",accountId:1,name:"Simple User"} |
+---------------------------------------------------------------------------------------------+
1 row

但是

@Indexed(unique = true, numeric = true)
private Long accountId;

返回:

neo4j-sh (0)$ start n=node:Principal(accountId = '1') return n; 
+---+
| n |
+---+
+---+
0 row

neo4j 1.9.2
spring-data-neo4j 2.3.0.RC1

如果我理解正确,这可能是discussion,但它已经很老了?

更新:

如果我使用

@Indexed(unique = true, numeric = false)

另一件有趣的事情发生了。检查关系是否存在(它实际上存在于数据库中):

count(r) 等于 0 - 不正确:

Long accountId = 1L;
Map<String, Object> result = template.query(
        "START child=node:Principal(accountId='{childId}') " +
                "MATCH child-[r:IS_MEMBER_OF]->parent " +
                "RETURN count(r)", MapUtil.map("childId", accountId)).singleOrNull();

count(r) 等于 1 - 正确:

Long accountId = 1L;
Map<String, Object> result = template.query(
        "START child=node:Principal(accountId='1') " +
                "MATCH child-[r:IS_MEMBER_OF]->parent " +
                "RETURN count(r)",null).singleOrNull();

【问题讨论】:

    标签: neo4j spring-data-neo4j


    【解决方案1】:

    数字索引查找不适用于具有文字值的密码,lucene 解析器不会创建正确的内部查询。同样使用参数,传递给索引的普通原始值在 neo4j lucene 实现中被视为字符串,因为查询无法知道数据是数字索引还是字符串。

    // this won't work, you have to remove the single quotes around '{childId}'
    "START child=node:Principal(accountId='{childId}') " +
    
        "MATCH child-[r:IS_MEMBER_OF]->parent " +
        "RETURN count(r)", MapUtil.map("childId", accountId)).singleOrNull();
    

    让数字查询与 cypher 一起使用的唯一方法是将 ValueContext.numeric(1) 值作为 java-parameter-map 中的参数传递到嵌入式数据库。

    【讨论】:

    • 还有一个问题,如果我使用@Indexed(unique = true, numeric = true) 那么我不能从neo4j 控制台/Neoeclipse 执行密码查询吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-20
    • 1970-01-01
    • 1970-01-01
    • 2014-10-04
    • 2014-05-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多