0
votes

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.

1

1 Answers

1
votes

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();
}