Your final approach (in your comments) has these drawbacks:
- It only works if the appropriate
Annotation
node already exists. - You are hardcoding the "cool" string in 2 places. I presume what you really want is to be able to do the same thing with any string.
EDITED
The following modified query should solve both of the above issues, efficiently, and also creates the Annotation
node if necessary.
- It uses
MERGE
to: create theAnnotation
if and only if it does not already exist. - It uses
CREATE UNIQUE
to create theisRelatedTo
relationship if it does not already exist. - It allows you to specify a
term
parameter for the string that you want to filter for (and use as theKeyword
for theAnnotation
). Passing the string as a parameter can make your query much faster.
MATCH (p:Paper) WHERE p.Title =~ (".*" + {term} + ".*") MERGE (a:Annotation {Keyword: {term}}) CREATE UNIQUE (p)-[:isRelatedTo]->(a) RETURN p, a;
Go to this console to test this (without the term
parameter).