neo4j - Neo4j 中的多级全文搜索
问题描述
当我在索引上调用 db.index.fulltext.queryNodes() 时,我可以对结果运行另一个全文查询吗?我需要在我的数据库中搜索跨不同标签的 7-8 个不同属性,每个属性具有不同的搜索参数。我该怎么做?如果我使用 reduce() 函数或 apoc.coll.intersection 并尝试获得一个交集,例如...
CALL db.index.fulltext.queryNodes("first_name", "manas~")
YIELD node as first_names
WITH collect(first_names) as first_name_list
CALL db.index.fulltext.queryNodes("aliases", "boncha~")
YIELD node as aliases
WITH collect(aliases) as alias_list,first_name_list
RETURN apoc.coll.intersection(first_name_list, alias_list) AS output
LIMIT 5
这不会导致内存膨胀吗?
解决方案
如果使用 Neo4j 4.1+,最好使用子查询:
CALL {
CALL db.index.fulltext.queryNodes("first_name", "manas~")
YIELD node, score
RETURN node, score
UNION ALL
CALL db.index.fulltext.queryNodes("aliases", "boncha~")
YIELD node, score
RETURN node, score
}
RETURN node, sum(score) AS totalScore
ORDER BY totalScore DESC
对于交集,您可以计算每个节点它们有多少匹配,因此如果它们在两个查询中匹配,则计数为 2:
CALL {
CALL db.index.fulltext.queryNodes("first_name", "manas~")
YIELD node, score
RETURN node, score
UNION ALL
CALL db.index.fulltext.queryNodes("aliases", "boncha~")
YIELD node, score
RETURN node, score
}
WITH node, count(*) AS matches, sum(score) AS totalScore
WITH node, matches, totalScore
WHERE matches = 2
ORDER BY totalScore DESC
RETURN node, totalScore
推荐阅读
- postgresql - 如何在 psql 查询中将文本数字转换为整数类型
- html - 如何从发布请求中获取数据?
- android - 将覆盖设置为假后,锚定覆盖不隐藏?扑
- linux - bash 错误 \r\r': 没有这样的文件或目录
- node.js - 我如何使用 puppeteer 截取网站并将其发送到消息 Discord.js?
- r - 如何在 geom_plot() 中正确添加平均值、标准差和抖动?ggplot2
- javascript - 在javascript中将双引号字符串拆分为数组
- flutter - 如何设置主页异步和条件?
- regex - 如何使用 Unicode 正则表达式验证字符串的一部分
- sql - 为 IP 地址创建 SQL Server UDDT?