How to boost Lucene queries with field values?

Hello,

I am curious how to boost full-text queries with document (node) values. We do get a field from our source systems that contain a weight that we shall use as multiplicator.

Lucene allows to influence the scores via boosting. This could be done via index or query time boosting. But my problem is that this shall not be done via a flat factor, but by a custom weight that is individual per document.

I have found this blog post:


In there you can find how to boost with a flat value. Unfortunately that did not help me with my issue.

When doing fulltext index queries via CALL db.index.fulltext.queryNodes(<indexName>, <luceneQuery>) YIELD node, score RETURN node.title, score
you can pass in a lucene query as second argument. For details on lucene query syntax see https://lucene.apache.org/core/5_5_5/queryparser/org/apache/lucene/queryparser/classic/package-summary.html#Boosting_a_Term.

Assume you have two properties title and description and you want to search for liar boosting results on title you could do

call db.index.fulltext.queryNodes(myindex, "title:liar^4 OR description:liar") yield node, score return node, score

Thank you Stefan, this is what I meant when: I found out how to boost it with a flat value :slight_smile:

We do get for each record an individual weight that we shall take into account. So image a document has three attributes

  • title
  • description
  • weight

Document-1 would have the following values

  • title: Not telling lies
  • description: Trust the author
  • weight: 1

Document-2 would have the following values

  • title: Another title
  • description: Some great description
  • weight: 3

I would like to perform this

call db.index.fulltext.queryNodes(myindex, "title:liar^weight OR description:liar") yield node, score return node, score

so you want the weight property being a dynamic boost factor on a per-record level?

1 Like

Exactly :slight_smile:

Lucene does support that, see https://lucene.apache.org/core/5_5_5/core/org/apache/lucene/search/package-summary.html#scoring and https://lucene.apache.org/core/5_5_5/core/org/apache/lucene/document/Field.html#setBoost-float-

However that is currently not used by Neo4j fulltext indexing and would require a change in Neo4j itself. Maybe create a github issue for this and reference this thread there.

1 Like