首页 > 解决方案 > 如何汇总分数

问题描述

我有这个密码查询:

CALL db.index.fulltext.queryNodes("names","John Snow") YIELD node, score
WITH node, score MATCH (node)-[c:ACTIVE]->() WHERE c.is_active = 'True'
RETURN DISTINCT node, score ORDER BY score DESC LIMIT 10

我想根据分数百分比过滤结果,所以可能我需要percentileDisc() as pd聚合然后WHERE score > pd子句。我如何在这里应用它?percentileDisc(score, 0.5)总是给自己打分。

标签: neo4jcypher

解决方案


这应该有效:

CALL db.index.fulltext.queryNodes("names","John Snow") YIELD node, score
WHERE EXISTS ((node)-[:ACTIVE {is_active: 'True'}]->())
WITH COLLECT({node: node, score: score}) AS data, percentileDisc(score, 0.5) AS p
UNWIND data AS d
WITH p, d
WHERE d.score > p
RETURN p, d.node AS node, d.score AS score
ORDER BY score DESC LIMIT 10

推荐阅读