facet.pivot自己的理解,就是按照多个维度进行分组查询,以下是自己的实战代码,按照newsType,property两个维度统计:

public List<ReportNewsTypeDTO> queryNewsType(
ReportQuery reportQuery) {
HttpSolrServer solrServer = SolrServer.getInstance().getServer();
SolrQuery sQuery = new SolrQuery();
List<ReportNewsTypeDTO> list = new ArrayList<ReportNewsTypeDTO>();
try {
String para = this.initReportQueryPara(reportQuery, );
sQuery.setFacet(true);
sQuery.add("facet.pivot", "newsType,property");//根据这两维度来分组查询
sQuery.setQuery(para);
QueryResponse response = solrServer.query(sQuery,SolrRequest.METHOD.POST);
NamedList<List<PivotField>> namedList = response.getFacetPivot();
System.out.println(namedList);//底下为啥要这样判断,把这个值打印出来,你就明白了
if(namedList != null){
List<PivotField> pivotList = null;
for(int i=;i<namedList.size();i++){
pivotList = namedList.getVal(i);
if(pivotList != null){
ReportNewsTypeDTO dto = null;
for(PivotField pivot:pivotList){
dto = new ReportNewsTypeDTO();
dto.setNewsTypeId((Integer)pivot.getValue());
dto.setNewsTypeName(News.newsTypeMap.get((Integer)pivot.getValue()));
int pos = ;
int neg = ;
List<PivotField> fieldList = pivot.getPivot();
if(fieldList != null){
for(PivotField field:fieldList){
int proValue = (Integer) field.getValue();
int count = field.getCount();
if(proValue == ){
pos = count;
}else{
neg = count;
}
}
}
dto.setPositiveCount(pos);
dto.setNegativeCount(neg);
list.add(dto);
}
}
}
} return list;
} catch (SolrServerException e) {
log.error("查询solr失败", e);
e.printStackTrace();
} finally{
solrServer.shutdown();
solrServer = null;
}
return list;
}
namedList打印结果:
{newsType,property=
[
newsType:8 [4260] [property:1 [3698] null, property:0 [562] null],
newsType:1 [1507] [property:1 [1389] null, property:0 [118] null],
newsType:2 [1054] [property:1 [909] null, property:0 [145] null],
newsType:6 [715] [property:1 [581] null, property:0 [134] null],
newsType:4 [675] [property:1 [466] null, property:0 [209] null],
newsType:3 [486] [property:1 [397] null, property:0 [89] null],
newsType:7 [458] [property:1 [395] null, property:0 [63] null],
newsType:5 [289] [property:1 [263] null, property:0 [26] null],
newsType:9 [143] [property:1 [138] null, property:0 [5] null]
]
}
这下应该明白了。写到这里,突然想到一个,所有的分组查询统计,不管是一个维度两个维度都可以使用face.pivot来统计,不错的东东。   好了,Solr的学习使用系列差不多就这些了,其实也没啥东西,根本没有深入进去,如果深入的话,估计得花几个月时间,目前先了解下基本原理和基本使用方法,能够应付目前项目中的问题就行,当然,要真正掌握还需时间,冰冻三尺非一日之寒嘛,需要时日,有时间再来玩一玩。
  在路上……

最新文章

  1. 突袭HTML5之SVG 2D入门1 - SVG综述////////////////zzzzzzzz
  2. (转)FTP操作类,从FTP下载文件
  3. iOS RSA 证书加密
  4. Django 1.8安装使用
  5. 用Windows Server 2003搭建企业内部邮件服务器
  6. .net 4中的pInvokeStackImbalance MDA默认是开启的
  7. 不用Root权限获取已经安装的Apk安装包
  8. Spring+TaskExecutor实例
  9. HTML之事件处理程序
  10. Orm之中介模型
  11. Python optparser库详解
  12. keras 入门整理 如何shuffle,如何使用fit_generator 整理合集
  13. go 字符串反转(倒序)
  14. 【Jenkins】Jenkins安装修改默认路径和端口的方法
  15. svm工具箱快速入手简易教程
  16. HDU1879 继续畅通工程 2017-04-12 19:12 50人阅读 评论(0) 收藏
  17. Codeforces Beta Round #80 (Div. 1 Only) D. Time to Raid Cowavans 分块
  18. Razor语法(五)
  19. 登录首页时报错:java.lang.IllegalArgumentException (不合法的参数异常)
  20. Java调用Groovy

热门文章

  1. CentOS 系统free命令
  2. android 开发架构学习
  3. MIF文件生成说明
  4. Linux内核设计与实现 总结笔记(第九章)内核同步介绍
  5. Spring Cloud Commons教程(一)普通抽象
  6. [CSP-S模拟测试]:玩具(概率DP)
  7. HTML5和CSS3兼容清单
  8. Uncaught TypeError: Cannot read property 'length' of null错误怎么处理?
  9. (转)SQLite部署-无法加载 DLL“SQLite.Interop.dll”: 找不到指定的模块
  10. AssertionError: View function mapping is overwriting an existing endpoint function: insertCase