cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Searching for disjunctions of paths

pebbe
Node Link

I would like to do a query like this:

match (n:Node{cat:'rel'})-[:REL{rel:'body'}]->(n2:Node)
match (n2{cat:'ssub'})
or (n2{cat:'conj'})-[:REL{rel:'cnj'}]->(:Node{cat:'ssub'})
or (n2{cat:'du'})-[:REL]->(:Node{cat:'ssub'})
return n;

But you can't use or.

What else can I do?

1 ACCEPTED SOLUTION

That works. The results are correct.

View solution in original post

5 REPLIES 5

its not really clear what you are looking to do.
You can include a or in a WHERE clause. Do you want to do

match (n2{cat:'ssub'}) 
where 
      (n2{cat:'conj'})-[:REL{rel:'cnj'}]->(:Node{cat:'ssub'})
 or  (n2{cat:'du'})-[:REL]->(:Node{cat:'ssub'})

or are you also looking for an OPTIONAL MATCH ??

With where it looks like this:

match (n:Node{cat:'rel'})-[:REL{rel:'body'}]->(n2:Node)
where
    (n2{cat:'ssub'}) 
 or (n2{cat:'conj'})-[:REL{rel:'cnj'}]->(:Node{cat:'ssub'})
 or (n2{cat:'du'})-[:REL]->(:Node{cat:'ssub'})
 return n;

This generates an error:

Neo.ClientError.Statement.SyntaxError: Type mismatch: expected Boolean but was Map (line 3, column 6 (offset: 67))
"    (n2{cat:'ssub'}) "
      ^

This works...

match (n:Node{cat:'rel'})-[:REL{rel:'body'}]->(n1:Node)
where (n1{cat:'ssub'}) is not null
   or (n1{cat:'conj'})-[:REL{rel:'cnj'}]->(:Node{cat:'ssub'}) is not null
   or (n1{cat:'du'})-[:REL]->(:Node{cat:'ssub'}) is not null
return distinct n.sentid as sentid, n.id as id, n1.cat
order by sentid, id;

But I get some results where n1.cat is neither ssub nor conj nor du, so these are clearly wrong.

change the

where
    (n2{cat:'ssub'})

to

where
    n2.cat='ssub'

That works. The results are correct.

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

All the sessions of the conference are now available online