1

I want to list the lastest 10 rows order by id DESC

Sort sort = new Sort(new SortField[]{new SortField("id",SortField.INT,true)});
TopDocs topDocs=indexSearch.search(null,null,10,sort);//no need Query,only sort
...

I got a 500 exception because the Query parameter is null

How can I implement it in a best way?

btw:id field is a NumericField,write using:

new NumericField("id",Integer.MAX_VALUE,Field.Store.YES,true)
Koerr
  • 15,215
  • 28
  • 78
  • 108

2 Answers2

3

You should use the MatchAllDocsQuery for that.

Lucene Query is a peculiar object that isn't only the specification of the query semantics, but also the implementation of the most efficient execution strategy for each particular query type. That's why there must be a special Query even for this "no-op"

Marko Topolnik
  • 195,646
  • 29
  • 319
  • 436
  • can you take a look my another lucene question? thanks http://stackoverflow.com/questions/10464377/in-this-lucene-case-using-booleanquery-or-write-more-indexes – Koerr May 05 '12 at 17:57
0

BTW: if you want to search the latest X rows it's better you add a new date field with the time this doc was added to repository and not to rely on the counter (id on your case). try to think what happen if you update an existed doc or you reach Integer.MAX_VALUE

shem
  • 4,686
  • 2
  • 32
  • 43