【问题标题】:Neo4j combine or union results from two Full text indexNeo4j 合并或合并来自两个全文索引的结果
【发布时间】:2020-01-22 10:11:04
【问题描述】:

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

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

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

我的要求是结合或联合符合任何条件的两者。你能帮我实现吗?

提前致谢。

【问题讨论】:

    标签: neo4j full-text-search full-text-indexing fulltext-index


    【解决方案1】:

    如果索引查找失败,那么您将无法取回任何行(并且该行的先前数据被清除),这可能会使您的查询短路。您可能想尝试两个结果的 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
    

    【讨论】:

    • 感谢您的快速回复。这可行,但我的要求是我想发送回复以匹配其他 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 Match (final)-[RELATION]-(Output:Node5) return Output
    • 在这种情况下你需要一些post-UNION processing,知识库文章有一些你可以使用的方法。也许apoc.cypher.run() 会帮助你。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-08
    • 1970-01-01
    • 2020-05-03
    相关资源
    最近更新 更多