Take the 2-minute tour ×

Hi I have document with fields like (title, content, datetime) I want to sort the results with the following formula

1) title boosts 2.5

2) content boost 1.5

3) IMPORTANT (boost those documents that is newer means datetime field is near today date) boost 3

how can I write a query considering the above criteria what should I do for #3

any help would be greatly appreciate.

share|improve this question
For example I need to find "SomeTitle" and "SomeBody" with the above criteria i have 1) SomeTitle, SomeBody, 4 day ago 2) SomeTitle, Some, 1 day ago I want to show the second item first what is the best query for obtain this –  Ehsan Jul 29 '10 at 16:29
add comment

2 Answers

+title:foo^2.5 +content:bar^1.5 datetime:20100721^3

Obviously, fill in appropriate values for the datetime field. The key here is that the datetime term is not a required term; it only functions increase the score for documents that match the term. You can add another datetime term for yesterday's date, and another for the day before, and so on, while decreasing the boost as you get farther away from today's date.

share|improve this answer
This is completely unrelated to my question. I don't want to search for datetime I just want to score those documents that is rear to the current date, and i think it is a kind of scoring or sorting but i don't know how can i implement it –  Ehsan Jul 21 '10 at 20:33
Baja's answer is actually the right one, although lucene's syntax is a bit non-intuitive. basically, you want: "+(original query) scoreBoostQuery" This will only match things which match "original query". But it will have a boost for things which also match scoreBoostQuery. –  Xodarap Jul 26 '10 at 17:54
add comment

You can use a function query to boost the score for documents containing each of the text fields i.e. Title and Content (both ranked by date). Then after this multiplying the recency boost by your weightings given above.


{!boost b=product(recip(ms(NOW,datetime),3.16e-11,1,1),2.5)}Title:<query> 
{!boost b=product(recip(ms(NOW,Created),3.16e-11,1,1),1.5)}Content:<query>

You can't use a sort as the ordering of the secondary and tertiary sorts will be meaningless unless of course the precision of your dates is sufficiently low.

share|improve this answer
add comment

Your Answer


