Reputation: 15723
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)
Upvotes: 1
Views: 163
Reputation: 200158
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"
Upvotes: 3
Reputation: 4712
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
Upvotes: 0