如何使用“AND”在OrientDB中通过边的属性查找顶点?

huangapple go评论95阅读模式
英文:

How to find vertexes by the properties of edges using "AND" in orientdb?

问题

  1. 类:Product
  2. 类:Parameter
  3. 边:ProductHasParameter,具有属性 value

问题:如何查找所有具有 2 条 ProductHasParameter 边的 Product

  • 具有 value=<SOME_VALUE_1> 到 Parameter(@rid=1)
    AND
  • 具有 value=<SOME_VALUE_2> 到 Parameter(@rid=2)

示例:

如何使用“AND”在OrientDB中通过边的属性查找顶点?

问题:哪些 Product 具有颜色=红色且价格=1000$?

换句话说:哪些类别为 Product 的顶点具有 2 条 ProductHasParameter 边:

  • 具有属性 value=红色 到 Parameter(@rid=8)
    AND
  • 具有属性 value=1000$ 到 Parameters(@rid=12)

注意:存在一个 @rid=2 的 Product 完全没有边。

我希望只获取 @rid=1 的 Product。

在 Cypher 中,可以这样编写查询:

MATCH (prd:Product)-[hasParameterColor:ProductHasParameter]->(paramColor:Parameter {@rid:"8"})
MATCH (prd:Product)-[hasParameterPrice:ProductHasParameter]->(paramPrice:Parameter {@rid:"12"})
WHERE hasParameterColor.value="red" AND hasParameterPrice.value="1000$"
RETURN pr
英文:

I have two classes and one edge:

  1. Class: Product
  2. Class: Parameter
  3. Edge: ProductHasParameter with a property value

Question: How to find all Product that have 2 edges ProductHasParameter:

  • with the value=<SOME_VALUE_1> to Parameter with @rid=1
    AND
  • with the value=<SOME_VALUE_2> to Parameter with @rid=2

?

Example:

如何使用“AND”在OrientDB中通过边的属性查找顶点?

Question: Which Products have Color=red AND price=1000$?

In other words: Which vertexes of class Product have 2 edges ProductHasParameter:

  • with a property value=red to Parameter with @rid=8
    AND
  • with a property value=1000$ to Parameters with @rid=12

?

Note: There is a Product with @rid=2 that doesn't have any edges at all.

I expect to get only Product with @rid=1.

In Cypher, i can write the query like this:

MATCH (prd:Product)-[hasParameterColor:ProductHasParameter]-&gt;(paramColor:Parameter {@rid:&quot;8&quot;})
MATCH (prd:Product)-[hasParameterPrice:ProductHasParameter]-&gt;(paramPrice:Parameter {@rid:&quot;12&quot;})
WHERE hasParameterColor.value=&quot;red&quot; AND hasParameterPrice.value=&quot;1000$&quot;
RETURN pr

答案1

得分: 0

尝试以下:

MATCH {class: ProductHasParameter, where:(value=1000)}.outV().outE('ProductHasParameter'){where:(value='red')}.outV(){as: cars} RETURN expand(cars);

上述查询选择所有值为1000的ProductHasParameter边(过滤掉除1000之外的任何值)

.outV()选择边的所有出顶点(汽车),这意味着值为1000的卡(可以是任何颜色)

.outE('ProductHasParameter'){where:(value='red')}选择所有从具有红色值的顶点(汽车)出发的ProductHasParameter边,这些边的出顶点的值为1000,颜色为红色

.outV(){as: cars}选择顶点(汽车)

我没有测试过这个查询,无法确定它是否有效,但上述思路应该能筛选出您需要的汽车。

英文:

Try the below:

MATCH {class: ProductHasParameter, where:(value=1000)}.outV().outE(&#39;ProductHasParameter&#39;){where:(value=&#39;red&#39;)}.outV(){as: cars} RETURN expand(cars);

MATCH {class: ProductHasParameter, where:(value=1000)} selects all ProductHasParameter edges with value 1000 (filters out any other value other than 1000)

.outV() selects all the out vertices of the edges (cars) which implies card whose value is 1000 (can be of any color)

.outE('ProductHasParameter'){where:(value='red')} selects all the out ProductHasParameter edges from the vertices (cars) that has value red, the out vertices of these edges will have value as 1000 and color as red

.outV(){as: cars} selects the vertices back (cars)

I have not tested the query so cannot say if it works but the above thought process should filter out the cars you requires.

huangapple
  • 本文由 发表于 2023年6月8日 16:16:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76429896.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定