我发现OrientDB和我有一个问题:
我有两个顶点定义:
Product
Criterion和一种边缘定义:
- IsRelatedToEdge多亏了IsRelatedToEdge,我可以将一个产品链接到多个标准
在我的示例中,我已经用5种产品填充了数据库。
shoe-1
shoe-2
shoe-3
hat-1
hat-24种标准:蓝红帽鞋
然后,我用这种方式将产品与准则联系起来:
shoe-1 <=> shoe
shoe-1 <=> blue
shoe-2 <=> shoe
shoe-2 <=> red
shoe-3 <=> shoe
shoe-3 <=> blue
hat-1 <=> shoe
hat-1 <=> blue
hat-2 <=> hat
hat-2 <=> red所以我们有两只蓝鞋,一顶蓝帽子,一只红鞋,一顶红帽。
我想不出怎么才能找到所有的蓝色鞋子。
编辑:我找到了一个“解决方案”,但看起来不太好:
select from Product where
in('IsRelatedToEdge')[name="blue"].size() = 1 and
in('IsRelatedToEdge')[name="shoe"].size() = 1发布于 2015-08-05 01:56:49
IMO,OrientDB的强大之处在于图形功能,而对表/索引的查询并没有真正利用这一点。我觉得做这个查询最好的方法是得到鞋的标准,然后得到所有的产品,有一个标准的边缘。从那些产品(所有的鞋),你现在可以过滤那些也有一个边缘的蓝色标准。写这篇文章的方法如下..。
select *
from (select expand(both('IsRelatedToEdge')) from Criterion where name = 'Shoe')
let $blue_criterion = (select from Criterion where name = 'Blue')
where both('IsRelatedToEdge') contains $blue_criterion[0]尽管如此,您可以考虑重新安排您的数据,以便更好/更容易地查询。例如,您可以创建一个Hat和Shoe类,它们都是Product的子类。通过这种方式对鞋子进行查询,只对Shoe顶点类进行查询。类似地,您可以创建不同的条件子类,例如Color。要获得这样一个配置的蓝色鞋子,查询需要以下内容.
select *
from Shoes
let $blue_criterion = (select from Color where name = 'Blue')
where both('IsRelatedToEdge') contains $blue_criterion[0]你甚至可以做出更具体的边缘,以使这一步进一步。
发布于 2015-08-05 08:54:41
在研究了neRok的解决方案之后,我找到了以下解决方案:
select expand($result)
let
$crit1 = (select expand(out('IsRelatedToEdge')) from Criterion where name='blue'),
$crit2 = (select expand(out('IsRelatedToEdge')) from Criterion where name='shoe'),
$result = intersect($crit1, $crit2)通过这种查询,我可以添加另一个标准。想象一下,如果我们有阿迪达斯标准,我想要所有蓝色的阿迪达斯鞋:
select expand($result)
let
$crit1 = (select expand(out('IsRelatedToEdge')) from Criterion where name='blue'),
$crit2 = (select expand(out('IsRelatedToEdge')) from Criterion where name='shoe'),
$crit3 = (select expand(out('IsRelatedToEdge')) from Criterion where name='adidas'),
$result = intersect($crit1, $crit2, $crit3)https://stackoverflow.com/questions/31814217
复制相似问题