lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stephane Bailliez <>
Subject Re: Sorting by field from a given 'offset'
Date Fri, 24 Jun 2005 13:42:33 GMT
Stephane Bailliez wrote:

> Hi all,
> "starting from document that has field f1 = a, give me the first n 
> documents sorted by field 'z' ordered by asc/desc"
To be more specific, that's something like:


// get the document field 'dt' from a search

// search must occur starting from the dt we just found
Term upperTerm = new Term(FIELD_DT, descending ? MIN_DT:MAX_DT);
Term lowerTerm = new Term(FIELD_DT, dt);
RangeQuery rangeQuery = new RangeQuery(lowerTerm, upperTerm, false);

// we will search in the content
Query contentQuery = QueryParser.parse(queryString, FIELD_DATACONTENT, 

// a document must have both query required
BooleanQuery query = new BooleanQuery();
query.add(rangeQuery, true, false);
query.add(contentQuery, true, false);

// sort according to dt
Sort sort = new Sort( new SortField(FIELD_DT, SortField.STRING, 
descending) );

// return only a given number of docs
TopFieldDocs topFieldDocs =, null, maxlength, sort);

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message