简体   繁体   English

Orientdb-具有多​​个边的where子句

[英]Orientdb - where clause with multiple edges

i'm still quite new at this so I will just go to the case. 我在这方面还很新,所以我将继续讨论。

In our application we have notes that can be shared between users and stored in folders. 在我们的应用程序中,我们具有可以在用户之间共享并存储在文件夹中的注释。 Single note can obviously be in multiple folders (which cannot be shared). 单个便笺显然可以位于多个文件夹中(不能共享)。 Till now for displaying notes in folder we were using this query: 直到现在在文件夹中显示注释,我们一直在使用以下查询:

(select expand(both(\'InFolder\')) from @folder_rid)

But now, we are developing some "advanced filters" where we want to show notes that are inside specific folder or those notes which are not in in. Notes can also be tagged (by single tag) so it was quite easy using "where clause" 但是现在,我们正在开发一些“高级过滤器”,在其中我们要显示特定文件夹中的注释或不在其中的注释。注释也可以被标记(通过单个标记),因此使用“ where子句非常容易“

SELECT FROM (select expand(both(\'CanView\')) from @user_rid) where out(\'HasTag\').@rid = @tag_rid

or 要么

SELECT FROM (select expand(both(\'CanView\')) from @user_rid) where out(\'HasTag\').@rid <> @tag_rid

And now the problem. 现在是问题所在。 Since note can be stored in multiple folders above approach does not work. 由于注释可以存储在上述多个文件夹中,因此该方法无效。 It works when I specify on which position in this array of edges(?) target folder should be: 当我指定Edge(?)目标文件夹的此数组中的哪个位置应该是有效时:

SELECT FROM (select expand(both(\'CanView\')) from @user_rid) where out(\'InFolder\')[0].@rid = @folder_rid
SELECT FROM (select expand(both(\'CanView\')) from @user_rid) where out(\'InFolder\')[1].@rid = @folder_rid

But obviously this is not the way to do this. 但这显然不是做到这一点的方法。 I found ( http://orientdb.com/orientdb-improved-sql-filtering/ ) that i can use ranges to do this, like 我发现( http://orientdb.com/orientdb-improved-sql-filtering/ )可以使用范围来做到这一点,例如

SELECT FROM (select expand(both(\'CanView\')) from @user_rid) where out(\'InFolder\')[0-2].@rid = @folder_rid

But it just calculates the value inside square brackets(oO). 但是它只是计算方括号(oO)内的值。 I also tried with [1,2,3] and using infos from https://code.google.com/p/orient/wiki/Document_Field_Part but I couldn't get it to work. 我也尝试使用[1,2,3]并使用https://code.google.com/p/orient/wiki/Document_Field_Part的信息,但无法正常工作。

What is the correct syntax to do this or is this whole approach just bad. 正确的语法是这样做的,还是整个方法不好? If problem is in the basics what is the good way to do this? 如果问题出在基础知识上,那么这样做的好方法是什么? Thanks for help and sorry for all mistakes I did in grammar. 感谢您的帮助,对于我在语法上的所有错误深表歉意。

I believe the query you're looking for is: 我相信您要查询的查询是:

SELECT 
FROM (SELECT expand(out('CanView')) FROM <user_rid>) 
WHERE <folder_rid> IN out('InFolder')

An example: 一个例子:

create class User extends V
create class Note extends V
create class Folder extends V


create class CanView extends E
create class InFolder extends E


create vertex User set name = 'user'
create vertex Note set name = 'note0'
create vertex Note set name = 'note1'
create vertex Note set name = 'note2'
create vertex Folder set name = 'folder0'
create vertex Folder set name = 'folder1'


create edge CanView from (select from User where name = 'user') to (select from Note where name = 'note0')
create edge CanView from (select from User where name = 'user') to (select from Note where name = 'note1')

create edge InFolder from (select from Note where name = 'note0') to (select from Folder where name = 'folder0')
create edge InFolder from (select from Note where name = 'note1') to (select from Folder where name = 'folder1')
create edge InFolder from (select from Note where name = 'note2') to (select from Folder where name = 'folder1')

There are three notes. 有三个音符。 The user can see note0 and note1 . 用户可以看到note0note1 note0 is in folder0 , note1 is in folder1 . note0folder0中note1folder1中

Let's say we want all the notes in folder0 the user can see. 假设我们希望用户可以看到folder0中的所有注释。 The query above will return note0 . 上面的查询将返回note0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM