Possible to modify text search score based on another document attribute?

17 views
Skip to first unread message

Dave Challis

unread,
May 30, 2019, 6:02:50 AM5/30/19
to ArangoDB
For example, say I've got collection of products containing data such as:

{"name": "headphones", "rating": 4}

Is there any way (using a fulltext index, or search view, or custom function) to boost/modify the searches on the "name" field based on the "rating" field?

I'd like to allow the most relevant products to be found, but then also apply a small upwards boost for things with a high rating field.

Andrey Abramov

unread,
May 30, 2019, 10:47:48 AM5/30/19
to ArangoDB
Hi Dave,

That's possible in 3.5, check out the following example:

FOR d in myView 
SEARCH d.name IN [ 'foo', 'bar', 'baz' ] 
SORT BM25(d)*d.rating DESC // DESC is important to get the most relevant results first
RETURN d

you can return evaluated value as well:

FOR d in myView 
SEARCH d.name IN [ 'foo', 'bar', 'baz' ] 
LET score = BM25(d)*LOG(d.rating+1)
SORT score DESC
RETURN { d, score }

you can also use query time boost to modify overall score based on your search condition:

LET importance = 42
FOR d in myView 
SEARCH BOOST(d.name == 'importantName', importance) || d.name IN [ 'foo', 'bar', 'baz' ] 
LET score = BM25(d)*LOG(d.rating+1)
SORT score DESC
RETURN { d, score }

Dave Challis

unread,
May 30, 2019, 12:35:24 PM5/30/19
to ArangoDB
That sounds perfect, I look forward to 3.5, many thanks.
Reply all
Reply to author
Forward
0 new messages