首页 > 解决方案 > 从 Neo4j 获取每个组的最高搜索结果

问题描述

我正在使用 Neo4j 的全文搜索功能来获取最接近搜索字符串输入列表的匹配技能。在密码查询下面。

UNWIND ["nursing care requirements", "relatives tutoring student nurses", "blood pressures", "emotional support", "intravenous infusions", "junior staff", "patient samples", "pulses", "workloads"] AS x
CALL db.index.fulltext.queryNodes("full-text-skills", x) YIELD node, score
RETURN x, node.name, score

它运行良好并返回所有匹配结果(上例为 1000 行)。score现在我想根据返回的属性获取最匹配的技能db.index.fulltext.queryNodes(列表中每个输入项 1 行)。我尝试在return语句之后添加限制,但它限制了整个输出。我真正想要的是在输入列表中限制每个项目的搜索结果。

标签: neo4jneo4j-apoc

解决方案


我终于找到了解决上述问题的方法。我们可以使用 collect 来收集每组的结果,并根据限制我们可以得到每组的结果。密码查询将是 -

UNWIND ["nursing care requirements", "relatives tutoring student nurses", "blood pressures", "emotional support", "intravenous infusions", "junior staff", "patient samples", "pulses", "workloads"] AS x
CALL db.index.fulltext.queryNodes("full-text-skills", x) YIELD node, score
RETURN x,collect(node.name)[0..3]

推荐阅读