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的学习使用系列差不多就这些了,其实也没啥东西,根本没有深入进去,如果深入的话,估计得花几个月时间,目前先了解下基本原理和基本使用方法,能够应付目前项目中的问题就行,当然,要真正掌握还需时间,冰冻三尺非一日之寒嘛,需要时日,有时间再来玩一玩。
  在路上……

Solr的学习使用之(九)facet.pivot实战的更多相关文章

  1. Solr的学习使用之(七)Solr高级查询facet、facet.pivot简介

    以下转载自:http://hongweiyi.com/2013/03/apache-solr-facet-introduction/ 1.什么是Faceted Search Facet['fæsɪt] ...

  2. solr中facet及facet.pivot理解(整合两篇文章保留参考)

    Facet['fæsɪt]很难翻译,只能靠例子来理解了.Solr作者Yonik Seeley也给出更为直接的名字:导航(Guided Navigation).参数化查询(Paramatic Searc ...

  3. solr中facet及facet.pivot理解

    Facet['fæsɪt]很难翻译,只能靠例子来理解了.Solr作者Yonik Seeley也给出更为直接的名字:导航(Guided Navigation).参数化查询(Paramatic Searc ...

  4. solr与.net系列课程(九)solr5.1的配置

    solr与.net系列课程(九)solr5.1的配置 最近一些园友来咨询solr5.1的配置方式,然后我就去官网下载了个最新版本的solr,发现solr5.0以后solr的下载包里的内容发生的变化,移 ...

  5. Solr的学习使用之(一)部署

    Solr的主要功能是全文检索,该功能分为两个过程:创建索引和对索引进行搜索 一.心得体会 第一次写技术博客,这次写的基本上都是从网络上整理的来的,外加自己的一些实践,以后争取全部原创哈,都说写技术博客 ...

  6. 我的MYSQL学习心得(九) 索引

    我的MYSQL学习心得(九) 索引 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) 数据类 ...

  7. solr课程学习系列-solr服务器配置(2)

    本文是solr课程学习系列的第2个课程,对solr基础知识不是很了解的请查看solr课程学习系列-solr的概念与结构(1) 本文以windows的solr6服务器搭建为例. 一.solr的工作环境: ...

  8. 学习“要件审判九步法”,正确处理五个关系 z

    学习“要件审判九步法”,正确处理五个关系 2015-06-29 07:39:07 | 来源:人民法院报第二版 | 作者:阮丹军 “要件审判九步法”,是邹碧华法官总结审判和审判管理双重经验后的心血之作, ...

  9. 简单的玩玩etimer <contiki学习笔记之九 补充>

    这幅图片是对前面  <<contiki学习笔记之九>>  的一个补充说明. 简单的玩玩etimer <contiki学习笔记之九> 或许,自己正在掀开contiki ...

随机推荐

  1. 关了浏览器再开,怎么session还在?

    关了浏览器session当然仍然存在,因为session是储存在服务器端的,而服务器是不可能知道你有没有关掉浏览器. 服务器只是简单的保持session接受用户请求,只有当session一段时间没有被 ...

  2. SQL server 字段合并CAST(org_no AS VARCHAR(20))+CAST(page_no AS VARCHAR(20))+CAST(djlb_no AS VARCHAR(20)))

    sql server 字段合并(CAST) ---------------------- select (CAST(org_no AS VARCHAR(20))+CAST(page_no AS VAR ...

  3. 1. Spring Security 框架简介

    官网:https://projects.spring.io/spring-security/Spring Security 是强大的,且容易定制的实现认证,与授权的基于 Spring 开发的框架.Sp ...

  4. mybatis insert update delete返回都是整型 0,1,增,删,改要提交事物

    mybatis insert update delete返回都是整型 0,1, 没有扔 增,删,改要提交事物

  5. 超好用json转excel工具

    给大家安利一个超实用的json数据转excel工具:http://www.yzcopen.com/doc/jsonexcel

  6. codevs 3060 抓住那头奶牛 x

    3060 抓住那头奶牛 USACO  时间限制: 1 s  空间限制: 16000 KB  题目等级 : 黄金 Gold   题目描述 Description 农夫约翰被告知一头逃跑奶牛的位置,想要立 ...

  7. 转载--C++的反思

    转载自http://blog.csdn.net/yapian8/article/details/46983319 最近两年 C++又有很多人出来追捧,并且追捧者充满了各种优越感,似乎不写 C++你就一 ...

  8. kohana 语言资源国际化、本地化

    语言配置开关: root@DESKTOP-I4OIMJC /cygdrive/e/html/tproject/framebota/platform # grep -n2 'I18n::lang' bo ...

  9. Quadratic equation

    Quadratic equation 牛客多校九B 给定 $(x+y)\%mod=b$ $(x*y)\%mod=c$ 求 $x,y$ 二次剩余 求$((x-y)^{2})\%mod = (b\time ...

  10. js中switch语句不执行

    参考http://www.jb51.net/article/54393.htm switch语句与if语句的关系最为密切,也是其它编程语言中普遍使用的一种流程控制语句,但switch的匹配是全等模式, ...