mirror of
https://github.com/querydsl/querydsl.git
synced 2026-07-03 21:07:49 +08:00
moved toSort from LuceneQuery to LuceneSerializer
This commit is contained in:
parent
e754eb1841
commit
445f0489dc
@ -126,27 +126,18 @@ public class LuceneQuery implements SimpleQuery<LuceneQuery>, SimpleProjectable<
|
||||
return documents;
|
||||
}
|
||||
|
||||
private List<Document> listSorted(List<OrderSpecifier<?>> orderBys, int limit, int offset) {
|
||||
List<SortField> sortFields = new ArrayList<SortField>(orderBys.size());
|
||||
for (OrderSpecifier<?> orderSpecifier : orderBys) {
|
||||
if (!(orderSpecifier.getTarget() instanceof Path<?>)) {
|
||||
throw new IllegalArgumentException("argument was not of type Path.");
|
||||
}
|
||||
sortFields.add(new SortField(serializer.toField((Path<?>)orderSpecifier.getTarget()), Locale.ENGLISH, !orderSpecifier.isAscending()));
|
||||
}
|
||||
Sort sort = new Sort();
|
||||
sort.setSort(sortFields.toArray(new SortField[sortFields.size()]));
|
||||
List<Document> documents = null;
|
||||
private List<Document> listSorted(List<OrderSpecifier<?>> orderBys, int limit, int offset) {
|
||||
try {
|
||||
Sort sort = serializer.toSort(orderBys);
|
||||
ScoreDoc[] scoreDocs = searcher.search(createQuery(), null, limit + offset, sort).scoreDocs;
|
||||
documents = new ArrayList<Document>(scoreDocs.length - offset);
|
||||
List<Document> documents = new ArrayList<Document>(scoreDocs.length - offset);
|
||||
for (int i = offset; i < scoreDocs.length; ++i) {
|
||||
documents.add(searcher.doc(scoreDocs[i].doc));
|
||||
}
|
||||
return documents;
|
||||
} catch (IOException e) {
|
||||
throw new QueryException(e);
|
||||
}
|
||||
return documents;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
*/
|
||||
package com.mysema.query.lucene;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@ -16,6 +17,8 @@ import org.apache.lucene.search.BooleanQuery;
|
||||
import org.apache.lucene.search.PhraseQuery;
|
||||
import org.apache.lucene.search.PrefixQuery;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.search.Sort;
|
||||
import org.apache.lucene.search.SortField;
|
||||
import org.apache.lucene.search.TermQuery;
|
||||
import org.apache.lucene.search.TermRangeQuery;
|
||||
import org.apache.lucene.search.WildcardQuery;
|
||||
@ -26,6 +29,7 @@ import com.mysema.query.types.Expr;
|
||||
import com.mysema.query.types.Operation;
|
||||
import com.mysema.query.types.Operator;
|
||||
import com.mysema.query.types.Ops;
|
||||
import com.mysema.query.types.OrderSpecifier;
|
||||
import com.mysema.query.types.Path;
|
||||
|
||||
/**
|
||||
@ -191,4 +195,19 @@ public class LuceneSerializer {
|
||||
throw new IllegalArgumentException("expr was not of type Operation");
|
||||
}
|
||||
|
||||
public Sort toSort(List<OrderSpecifier<?>> orderBys){
|
||||
List<SortField> sortFields = new ArrayList<SortField>(orderBys.size());
|
||||
for (OrderSpecifier<?> orderSpecifier : orderBys) {
|
||||
if (!(orderSpecifier.getTarget() instanceof Path<?>)) {
|
||||
throw new IllegalArgumentException("argument was not of type Path.");
|
||||
}
|
||||
sortFields.add(new SortField(toField((Path<?>)orderSpecifier.getTarget()),
|
||||
Locale.ENGLISH,
|
||||
!orderSpecifier.isAscending()));
|
||||
}
|
||||
Sort sort = new Sort();
|
||||
sort.setSort(sortFields.toArray(new SortField[sortFields.size()]));
|
||||
return sort;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user