}
private void processGroupOptions(SolrQuery solrQuery, Query query) {
GroupOptions groupOptions = query.getGroupOptions();
if (groupOptions == null
|| (CollectionUtils.isEmpty(groupOptions.getGroupByFields())
&& CollectionUtils.isEmpty(groupOptions.getGroupByFunctions()) && CollectionUtils.isEmpty(groupOptions
.getGroupByQueries()))) {
return;
}
solrQuery.set(GroupParams.GROUP, true);
solrQuery.set(GroupParams.GROUP_MAIN, groupOptions.isGroupMain());
solrQuery.set(GroupParams.GROUP_FORMAT, "grouped");
if (!CollectionUtils.isEmpty(groupOptions.getGroupByFields())) {
for (Field field : groupOptions.getGroupByFields()) {
solrQuery.add(GroupParams.GROUP_FIELD, field.getName());
}
}
if (!CollectionUtils.isEmpty(groupOptions.getGroupByFunctions())) {
for (Function function : groupOptions.getGroupByFunctions()) {
String functionFragment = createFunctionFragment(function, 0);
setObjectNameOnGroupQuery(query, function, functionFragment);
solrQuery.add(GroupParams.GROUP_FUNC, functionFragment);
}
}
if (!CollectionUtils.isEmpty(groupOptions.getGroupByQueries())) {
for (Query groupQuery : groupOptions.getGroupByQueries()) {
String queryFragment = getQueryString(groupQuery);
setObjectNameOnGroupQuery(query, groupQuery, queryFragment);
solrQuery.add(GroupParams.GROUP_QUERY, queryFragment);
}
}
if (groupOptions.getSort() != null) {
for (Order order : groupOptions.getSort()) {
solrQuery.add(GroupParams.GROUP_SORT, order.getProperty().trim() + " "
+ (order.isAscending() ? ORDER.asc : ORDER.desc));
}
}
if (groupOptions.getCachePercent() > 0) {
solrQuery.add(GroupParams.GROUP_CACHE_PERCENTAGE, String.valueOf(groupOptions.getCachePercent()));
}
if (groupOptions.getLimit() != null && groupOptions.getLimit() >= 0) {
solrQuery.set(GroupParams.GROUP_LIMIT, groupOptions.getLimit());
}
if (groupOptions.getOffset() != null && groupOptions.getOffset() >= 0) {
solrQuery.set(GroupParams.GROUP_OFFSET, groupOptions.getOffset());
}
solrQuery.set(GroupParams.GROUP_TOTAL_COUNT, groupOptions.isTotalCount());
solrQuery.set(GroupParams.GROUP_FACET, groupOptions.isGroupFacets());
solrQuery.set(GroupParams.GROUP_TRUNCATE, groupOptions.isTruncateFacets());
}