2017-05-05 31 views
0

我已经使用Lucene的全文功能对Neo4j中的书籍节点的title属性进行了索引。 当我想要的所有节点标题来搜索特定的词(如wars),我可以做到以下几点:检索Neo4j Lucene每个文档的分数,而不仅仅是订单

 IndexHits<Node> nodes = graphDb.index().forNodes("node_auto_index").query("title:wars"); 
    for (Node n : nodes) { 
     //do something 
    } 
    nodes.close(); 

这个方法返回的Lucene保持一定的频率得分排序的节点。

我想知道与结果中每个节点相关的实际分数。例如,如果该指数内部看起来如下:

wars -> id8:4, id3:3, id1:2

我想返回相应的分数4,3和1,而不仅仅是IDS。

谢谢。

回答

1

您可以使用以下方法:

IndexHits<Node> hits = graphDb.index().forNodes("node_auto_index").query("title:wars"); 
while (hits.hasNext()) { 
    Node node = hits.next(); 
    float weight = hits.currentScore(); 
} 
+0

谢谢!是否有恒定的时间方法来检索评分给定的术语和文档ID?例如'(战争,id1)= 2'? – kami

相关问题