0

I have a case of scenario that there are TOURIST who wants to travel and every country has VISA control and there is a path along countries so some of connections you are not allowed to visit that specific country. There are 3 types of VISA (A,B,C) and i want make a query that makes a single traversal and returns which tourists can go which countries with their VISA types. Each tourist can have variations of those 3 VISA types and it's mapped between edges of COUNTRY nodes as a property of a enum value like this :

NOT_ALLOWED_TO_PASS: 0
VISA_A: 1
VISA_B: 2
VISA_C: 4
VISA_AB: 3
VISA_AC: 5
VISA_BC: 6
VISA_ABC:7

I have 2 types of nodes and 2 types of relations;

node t > "TOURIST" which has t.name and id,

node c > "COUNTRY" which has c.name and id

relation r1 > "CAN_START" which has only id // tourist can start from it's linked nodes

relation r2 > "CAN_PASS" which has r.visa_type //enum that i explained above

t - [r:can_start]-c

c- [r:can_pass]-c

I've achieved this with implementing this query below:

Match (t:Tourist)-[r1:CAN_START]-(c1:Country)
match path= (c1:Country) -[CAN_PASS*] -(c2:Country)
where all(r2 in relationships(path)where  r2.visa_type IN ["1","3","5","7"]) //this for visa_type A
return t.name as Tourist, c1.name+collect(c2.name) as CountryListWithTypeA

i can get my result with doing union etc but it traverses network 3 times.I want to get this 3 different results within a single traversal.

How can i do that ?

1 Answer 1

0

You can OR the conditions like this:

Match (t:Tourist)-[r1:CAN_START]-(c1:Country)
match path=(c1:Country)-[CAN_PASS*]-(c2:Country)
where all(r2 in relationships(path) where r2.visa_type IN ["1","3","5","7"]) 
OR all(r2 in relationships(path) where r2.visa_type IN ["2","6"])
OR all(r2 in relationships(path) where r2.visa_type = "4")  
return t.name as Tourist, c1.name+collect(c2.name) as CountryListWithTypeA
Sign up to request clarification or add additional context in comments.

1 Comment

that simply returns the first possible nodes for visa_A, i want to return 3 different columns which are : CountryListWithTypeA ,CountryListWithTypeB ,CountryListWithTypeC. And i want to do this within a single traversal.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.