将WHERE IN与COLLECT一起使用,其中collect正在创建地图

时间:2018-05-24 05:27:38

标签: neo4j cypher collect

我有一个neo4j图来定义单词关系。每个单词节点与任何其他类似性质的单词具有[r:IS_RELATED_TO]关系。这种关系有相似之处。

我需要搜索传入的单词列表。以下查询还有很长的路要走,但我仍然坚持如何使用WHERE子句。

WITH 
['landscape', 'photography', 'exposure'] as searchTermWords

//get all the words similar to those in the search term
match 
(w1:WordGraph_Word)-[r:IS_RELATED_TO]-(w2:WordGraph_Word)
where w1.word in searchTermWords
WITH COLLECT({
word1:w1,
word2:w2,
similarity:r.similarityValue
}) as similarWords



//get all question collections with those similar words
match 
(qc:QuestionCollection)-[:HAS_WORD]->(w:WordGraph_Word)
where w in similarWords.word1

return *

当我执行此操作时,我收到以下错误:

Type mismatch: expected Any, Map, Node or Relationship 
but was List<Map> (line 19, column 12 (offset: 437))
"where w in similarWords.word1"

我也试过用#34;其中w用类似的词。[&#39; word1&#39;]&#34;那也失败了。

任何想法都会受到欢迎。

谢谢!

1 个答案:

答案 0 :(得分:0)

嗯,similarWords是集合,而不是地图,因此键是整数,每个元素都是您在collect()中创建的地图。

为了让它更容易一点,我建议收集一点点改动:

WITH 
['landscape', 'photography', 'exposure'] as searchTermWords

//get all the words similar to those in the search term
MATCH
(w1:WordGraph_Word)-[r:IS_RELATED_TO]-(w2:WordGraph_Word)
where w1.word in searchTermWords
WITH w1, collect({word: w2, similarity: r.similarityValue}) AS similarWords
MATCH (w1)<-[:HAS_WORD]-(qc:QuestionCollection)
RETURN w1, similarWords, collect(qc) AS questions