Neo4j 合并或联合来自两个全文索引的结果

Neo4j combine or union results from two Full text index

我在下面尝试了全文索引,如下所示

CALL db.index.fulltext.queryNodes("index1", "x") YIELD node as node1, score as score1
With collect({id: node1.id, score: score1}) as rows1
CALL db.index.fulltext.queryNodes("index2", "name:Y") YIELD node as node2, score as score2
With collect({id: node2.id, score: score2}) as rows2, rows1
return rows1 + rows2 as final

以上returns结果如果两者都有一些记录,如果node2没有任何匹配结果,那么即使node1结果很少,最终结果也是空的。

我的要求是合并或并集符合任何条件的两者。你能帮我实现这个目标吗?

提前致谢。

如果索引查找失败,那么您将得不到任何行(并且该行的先前数据将被清除),这可能会使您的查询短路。您可能想尝试使用两个结果的 UNION:

CALL db.index.fulltext.queryNodes("index1", "x") YIELD node, score
RETURN node, score
UNION
CALL db.index.fulltext.queryNodes("index2", "name:Y") YIELD node, score
RETURN node, score