use of org.qi4j.api.query.grammar.OrderBy in project qi4j-sdk by Qi4j.
the class SolrEntityQueryMixin method findEntities.
@Override
public Iterable<EntityReference> findEntities(Class<?> resultType, @Optional Specification<Composite> whereClause, @Optional OrderBy[] orderBySegments, @Optional Integer firstResult, @Optional Integer maxResults, Map<String, Object> variables) throws EntityFinderException {
try {
QuerySpecification expr = (QuerySpecification) whereClause;
SolrServer server = solr.solrServer();
NamedList<Object> list = new NamedList<Object>();
list.add("q", expr.query());
list.add("rows", maxResults != 0 ? maxResults : 10000);
list.add("start", firstResult);
if (orderBySegments != null && orderBySegments.length > 0) {
for (OrderBy orderBySegment : orderBySegments) {
String propName = ((Member) orderBySegment.property().accessor()).getName() + "_for_sort";
String order = orderBySegment.order() == OrderBy.Order.ASCENDING ? "asc" : "desc";
list.add("sort", propName + " " + order);
}
}
SolrParams solrParams = SolrParams.toSolrParams(list);
logger.debug("Search:" + list.toString());
QueryResponse query = server.query(solrParams);
SolrDocumentList results = query.getResults();
List<EntityReference> references = new ArrayList<EntityReference>(results.size());
for (SolrDocument result : results) {
references.add(EntityReference.parseEntityReference(result.getFirstValue("id").toString()));
}
return references;
} catch (SolrServerException e) {
throw new EntityFinderException(e);
}
}
Aggregations