lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Boyd <andrew.b...@mindspring.com>
Subject Re: Finding minimum and maximum value of a field?
Date Tue, 31 May 2005 11:54:22 GMT
How about using range query?

private Term begin, end;

begin = new Term("dateField",  DateTools.dateToString(Date.valueOf(<"backInTimeStringDate">)));
end = new Term("dateField",  DateTools.dateToString(Date.valueOf(<"farFutureStringDate">)));

RangeQuery query = new RangeQuery(begin, end, true);

IndexSearcher searcher = new IndexSearcher(directory);

Hits hits = searcher.search(query);

Document minDoc = hits.doc(0);
Document maxDoc = hits.doc(hits.length()-1);

String minDateString = minDoc.get("dateField");
String maxDateString = maxDoc.get("dateField");

That sould give you the min and max date fields.

Andrew

-----Original Message-----
From: Kevin Burton <burton@rojo.com>
Sent: May 31, 2005 2:06 AM
To: java-user@lucene.apache.org
Subject: Finding minimum and maximum value of a field?

I have an index with a date field.  I want to quickly find the minimum 
and maximum values in the index.

Is there a quick way to do this?  I looked at using TermInfos and 
finding the first one but how to I find the last?

I also tried the new sort API and the performance was horrible :-/

Any ideas?

Kevin

-- 


Use Rojo (RSS/Atom aggregator)! - visit http://rojo.com. 
See irc.freenode.net #rojo if you want to chat.

Rojo is Hiring! - http://www.rojonetworks.com/JobsAtRojo.html

   Kevin A. Burton, Location - San Francisco, CA
      AIM/YIM - sfburtonator,  Web - http://peerfear.org/
GPG fingerprint: 5FB2 F3E2 760E 70A8 6174 D393 E84D 8D04 99F1 4412 


---------------------------------------------------------------------
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


Mime
View raw message