// 最近7天 && source != 3 ; 按照attention_uid 分组,安装 count(uid) 排序
public List<Map<String, Object>> findWeekAttentionList(Integer index, Integer row, int appType) {
long pass7Day = DateUtils.addDays(new Date(), -7).getTime();
List<Map<String, Object>> list = new ArrayList<>();
SolrQuery solrQuery = new SolrQuery();
// solrQuery.set("q", "*:*" );
solrQuery.setParam("facet", true);//是否分组
solrQuery.set("df", "attention_uid,count");
solrQuery.setParam("facet.field", "attention_uid");//分组的域
solrQuery.setParam("facet.sort", "true");
solrQuery.setParam("facet.mincount", "1");
solrQuery.setParam("facet.offset", String.valueOf(index));
solrQuery.setParam("facet.limit", String.valueOf(row));// <0 全部
String createTimeCondition = String.format("create_time:[%s TO *]", pass7Day);
String sourceCondition = " -source: 3 ";
String q = sourceCondition + " AND " + createTimeCondition;
solrQuery.set("q", q);
solrQuery.setStart(0);
solrQuery.setRows(0);
QueryResponse resp = null;
try {
resp = solrClient.query(solrQuery);
} catch (SolrServerException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
List<FacetField> facetFields = resp.getFacetFields();
if (CollectionUtils.isEmpty(facetFields)) return list;
Optional<FacetField> first = facetFields.stream().findFirst();
FacetField facetField = first.get();
if (facetField == null) return list;
List<FacetField.Count> values = facetField.getValues();
Map<String, Object> item = null;
for (FacetField.Count countItem : values) {
item = new HashMap<>();
item.put("attentionUid", countItem.getName());
item.put("num", countItem.getCount());
list.add(item);
}
return list;
}
基于solr 的分组排序
最新推荐文章于 2024-04-07 11:05:22 发布