kami
kami

Reputation: 361

Retrieve scores for each document Neo4j Lucene, not just the order

I have indexed the title property of a book node in Neo4j using the full-text capabilities of Lucene. When I want to search for a particular term(like wars) in a title across all nodes, I can do the following:

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

This returns the nodes sorted in order of some frequency score maintained by Lucene.

I would like to know the actual score associated to each of the nodes in the result. For example if the index internally looks as follows:

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

I would like to return the corresponding scores 4,3 and 1 instead of just the ids.

Thanks.

Upvotes: 0

Views: 97

Answers (1)

Christophe Willemsen
Christophe Willemsen

Reputation: 20185

You can use the following :

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

Upvotes: 1

Related Questions