views:

48

answers:

2

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

1) 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 ?

A: 

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

Guillaume Lebourgeois
will you give me an example ?
Ehsan
+1  A: 

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.

Mikos
You shouldn't need to boost the title or body. Because Lucene automatically lowers the score of longer text fields, the body will be scored lower than the title anyway.
Xodarap
yes i want to know exactly how can I write #2
Ehsan
Hope you didn't get the idea that you can get SO users to do your work for you. Just Google it.
Mikos
As you said, if #2 is related to only boosting i think the phrase is less than 15 character, and i think we are here to share knowledge not googling, cause everyone knows to google it first and then ask here
Ehsan
@Ehsan - I hope we do know to Google it first...And If you did Google, you would have noticed this link at the top:http://bit.ly/bcYWtJCould you be specific with your issue? It would help others help you.
Mikos