|
@ -359,6 +359,51 @@ public class SolrUtil {
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 单组分组Count统计(start从0开始),筛选出聚合值>=groupCount
|
|
|
*
|
|
|
* @param core core名
|
|
|
* @param q 查询条件
|
|
|
* @param fq 筛选条件
|
|
|
* @param groupField 分组字段名
|
|
|
* @param start 起始偏移位
|
|
|
* @param limit 结果条数,为负数则不限制
|
|
|
* @param groupCount 聚合值
|
|
|
*/
|
|
|
public Map<String, Long> groupCountLte(String core, String q, String fq, String groupField, int start, int limit, int groupCount) throws Exception {
|
|
|
SolrClient conn = pool.getConnection(core);
|
|
|
SolrQuery query = new SolrQuery();
|
|
|
if (null != q && !q.equals("")) {
|
|
|
query.setQuery(q);
|
|
|
} else {
|
|
|
query.setQuery("*:*");
|
|
|
}
|
|
|
if (null != fq && !fq.equals("")) {
|
|
|
query.setFilterQueries(fq);
|
|
|
}
|
|
|
//设置facet=on
|
|
|
query.setFacet(true);
|
|
|
query.setRows(0);
|
|
|
query.addFacetField(groupField);
|
|
|
//限制每次返回结果数
|
|
|
query.setFacetLimit(limit);
|
|
|
query.set(FacetParams.FACET_OFFSET, start);
|
|
|
//不统计null的值
|
|
|
query.setFacetMissing(false);
|
|
|
// 设置返回的数据中每个分组的数据最小值,比如设置为0,则统计数量最小为0,不然不显示
|
|
|
query.setFacetMinCount(0);
|
|
|
QueryResponse rsp = conn.query(query);
|
|
|
List<FacetField.Count> countList = rsp.getFacetField(groupField).getValues();
|
|
|
Map<String, Long> rmap = new HashMap<>();
|
|
|
for (FacetField.Count count : countList) {
|
|
|
if (count.getCount() >= groupCount) {
|
|
|
rmap.put(count.getName(), (long) count.getCount());
|
|
|
}
|
|
|
}
|
|
|
return rmap;
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 多组分组Count(独立计算)
|
|
|
*
|