Query for lucene search result
I have a storage of news with the following fields (Title, Body, NewsDate)
I need a best query with the following criteria1)开发者_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 placeAny 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
Index time boosting would be like:
Field fld = new Field(....); fld.setBoost(10f);//10x more important, 1 is default
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.
精彩评论