mirror of
https://github.com/querydsl/querydsl.git
synced 2026-07-03 21:07:49 +08:00
Fixed LuceneQuery.listResults, had a logic bug in which totalCount wasn't all of the matched documents, but just the amount of documents matching the limit. Also as a slight optimization lists initialized to resulting size in initialization.
This commit is contained in:
parent
6bde4f7a35
commit
ca00c68302
@ -113,9 +113,10 @@ public class LuceneQuery implements SimpleQuery<LuceneQuery>, SimpleProjectable<
|
||||
return listSorted(orderBys, limit, offset);
|
||||
}
|
||||
|
||||
List<Document> documents = new ArrayList<Document>(); // TODO : initialize List with proper size
|
||||
List<Document> documents = null;
|
||||
try {
|
||||
ScoreDoc[] scoreDocs = searcher.search(createQuery(), limit + offset).scoreDocs;
|
||||
documents = new ArrayList<Document>(scoreDocs.length - offset);
|
||||
for (int i = offset; i < scoreDocs.length; ++i) {
|
||||
documents.add(searcher.doc(scoreDocs[i].doc));
|
||||
}
|
||||
@ -126,7 +127,6 @@ public class LuceneQuery implements SimpleQuery<LuceneQuery>, SimpleProjectable<
|
||||
}
|
||||
|
||||
private List<Document> listSorted(List<OrderSpecifier<?>> orderBys, int limit, int offset) {
|
||||
List<Document> documents = new ArrayList<Document>(); // TODO : initialize List with proper size
|
||||
List<SortField> sortFields = new ArrayList<SortField>(orderBys.size());
|
||||
for (OrderSpecifier<?> orderSpecifier : orderBys) {
|
||||
if (!(orderSpecifier.getTarget() instanceof Path<?>)) {
|
||||
@ -136,8 +136,10 @@ public class LuceneQuery implements SimpleQuery<LuceneQuery>, SimpleProjectable<
|
||||
}
|
||||
Sort sort = new Sort();
|
||||
sort.setSort(sortFields.toArray(new SortField[sortFields.size()]));
|
||||
List<Document> documents = null;
|
||||
try {
|
||||
ScoreDoc[] scoreDocs = searcher.search(createQuery(), null, limit + offset, sort).scoreDocs;
|
||||
documents = new ArrayList<Document>(scoreDocs.length - offset);
|
||||
for (int i = offset; i < scoreDocs.length; ++i) {
|
||||
documents.add(searcher.doc(scoreDocs[i].doc));
|
||||
}
|
||||
@ -159,9 +161,8 @@ public class LuceneQuery implements SimpleQuery<LuceneQuery>, SimpleProjectable<
|
||||
|
||||
@Override
|
||||
public SearchResults<Document> listResults() {
|
||||
// FIXME : SearchResults.total is number of total results, not amount of documents in paged view
|
||||
List<Document> documents = list();
|
||||
return new SearchResults<Document>(documents, queryMixin.getMetadata().getModifiers(), documents.size());
|
||||
return new SearchResults<Document>(documents, queryMixin.getMetadata().getModifiers(), count());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -267,7 +267,7 @@ public class LuceneQueryTest {
|
||||
assertEquals("1990", results.getResults().get(1).get("year"));
|
||||
assertEquals(2, results.getLimit());
|
||||
assertEquals(1, results.getOffset());
|
||||
assertEquals(2, results.getTotal());
|
||||
assertEquals(4, results.getTotal());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -280,7 +280,7 @@ public class LuceneQueryTest {
|
||||
assertEquals("1954", results.getResults().get(0).get("year"));
|
||||
assertEquals(1, results.getLimit());
|
||||
assertEquals(1, results.getOffset());
|
||||
assertEquals(1, results.getTotal());
|
||||
assertEquals(4, results.getTotal());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user