英文:
How to find vertexes by the properties of edges using "AND" in orientdb?
问题
- 类:
Product
- 类:
Parameter
- 边:
ProductHasParameter
,具有属性value
问题:如何查找所有具有 2 条 ProductHasParameter
边的 Product
:
- 具有
value
=<SOME_VALUE_1> 到Parameter
(@rid=1)
AND - 具有
value
=<SOME_VALUE_2> 到Parameter
(@rid=2)
示例:
问题:哪些 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:
- Class:
Product
- Class:
Parameter
- Edge:
ProductHasParameter
with a propertyvalue
Question: How to find all Product
that have 2 edges ProductHasParameter
:
- with the
value
=<SOME_VALUE_1> toParameter
with @rid=1
AND - with the
value
=<SOME_VALUE_2> toParameter
with @rid=2
?
Example:
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 toParameter
with @rid=8
AND - with a property
value
=1000$ toParameters
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]->(paramColor:Parameter {@rid:"8"})
MATCH (prd:Product)-[hasParameterPrice:ProductHasParameter]->(paramPrice:Parameter {@rid:"12"})
WHERE hasParameterColor.value="red" AND hasParameterPrice.value="1000$"
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('ProductHasParameter'){where:(value='red')}.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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论