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 org.apache.lucene.queryparser.classic (Lucene 5.5.5 API).
Assume you have two properties title and description and you want to search for liar boosting results on title you could do
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.
index the weight field and in query list all the weight like below
call db.index.fulltext.queryNodes(myindex, "(title:liar OR description:liar) AND (weight:3^3 OR weight:2^2) weight:1^1") yield node, score return node, score
let’s combine the rating-boosting and the time decay effect in a single query. And just so you know you can always manipulate results later with cypher, let’s add a filter that will return only thrillers.
WITH apoc.text.join([x in range(0,10) |
"string_release_date:" + toString((date().year — x)) + "^" +
toString(10-x)]," ") as time_decay
CALL db.index.fulltext.queryNodes("MovieIndex", "title:dream string_rating:[50 TO 99]^2 "+ time_decay) YIELD node, score
// filter only thrillers
MATCH (node)-[:HAS_TAG]->(:MovieTag{id:'thriller'})
RETURN node.title as title,score
LIMIT 5
It looks like the author is using a node property as a multiplier for boost.