如何获取连接Orient db中两个特定顶点的边

时间:2015-10-14 13:46:45

标签: orientdb

我已经尝试过文档和控制台,但没有找到办法。

Vertex with property" A",Vertex with property" B"和Edge标签"已连接"。

我想找出连接这两个顶点的边缘并获得边缘的 id

我还没有能够做到这一点。我能做到

select from (SELECT EXPAND(BOTH('Connected')) FROM Tag WHERE prop='A') where prop='B'

但我需要获得@rid的优势。如果我将BOTH改为BOTHE那么我怎样才能特别要求用道具B标记。

我也尝试过:

SELECT FROM Connected WHERE IN=(SELECT FROM TAG WHERE prop = 'A') AND OUT = (SELECT FROM TAG WHERE prop = 'B')

但我从那里得不到任何东西

更新

select from Connected where (out in (select from Tag where tagName='testTagA') AND in in (select from Tag where tagName='testTagB')) OR (out in (select from Tag where tagName='testTagB') AND in in (select from Tag where tagName='testTagA'))

这解决了这个问题,但是有没有更简单的方法?我认为这会使用给定的标签扫描所有边缘。

2 个答案:

答案 0 :(得分:0)

尝试此查询

select from Connected where out in (select from Tag WHERE prop = 'B' ) and in in (select from Tag WHERE prop = 'A' )

答案 1 :(得分:0)

试试这个:

1:

SELECT FROM (
    SELECT EXPAND(BOTHE('Connected')) FROM Tag WHERE prop='A'
) WHERE in.prop='B' or out.prop='B'

2:

SELECT FROM Connected 
WHERE (in.prop = 'A' AND out.prop = 'B') OR (in.prop = 'B' AND out.prop = 'A')

2B:

SELECT FROM Connected 
LET $inProp = in.prop, $outProp = outProp = out.prop 
WHERE ($inProp = 'A' AND $outProp = 'B') OR ($inProp = 'B' AND $outProp = 'A')

我不确定哪个是你最快的,你必须尝试一下,因为它取决于你的数据库和查询的其他部分。 2b比2快,但只是超小的余量。