[英]Neo4J Arrays in MATCH query
The intention of my Query is to mark similar words. 我的查询的目的是标记相似的单词。
CREATE CONSTRAINT ON (n:Word) ASSERT n.title IS UNIQUE
MATCH (n) WHERE ID(n)={id}
MERGE (o:Word{title:{title}})
WITH n,o MERGE n-[r:SIMILAR{location:'{location}'}]->o
RETURN ID(o)
n
is a existing Word. n
是一个现有的单词。 I want to create the relationsship & the other Word ( o
) if they don't exist yet. 我想创建关系和其他单词(
o
)(如果尚不存在)。
The Problem with this query is, that it works for one title, but if I use a Array with titles the title of the Word o
is the whole Array. 此查询的问题是,它适用于一个标题,但是如果我使用带有标题的数组,则单词
o
的标题就是整个数组。
Can you suggest me another Query that does the same and/or a way to pass multiple values to title. 您能否建议我另一个执行相同的查询和/或将多个值传递给标题的方法。
I'm using the Neography Gem on Rails eg the REST API 我正在使用Rails上的Neography宝石,例如REST API
To use individual values in a parameter array you can use FOREACH
, something like 要在参数数组中使用单个值,可以使用
FOREACH
,例如
MATCH (n)
WHERE ID (n) = {id}
FOREACH (t IN {title} |
MERGE (o:Word {title:t})
MERGE n-[:SIMILAR]->o
)
If you want to pass location
also as a parameter (it is actually a string literal in your current query), such that merge operations for n
should happen for each title, location
pair in a parameter array, you can try 如果您还希望将
location
作为参数传递(它实际上是当前查询中的字符串文字),以便对参数数组中的每个title, location
对进行n
合并操作,则可以尝试
FOREACH (map IN {maps} |
MERGE (o:Word {title:map.title})
MERGE n-[:SIMILAR {location:map.location}]->o
)
with a parameter that looks something like 参数看起来像
{
"maps": [
{
"title":"neography",
"location":"1.."
},{
"title":"coreography",
"location":"3.."
}
]
}
Other suggestions: 其他建议:
MATCH (n:Word {title:"geography"})
MATCH (n:Word {title:"geography"})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.