Databases Reference
In-Depth Information
• That specific properties on matched nodes and relationships must be present (or
absent), irrespective of their values.
• That certain properties on matched nodes and relationships must have specific
values.
• That other arbitrarily complex expression predicates must be met.
Compared to the MATCH clause, which describes structural relationships and assigns
identifiers to parts of the pattern, WHERE is more of a tuning exercise to filter down the
current pattern match. Let's imagine, for example, that we want to restrict the range of
plays in our results to those from Shakespeare's final period , which is generally accepted
to have begun around 1608. We do this by filtering on the year property of matched
WROTE_PLAY relationships. To enable this filtering, we adjust the MATCH clause, binding
the WROTE_PLAY relationship to an identifier, which we'll call w . Relationship identifiers
come before the colon that prefixes a relationship's name. We then add a WHERE clause
that filters on this relationship's year property:
START theater= node :venue(name= 'Theatre Royal' ),
newcastle= node :city(name= 'Newcastle' ),
bard= node :author(lastname= 'Shakespeare' )
MATCH (newcastle)<-[:STREET|CITY*1..2]-(theater)
<-[:VENUE]-()-[:PERFORMANCE_OF]->()-[:PRODUCTION_OF]->
(play)<-[w:WROTE_PLAY]-(bard)
WHERE w.year > 1608
RETURN DISTINCT play.title AS play
Adding this WHERE clause means that for each successful match, the Cypher execution
engine checks that the WROTE_PLAY relationship between the Shakespeare node and the
matched play has a year property with a value greater than 1608. Matches with a
WROTE_PLAY relationship whose year value is greater than 1608 will pass the test; these
plays will then be included in the results. Matches that fail the test will not be included
in the results. By adding this clause, we ensure that only plays from Shakespeare's late
period are returned:
+---------------+
| play |
+---------------+
| "The Tempest" |
+---------------+
1 row
Processing Results
Cypher's RETURN clause allows us to perform some processing on the matched graph
data before returning it to the user (or the application) that executed the query.
Search WWH ::




Custom Search