开发者

Query for lucene search result

开发者 https://www.devze.com 2023-01-09 16:17 出处:网络
I have a storage of news with the following fields (Title, Body, NewsDate) I need a best query with the following criteria

I have a storage of news with the following fields (Title, Body, NewsDate)

I need a best query with the following criteria

1)开发者_JAVA技巧 title is more important but less than date

2) date should be compare to the current date if the date of a document is near the current date it is more valuable (NOTE: It doesn't mean that sorting descending on news date cause there maybe results that their title and its body is more relevant but its older) this is just another factor for searching and i think it needs custom sorting

3) body has is in the third place

Any solution ?


Like @Guillaume said, you need to use boosting.

You can employ in 2 places: one while indexing (boost title and body), and second (the date field) while querying. The date-field is query-time since it is dynamic

  1. Index time boosting would be like:

    Field fld = new Field(....); fld.setBoost(10f);//10x more important, 1 is default

  2. Query time boost would be get the date diff (say in days or mins) and apply the boost inversely i.e. the greater the diff. the smaller the boost.


You should use Boosting in your schema, instead of very complicated queries.

0

精彩评论

暂无评论...
验证码 换一张
取 消