0

As a follow-up to my previous question I would like to know how to use logical operators AND, OR and NOT when performing an index query.

Using the same book club database scenario what would the Cypher query look like:

  1. Find all readers that have read (Fiction AND Non-Fiction) OR Reference books?
  2. Find all readers that have read (Fiction OR Non-Fiction) AND NOT Reference books?

I'm pretty sure that those two examples should provide enough material to cover any other scenario.

EDIT: I created a Neo4j Console scenario to demonstrate this.

Community
  • 1
  • 1
Dave Michener
  • 1,058
  • 11
  • 30

1 Answers1

0

For your first use case, you can give this a try. Second can be done on similar lines -

start b1=node:MyBookIndex('Genre:Fiction'), 
      b2=node:MyBookIndex('Genre:Non-Fiction'),
      b3=node:MyBookIndex('Genre:Reference')
match b1-[a?:HasRead]-r,
      b2-[b?:HasRead]-r,
      b3-[c?:HasRead]-r
where (a <> null and b <> null) or (c <> null)
return r.ReaderName

(Note: not tested)

Gopi
  • 10,073
  • 4
  • 31
  • 45
  • That didn't work as I get the following using the Neo4j Web admin console's Data browser tab to execute the query: > Invalid query > This pattern is not supported right now. These pattern elements are part of multiple double optional paths, and that is not allowed. r1,F,r2 – Dave Michener May 08 '13 at 17:59
  • Note that in my previous comment the `"r1, F, r2"` mentioned is from a test using my data. Using the example from @Gopi's reply you would see `"a, r, b"`. – Dave Michener May 08 '13 at 18:08