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 Cool The Breezer <te...@yahoo.com> on 2008/11/10 07:21:09 UTC

Order the index by timestamp field and Get n documents

Hi,
   In my index, there is a field called timestamp which is long value of date. I am  trying to get sort all documents by timestamp and get N documents. 
I am trying to find a way to create a query like "timestamp > 0" and then order the result by timestamp and get N fields. However I am not able to do that. Suggest me the best way. Or there are any lowlevel method available for the same.

I am using Lucene 2.3.1 and looking into method search(Weight weight, Filter filter, int nDocs, Sort sort) in IndexSearcher. Trying to know how to create a Weight object.

Anyway, I would really appreciate your suggestion....

-RB


      

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Order the index by timestamp field and Get n documents

Posted by Tomer Gabel <to...@tomergabel.com>.
Possibly the fastest way to do this is to use a sortable timestamp field
(e.g. padded long) and use a TermEnumerator, which always gives a
lexicographically-sorted enumeration. Since you'd probably prefer a "most
recent" policy you may need to come up with a reverse-timestamp scheme (e.g.
instead of zero-padded "milliseconds since epoch" you may prefer zero-padded
"milliseconds 'till year 3000" values).

Lucene doesn't handle this type of queries very efficiently, however, so you
may prefer an SQL database instead (or in addition).
--TG

 


Cool The Breezer wrote:
> 
> Hi,
>    In my index, there is a field called timestamp which is long value of
> date. I am  trying to get sort all documents by timestamp and get N
> documents. 
> I am trying to find a way to create a query like "timestamp > 0" and then
> order the result by timestamp and get N fields. However I am not able to
> do that. Suggest me the best way. Or there are any lowlevel method
> available for the same.
> 
> I am using Lucene 2.3.1 and looking into method search(Weight weight,
> Filter filter, int nDocs, Sort sort) in IndexSearcher. Trying to know how
> to create a Weight object.
> 
> Anyway, I would really appreciate your suggestion....
> 
> -RB
> 
> 
>       
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
> 
> 
> 


-----
--

http://www.tomergabel.com Tomer Gabel 


-- 
View this message in context: http://www.nabble.com/Order-the-index-by-timestamp-field-and-Get-n-documents-tp20414870p20523960.html
Sent from the Lucene - Java Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Order the index by timestamp field and Get n documents

Posted by 黄成 <zz...@gmail.com>.
I think you should use NumberTools to format timestamp first, otherwise sort
will not work correctly

On Mon, Nov 10, 2008 at 8:00 PM, Cool The Breezer
<te...@yahoo.com>wrote:

> Could able to do that using range query
>
> String end = "253373251260000";//i.e. 11/30/9999, assume that this is max
> end date
>
> Term endTerm = new Term("timestamp",end);
> RangeQuery rangeQuery = new RangeQuery(null,endTerm,true);
>
> Sort sort = new Sort("timestamp",true);
> Filter dupFilter = new DuplicateFilter("id");
> Hits hits = searcher.search(rangeQuery,dupFilter,sort);
>
>
>
>
> --- On Mon, 11/10/08, Cool The Breezer <te...@yahoo.com> wrote:
>
> > From: Cool The Breezer <te...@yahoo.com>
> > Subject: Order the index by timestamp field and Get n documents
> > To: java-user@lucene.apache.org
> > Date: Monday, November 10, 2008, 1:21 AM
> > Hi,
> >    In my index, there is a field called timestamp which is
> > long value of date. I am  trying to get sort all documents
> > by timestamp and get N documents.
> > I am trying to find a way to create a query like
> > "timestamp > 0" and then order the result by
> > timestamp and get N fields. However I am not able to do
> > that. Suggest me the best way. Or there are any lowlevel
> > method available for the same.
> >
> > I am using Lucene 2.3.1 and looking into method
> > search(Weight weight, Filter filter, int nDocs, Sort sort)
> > in IndexSearcher. Trying to know how to create a Weight
> > object.
> >
> > Anyway, I would really appreciate your suggestion....
> >
> > -RB
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > java-user-unsubscribe@lucene.apache.org
> > For additional commands, e-mail:
> > java-user-help@lucene.apache.org
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>

Re: Order the index by timestamp field and Get n documents

Posted by Cool The Breezer <te...@yahoo.com>.
Could able to do that using range query

String end = "253373251260000";//i.e. 11/30/9999, assume that this is max end date

Term endTerm = new Term("timestamp",end);
RangeQuery rangeQuery = new RangeQuery(null,endTerm,true);
		
Sort sort = new Sort("timestamp",true);
Filter dupFilter = new DuplicateFilter("id");
Hits hits = searcher.search(rangeQuery,dupFilter,sort);




--- On Mon, 11/10/08, Cool The Breezer <te...@yahoo.com> wrote:

> From: Cool The Breezer <te...@yahoo.com>
> Subject: Order the index by timestamp field and Get n documents
> To: java-user@lucene.apache.org
> Date: Monday, November 10, 2008, 1:21 AM
> Hi,
>    In my index, there is a field called timestamp which is
> long value of date. I am  trying to get sort all documents
> by timestamp and get N documents. 
> I am trying to find a way to create a query like
> "timestamp > 0" and then order the result by
> timestamp and get N fields. However I am not able to do
> that. Suggest me the best way. Or there are any lowlevel
> method available for the same.
> 
> I am using Lucene 2.3.1 and looking into method
> search(Weight weight, Filter filter, int nDocs, Sort sort)
> in IndexSearcher. Trying to know how to create a Weight
> object.
> 
> Anyway, I would really appreciate your suggestion....
> 
> -RB
> 
> 
>       
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail:
> java-user-help@lucene.apache.org


      

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org