Lucene term boosting with sunspot-rails

南笙酒味 提交于 2019-12-24 17:25:17

问题


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


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/4186844/lucene-term-boosting-with-sunspot-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!