neo4j 在一个子查询中进行两次全文搜索

neo4j two fulltext searches in one subquery

我正在尝试从两个节点中找到得分最高的全文查询:

(node1)-[:ACTED_IN]-(node2)

Where node1 can be e.g., a search:
CALL db.index.fulltext.queryNodes('movie_search', 'Matrix')
YIELD score, node as node1 

And node2 is the analogous: 
CALL db.index.fulltext.queryNodes('actor search', 'Fish')
YIELD score as scoreC, node as nodeC 

这可能是一个子搜索(即,在第一次搜索后对图进行子集化)。我假设这可能是一个子查询,但仍在尝试了解如何使用子查询来完成此操作。

理想情况下,顶部关系将 return 根据全文搜索

Movie 和 Actor 之间的关系对
#Movie, Actor,
"The Matrix", "Laurence Fishburne"
"The Matrix Reloaded", "Laurence Fishburne"
"Matrix Revolutions", "Laurence Fishburne"
"Apocalypse Now", "Laurence Fishburne # this one would have a lower score, but probably also show up
...

我们可以使用第一次搜索的结果来提高第二次搜索的分数,基于演员节点在哪个电影节点中扮演角色。

你没有告诉我们你想用数学方法对分数做什么,所以对于这个例子,我只是添加它们。

CALL db.index.fulltext.queryNodes('movie_search', 'Matrix')
YIELD score, node as movie
WITH collect([movie, score]) as movieScores

CALL db.index.fulltext.queryNodes('actor search', 'Fish')
YIELD score, node as actor
MATCH (actor)-[:ACTED_IN]->(movie:Movie)
WITH score, actor, movie, coalesce([pair IN movieScores WHERE pair[0] = movie | pair[1]][0], 0) as movieScore
RETURN movie.title as movie, actor.name as actor, score + movieScore as totalScore
ORDER BY totalScore DESC

我们正在做的是将电影及其分数收集到一个列表中,我们以后可以交叉引用。在我们得到演员节点后,我们找到他们演过的所有电影,并为每一行找到该电影的 movie/score 对(如果找到 none,则使用 coalesce() 使用默认值 0),然后我们添加分数并对它们进行排序。