OrientDB - 比较2个顶点,边缘属性

时间:2015-04-28 05:37:15

标签: sql graph-databases orientdb

我有两种类型的顶点( Car 属性)和一种类型的边( Property ):

CREATE CLASS Car extends V
CREATE CLASS Attribute extends V
CREATE CLASS Property extends E

属性包含可用的属性,让我们说引擎颜色和的模型

Car 应该包含指向这些属性的链接:

CREATE VERTEX Attribute SET attributeName = "engine"
CREATE VERTEX Attribute SET attributeName = "color"
CREATE VERTEX Attribute SET attributeName = "year"
CREATE VERTEX Attribute SET attributeName = "model"

(有没有更快的方法来创建这些没有4个查询?)

CREATE VERTEX Car SET name = "Suzuki"
CREATE VERTEX Car SET name = "Honda"

CREATE EDGE Property from (SELECT FROM Car WHERE name = "Suzuki") to (SELECT FROM Attribute WHERE attributeName = "color") SET value = "pink"

CREATE EDGE Property from (SELECT FROM Car WHERE name = "Suzuki") to (SELECT FROM Attribute WHERE attributeName = "model") SET value = "Alto"

CREATE EDGE Property from (SELECT FROM Car WHERE name = "Suzuki") to (SELECT FROM Attribute WHERE attributeName = "year") SET value = 2005


CREATE EDGE Property from (SELECT FROM Car WHERE name = "Honda") to (SELECT FROM Attribute WHERE attributeName = "color") SET value = "black"

CREATE EDGE Property from (SELECT FROM Car WHERE name = "Honda") to (SELECT FROM Attribute WHERE attributeName = "engine") SET value = 2500

CREATE EDGE Property from (SELECT FROM Car WHERE name = "Honda") to (SELECT FROM Attribute WHERE attributeName = "model") SET value = "Civic"

CREATE EDGE Property from (SELECT FROM Car WHERE name = "Honda") to (SELECT FROM Attribute WHERE attributeName = "year") SET value = 2005

(再次,更快的方式?)

现在我想搜索任何颜色为黑色的汽车(本田应该退回)。

但是当我搜索2005年的任何一辆车和2500的引擎时,虽然铃木没有引擎属性,但它也应该被返回(所以本田铃木)。

我尝试了以下查询:

select distinct(out.Car) as car from Property WHERE 
                    (in.attributeName="engine" AND value=2500) OR 
                    (in.attributeName="year" AND value=2005) 

当然,铃木也被退回了......有什么帮助吗?

非常感谢! :)

0 个答案:

没有答案