Hi Guys, I have a graph with different three types of Nodes/vertices. for example , customer, physical address and email address. Customers may be linked to emails or to physical address. Now I want to extract all customers that may be linked to a particular physical address. I have been using the following query:
CREATE QUERY initial_queries(/* Parameters here */)
FOR GRAPH MyGraph SYNTAX(“v2”) {
Seed = {physical_address.*};
customers = SELECT p
FROM Seed:s - (_*1..6) - customer_number:p
WHERE [s.id](http://s.id/) == "6******" ;
PRINT customers;
}
But this returns only customers that are directly linked to the physical address.
I also want customers that can be indirectly linked to the physical address, like
C1 is linked to physical address A1
C1 and C2 are linked to email address E1
So based on this I want to extract a relationship that shows C2 is also linked to A1. Can anybody help with this ?
CREATE QUERY customers(vertex<address> input) FOR GRAPH MyGraph {
SetAccum<vertex> @@customers;
OrAccum @visited;
Start (ANY) = {input};
while Start.size() > 0 do
Start = Select t from Start:s-(:e)-:t
where t.@visited == false
accum t.@visited += true,
if t.type == "customer" then
@@customers += t
end;
end;
print @@customers;
}
What we’re doing in this query is we traverse every connection starting from an initial address vertex. If a target vertex is of type customer, we add it to the SetAccum, which we print at the end. The loop exits when there are no more unvisited vertices to traverse to.
We’re using query syntax v1 for this query - v2’s performance is a bit slower than v1 at the moment. We are working on optimizing v2 performance.