Databases Reference
In-Depth Information
• The syntax (theater)<-[:VENUE]-() uses the anonymous node, hence the empty
parentheses. Knowing the data as we do, we expect the anonymous node to match
performances, but because we're not interested in using the details of individual
performances elsewhere in the query or in the results, we don't name the node or
bind it to an identifier.
• We use the anonymous node again to link the performance to the production ( ()-
[:PERFORMANCE_OF]->() ). If we were interested in returning details of perform‐
ances and productions, we would replace these occurrences of the anonymous node
with identifiers: (performance)-[:PERFORMANCE_OF]->(production) .
• The remainder of the MATCH is a straightforward (play)<-[:WROTE_PLAY]-
(bard) node-to-relationship-to-node pattern match. This pattern ensures we only
return plays written by Shakespeare. Because (play) is joined to the anonymous
production node, and by way of that to the performance node, we can safely infer
that it has been performed in Newcastle's Theatre Royal. In naming the play node
we bring it into scope so that we can use it later in the query.
At this point our query looks like this:
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)<-[:WROTE_PLAY]-(bard)
RETURN DISTINCT play.title AS play
Running this query yields all the Shakespeare plays that have been performed at the
Theatre Royal in Newcastle:
+-----------------+
| play |
+-----------------+
| "Julius Caesar" |
| "The Tempest" |
+-----------------+
2 rows
That's great if we're interested in the entire history of Shakespeare at the Theatre Royal,
but if we're interested only in specific plays, productions, or performances, we need
somehow to constrain the set of results.
Constraining Matches
We constrain graph matches using the WHERE clause. WHERE allows us to eliminate
matched subgraphs from the results, by stipulating one or more of the following:
• That certain paths must be present (or absent) in the matched subgraphs.
Search WWH ::




Custom Search