-
-
Notifications
You must be signed in to change notification settings - Fork 874
Description
OrientDB Version: 3.0.20
Java Version: 1.8.0_191
OS: Windows 10
Assuming I have this model:
Person (userId String)
Friend (from person to person) (status: 1=requested,2=approved)
I need to create a query that will find all Person that will match 'John' (Lucene full text), and will return (a) the friend data between them and person 'Bar', and (b) The amount of friends that person and 'Bar' has in common.
The current query I have is:
SELECT (MATCH {class:Person, where:(SEARCH_CLASS("John") = true)}.bothE("Friend"){as:friend, where:(status=2)}.bothV("Person"){where:(userId="bulu")} RETURN friend:{*}) as friend, (MATCH {class:Person, where:(SEARCH_CLASS("John") = true)}.bothE("Friend"){where:(status=2),as:fs1}.bothV("Person"){as:friend, where:($matched != $currentMatch)}.bothE("Friend"){where:(status=2 AND $matched.fs1 != $currentMatch)}.bothV("Person"){where:(userId="bar" AND $matched.friend != $currentMatch)} RETURN COUNT(friend) as cnt) as count
Which technically is working, but:
(1) It looks like a really bad query, performance-wise. I have to repeat few things in each sub-query (such as SEARCH_CLASS). Anyway to avoid that?
(2) The result contains 2 columns, 'friend' and 'count', but in each of them I have an array, and in the count I even have a nested json with 'cnt'. Is there a way to avoid all that, so that in the first column/cell I will simply have the json data of 'friend', and in the second I will simply have an integer - the count?