简体   繁体   中英

How do I create relationships from substrings in Neo4J

I have a set of 'tag' nodes and 'category' nodes, and wanted to generate relationships between the two by testing if the category's name is a substring of the tag's name. This was my approach thus far (apologies, I'm one day into cypher so this may be fundamentally flawed but I am yet to find something equivalent to reverse engineer thus far)

match(cat:category)
match(tag:tag) where tag.name =~ '.*'+cat.name+'.*'
merge (tag)-[:belongs_to]-(cat)

Error:

Type mismatch: expected Boolean, Collection<Boolean> or Collection<Collection<Boolean>> but was String (line 2, column 48 (offset: 67))
"match(tag:tag) where tag.name =~ '.*'+cat.name+'.*'"

The error seems to revolve around the use of =~ and concatenated strings, any advice would be appreciated!

The problem is with the order in which the expression in the WHERE clause is evaluated. You can get around it by being explicit: enclose the string concatenation in parentheses.

WHERE tag.name =~ ('.*' + cat.name + '.*')

I tried quickly looking for documentation on cypher operator precedence but it wasn't in the operator chapter , so I'm not sure where this is documented.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM