You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Philipp Chudinov <mo...@basko.ru> on 2002/09/05 02:59:35 UTC

Re: Order by date:SOLVED and HitsIterator sorting

Thank you Peter and Terry!
The SearchBean is the remedy.
One more question:
from here:
http://www.mail-archive.com/lucene-user@jakarta.apache.org/msg01898.html

   From: Terry Steichen
   Subject: Re: SearchBean Persistence
   Date: Fri, 05 Jul 2002 07:39:03 -0700

«Changes to HitsIterator:
 Added new constructor that includes a sort order flag (a=ascending,
d=decending, r=relevance)
Add sort order parameter to sortByField() method etc.»

but it looks like
HitsIterator hi = new HitsIterator(hits, "a");
and
HitsIterator hi = new HitsIterator(hits, "d");
produces the same result... Is it fixed?

Phil


----- Original Message -----
From: "Peter Carlson" <ca...@bookandhammer.com>
To: "Lucene Users List" <lu...@jakarta.apache.org>
Sent: Tuesday, September 03, 2002 10:56 AM
Subject: Re: Order by date


> Phil,
>
> Lucene returns results in the same order as they were added to the
> index. So if you want to sort by date, and only by date then add
> documents to your index in chronological order.
>
> If you want to sort by more than one field, then one solution (and
> probably the fastest) is to get all terms of a given field and sort
> them along with their unique Lucene ID. Then, when you want to sort the
> subset of results, so the sort yourself based on the ID without using
> the index (using the index to get the values to sort will be much
> slower then getting all the values first and storing them). This was
> done in SearchBean in the contributions area if you want to see an
> example.
>
> I hope this helps
>
> --Peter
>
>
> On Monday, September 2, 2002, at 01:32 PM, Philipp Chudinov wrote:
>
> > Thank you, Terry. But I need to do it without additional classes or
> > smth.
> > I just can not understand the problem... I've tried to reindex the
> > stuff
> > with
> >
> > doc.add(Field.Keyword("_published", DateField.dateToString(date)));
> >
> > and to search with
> >
> >       Query query = new RangeQuery(null, new Term("_published",
> > DateField.dateToString(new java.util.Date())), true);
> >       DateFilter filter = DateFilter.Before("_published", new
> > java.util.Date());
> >       Hits hits = searcher.search(query, filter);
> >
> > maybe, I misunderstand how to use this filter? Does RangeQuery
> > automatically
> > order results by field? Looks like it should... people in the
> > mailinglist
> > says, that my first approach works well (when encoding date to string
> > with
> > pattern(yyyyMMdd), but iam still lobotomized;(
> > Phil.
> >
> > ----- Original Message -----
> > From: "Terry Steichen" <te...@net-frame.com>
> > To: "Lucene Users List" <lu...@jakarta.apache.org>
> > Sent: Tuesday, September 03, 2002 1:16 AM
> > Subject: Re: Order by date
> >
> >
> >> Try Peter Carlson's SearchBean contribution.  Check the messages -
> >> there
> > was
> >> quite a bit of discussion on it.
> >>
> >> Regards,
> >>
> >> Terry
> >>
> >> ----- Original Message -----
> >> From: "Philipp Chudinov" <mo...@basko.ru>
> >> To: "Lucene Users List" <lu...@jakarta.apache.org>
> >> Sent: Monday, September 02, 2002 3:21 PM
> >> Subject: Order by date
> >>
> >>
> >>> Hi!
> >>> How can I order search results by date? I just need to show n
> >>> documents,
> >>> ordered by date (desc). I index documents with
> >>>
> >>> doc.add(Field.Keyword("_published", new
> >>> SimpleDateFormat("yyyyMMddHHmmss").format(date)));
> >>>
> >>> , so it gives something like "20020619165800" in this field. Then I
> >>> use
> >>> RangeQuery(null, currentdate(formatted the same way
> >>> indexed("yyyyMMddHHmmss"), true). But results are not ordered
> >>> properly.
> >>> Looks like this:
> >>>
> >>> 20020619165800
> >>> 20020619165800
> >>> 20020619165800
> >>> 20020711170700
> >>> 20020711170700
> >>> 20020705131800
> >>> 20020705131800
> >>> 20020619165900
> >>>
> >>> So, how can I order them? Should I write some kind of "DateFilter"
> >>> (as
> >>> suggested here
> >>>
> > http://www.mail-archive.com/lucene-user@jakarta.apache.org/
> > msg01266.html)?
> >>> If so, can't anybody explane me, how can I do this, since I feel
> >>> myself
> > as
> >> a
> >>> lobotomized flatworm now:(
> >>>
> >>> Thanx.
> >>>
> >>>
> >>> --
> >>> To unsubscribe, e-mail:
> >> <ma...@jakarta.apache.org>
> >>> For additional commands, e-mail:
> >> <ma...@jakarta.apache.org>
> >>>
> >>>
> >>
> >>
> >> --
> >> To unsubscribe, e-mail:
> > <ma...@jakarta.apache.org>
> >> For additional commands, e-mail:
> > <ma...@jakarta.apache.org>
> >>
> >
> >
> > --
> > To unsubscribe, e-mail:
> > <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> > <ma...@jakarta.apache.org>
> >
> >
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>