我使用 Lucene 的全文功能在 Neo4j 中索引了图书节点的 title
属性。
当我想在所有节点的标题中搜索特定术语(例如 wars
)时,我可以执行以下操作:
IndexHits<Node> nodes = graphDb.index().forNodes("node_auto_index").query("title:wars");
for (Node n : nodes) {
//do something
}
nodes.close();
这将返回按 Lucene 维护的某些频率分数顺序排序的节点。
我想知道与结果中每个节点相关的实际分数。例如,如果索引内部如下所示:
war -> id8:4、id3:3、id1:2
我想返回相应的分数 4,3 和 1,而不仅仅是 id。
谢谢。
最佳答案
您可以使用以下内容:
IndexHits<Node> hits = graphDb.index().forNodes("node_auto_index").query("title:wars");
while (hits.hasNext()) {
Node node = hits.next();
float weight = hits.currentScore();
}
关于java - 检索每个文档 Neo4j Lucene 的分数,而不仅仅是顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43798334/