Hey,

I'm not familiar w/ an out-of-the-box feature like that in Lucene, but what
you could do is:

   1. Add to each document a field, let's say "datepld" by using the
   d.add(new Field("datepld", TokenStream)).
   2. Write a special TokenStream which its next() methods add a single,
   fixed, term (the value is not important) with a payload. The payload value
   represents the date value of the document, represented as long or int (if
   you don't care about ms precision).
   3. Write a HitCollector which extends TopDocCollector and overwrite its
   collect() method. When it's called, it skips the "datepld" posting list,
   reads the payload value and adds it to the score given to collect() (or do
   some other manipulation on the score given to collect(), which represents
   the relevancy of the this document to the query the user submit).

Another option is to go through steps 1 and 2, but instead writing a
HitCollector you can write a Similarity, for example DateBoostSimilarity
which extends DefaultSimilarity, and override its scorePayload() method.
This method already passes you the payload information of that field (you
can compare the fieldName to be on the safe side, in case you have other
fields w/ payloads as well). Convert the payload info to long (or int,
depending how you indexed it) and return it.

I prefer method #1 since it gives you complete control of the document's
score.

Note that there are some classes in Lucene which have the "Boost" name in
them, but I must admit I haven't dug deep into them yet: BoostingTermQuery,
BoostingSpanScorer and BoostingTermWeight.

BTW, you can look at TestBoostingTermQuery to see an implementation of #2.

Hope this helps,
Shai

On Thu, Jan 15, 2009 at 5:44 AM, mitu2009 <musicfrea...@gmail.com> wrote:

>
> Hi,
>
> Is it possible to bubble up newer records in lucene search results? ie.I
> want Lucene to give a higher score to records which are closer to today's
> date.
> --
> View this message in context:
> http://www.nabble.com/Bubbling-up-newer-records-tp21470766p21470766.html
> Sent from the Lucene - Java Developer mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-dev-unsubscr...@lucene.apache.org
> For additional commands, e-mail: java-dev-h...@lucene.apache.org
>
>

Reply via email to