@JsolarC Based on the information provided I went ahead and designed a small solution to show you what I would do.
You mentioned that you are using location information (country). There is a concept of Geo-Trees in Graphs. Geo-Tree’s can help with filtering information by crawling along edges. Please refer to the right side of this image:
Next, let’s look at how you would go about pulling that information. I’m using v1 syntax. v2 syntax you could simply state this in an expression, but v1 helps you understand the journey.
Getting Started
To get started I want to pass those parameters, “USA” for the country and “Amazon” for the client.
CREATE QUERY findOrders(VERTEX<Client> client, VERTEX<Country> country) FOR GRAPH Shipments { `
Next, I want to accumulate the users and their orders into lists
ListAccum<EDGE> @@userOrders;
After this, we will start with our seed which is “USA” in our case. Then we will find only the addresses (of users) that are located in the “USA”
Seed = {country};
AddressInCountry = SELECT tgt FROM Seed:s -(ADDRESS_IN_COUNTRY:e)- Address:tgt;
After we have those let’s find the “Users” belonging to those “USA” addresses:
UsersInCountry = SELECT tgt FROM AddressInCountry:s -(ADDRESS_OF_USER:e)- Users:tgt;
Okay now we have all the users that are located in the “USA”, but we want only the Users that belong to Client “Amazon”. To do this we will take a peek and filter our users that only belong to that client “Amazon” with a WHERE clause.
ClientUsers = SELECT s FROM UsersInCountry:s -(HAS_CLIENT:e)- Client:tgt WHERE tgt == client;
Lastly, let’s use an ACCUM and our ListAccum to grab all those orders belonging to the users.
GetOrder = SELECT tgt FROM ClientUsers:s -(PLACES_ORDER:e)- Orders:tgt ACCUM @@userOrders += e;
Final Product
This is what we end up with when putting the pieces together.
CREATE QUERY findOrders(VERTEX<Client> client, VERTEX<Country> country) FOR GRAPH Shipments {
ListAccum<EDGE> @@userOrders;
Seed = {country};
AddressInCountry = SELECT tgt FROM Seed:s -(ADDRESS_IN_COUNTRY:e)- Address:tgt;
UsersInCountry = SELECT tgt FROM AddressInCountry:s -(ADDRESS_OF_USER:e)- Users:tgt;
ClientUsers = SELECT s FROM UsersInCountry:s -(HAS_CLIENT:e)- Client:tgt WHERE tgt == client;
GetOrder = SELECT tgt FROM ClientUsers:s -(PLACES_ORDER:e)- Orders:tgt ACCUM @@userOrders += e;
PRINT @@userOrders;
}
Output
When executing the query with inputs of “USA” and “Amazon” we get the following: