我有以下neo4j数据库:http://console.neo4j.org/?id=gkkmha
然后运行以下查询:
MATCH (person:Person)-[:plays]->(instrument:Instrument {name: 'Drums'})
OPTIONAL MATCH (band:Band { name: 'bandname' })-[:genre]->(genre:Genre)<-[:likes]-(person)
OPTIONAL MATCH (band)-[:influenced]->(influence:Influence)<-[:influenced]-(person)
RETURN person.name, COLLECT(genre.name) as matched_genres, COLLECT (influence.name) as matched_influences, (count(genre)/4.0) as score
ORDER BY score DESC我希望能够找到音乐家谁演奏指定的乐器,但也有类似的体裁匹配和影响的乐队。到目前为止,我已经完成了匹配类型的工作,并返回了这些类型的列表,但我不能让它对影响做同样的事情。我希望它返回一个匹配的影响列表以及。
理想情况下,它还能得到乐队与之相关的各种类型和影响的总数(尽管这只是一个很好的选择)。
当前产出:
+-----------------------------------------------------------------+
| person.name | matched_genres | matched_influences | score |
+-----------------------------------------------------------------+
| "Robert Smith" | ["Soul","Motown"] | [] | 0.5 |
| "Alex Smith" | ["Soul"] | [] | 0.25 |
| "Mr Drummer" | [] | [] | 0.0 |
+-----------------------------------------------------------------+
3 rows
54 ms有什么想法吗?
发布于 2014-07-25 13:44:45
我相信你有一个错误,而不是:influenced,尝试:Influenced
MATCH (person:Person)-[:plays]->(instrument:Instrument { name: 'Drums' })
OPTIONAL
MATCH (band:Band { name: 'bandname' })-[:genre]->(genre:Genre)<-[:likes]-(person)
OPTIONAL
MATCH (band)-[:Influenced]->(influence:Influence)<-[:Influenced]-(person)
RETURN person.name, COLLECT(genre.name) AS matched_genres, COLLECT(influence.name) AS matched_influences,(count(genre)/4.0) AS score
ORDER BY score DESChttps://stackoverflow.com/questions/24956626
复制相似问题