使用cypher通过索引查找执行匹配 [英] Performing match by index lookup with cypher

查看:103
本文介绍了使用cypher通过索引查找执行匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个密集的节点问题,为了解决这个问题,我一直在使用索引来使用本机Java API进行一些匹配,但是我一直在给Cypher一眼,并想知道是否可以这样做.目前,我的模式在Java代码中如下所示:

I have a dense node problem and to get around this I've been using indexing to perform some matching using the native Java API, but I've been giving Cypher a second look and wanted to know if this could be done. Currently my pattern looks like this in Java Code:

Node startNode = db.getNodeById(1);
Index<Relationship> relationshipIndex = db.index.forRelationships("relationships");

for(Relationship relationship1 : startNode.getRelationships(Direction.OUT)) {
    Node otherNode = relationship.getOtherNode(startNode);
    String indexValue = (String)otherNode.getProperty("indexValue");
    for(Relationship relationship2 : relationshipIndex.get("indexKey", indexValue)){
        Node endNode = relationship.getOtherNode(startNode);
        //Processing on the endNode
    }
}

我如何将其翻译为密码?像这样:

How would I translate this to cypher? Something like:

START startNode=node(1)
MATCH startNode-[r1]->otherNode
WITH node:relationships("indexValue:" + otherNode.indexValue) as r2
RETURN r2.endNode //Notation for getting node off relationship?

我真的看不到任何地方可以建立关系,然后通过这样的关系获得终端节点.

I don't really see anywhere to just get a relationship, then get the end node through a relationship like this.

推荐答案

是的,在2.0版本中有一个startNode(rel)/endNode(rel)函数,但在1.9或更早版本中不存在.

Yeah, in 2.0 there's a startNode(rel)/endNode(rel) function, but it's not there for 1.9 or earlier.

http://console.neo4j.org/r/4807s7

因此,从理论上讲,您可以这样做:

So in theory you could do this:

start rel=rel:rel_auto_index(indexKey="value") 
with endNode(rel) as n
match n-->m
return *

这将避免接触该关系的startNode(除非从n指向它的指针).

And that would avoid ever touching the startNode of the relationship (unless there's a pointer back to it from n).

这篇关于使用cypher通过索引查找执行匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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