lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shai Erera <>
Subject Retrieving the first document in a range
Date Tue, 05 Apr 2011 14:06:26 GMT

We have a date field which is indexed as NumericField<Long> and we'd like to
get the first docid that is since 3 weeks ago. Currently we're doing
something like this:

Query q = NumericRangeQuery.newLongRange("date", timeBefore3Weeks,
System.currentTimeMillis(), true, true);
Scorer s = q.weight(searcher).scorer(reader, true, false);
int doc = s.nextDoc();
if (doc == DISI.NO_MORE_DOCS) {
  // no docs since last 3 weeks
} else {
  // do something

Is there a more efficient way to achieve this?

Can we use TermEnum to skip to the first term 'after 3 weeks'? If so, we can
pull the first doc that appears in the TermDocs of that Term (if it's a
valid term). I'm not sure though that we can use the lexicon with numeric
fields this way ...


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message