Lucene term boosting with sunspot-rails

2019-08-12 00:49发布

I'm having an issue with Lucene's Term [Boosting][1] query syntax, specifically in Ruby on Rails via the sunspot_rails gem. This is whereby you can specify the weight of a specific term during a query, and is not related to the weighting of a particular field.

The HTML query generated by sunspot uses the qf parameter to specify the fields to be searched as configured, and the q parameter for the query itself. When the caret is added to a search term to specify a boost (i.e. q=searchterm^5) it returns no results, even though results would be returned without the boost term.

If, on the other hand, I create an HTTP query manually and manually specify the field to search (q=title_texts:searchterm^5), results are returned and scores seem affected by the boost.

In short, it appears as though query term boosting doesn't work in conjunction with fields specified with qf.

My application calls for search across several fields, using the respective boosts associated to those fields, conditionally in turn with boosting on individual terms of a query.

Any insight?

[1]: http://lucene.apache.org/java/2_9_1/queryparsersyntax.html#Boosting a Term

2条回答
做自己的国王
2楼-- · 2019-08-12 01:12

Sunspot uses the dismax parser for fulltext search, which eschews the usual Lucene query syntax in favor of a limited (but user-input-friendly) query syntax combined with a set of additional parameters (such as qf) that can be constructed by the client application to tune how search works. Sunspot provides support for per-field boost using the boost_fields method in the fulltext DSL:

http://outoftime.github.com/sunspot/docs/classes/Sunspot/DSL/Fulltext.html#M000129

查看更多
男人必须洒脱
3楼-- · 2019-08-12 01:12

The solution I have found is to use DisMax, but adding the bq parameter with a boolean string with the boosted terms therein.

查看更多
登录 后发表回答