Solr的学习使用之(九)facet.pivot实战
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实战的更多相关文章
- Solr的学习使用之(七)Solr高级查询facet、facet.pivot简介
以下转载自:http://hongweiyi.com/2013/03/apache-solr-facet-introduction/ 1.什么是Faceted Search Facet['fæsɪt] ...
- solr中facet及facet.pivot理解(整合两篇文章保留参考)
Facet['fæsɪt]很难翻译,只能靠例子来理解了.Solr作者Yonik Seeley也给出更为直接的名字:导航(Guided Navigation).参数化查询(Paramatic Searc ...
- solr中facet及facet.pivot理解
Facet['fæsɪt]很难翻译,只能靠例子来理解了.Solr作者Yonik Seeley也给出更为直接的名字:导航(Guided Navigation).参数化查询(Paramatic Searc ...
- solr与.net系列课程(九)solr5.1的配置
solr与.net系列课程(九)solr5.1的配置 最近一些园友来咨询solr5.1的配置方式,然后我就去官网下载了个最新版本的solr,发现solr5.0以后solr的下载包里的内容发生的变化,移 ...
- Solr的学习使用之(一)部署
Solr的主要功能是全文检索,该功能分为两个过程:创建索引和对索引进行搜索 一.心得体会 第一次写技术博客,这次写的基本上都是从网络上整理的来的,外加自己的一些实践,以后争取全部原创哈,都说写技术博客 ...
- 我的MYSQL学习心得(九) 索引
我的MYSQL学习心得(九) 索引 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) 数据类 ...
- solr课程学习系列-solr服务器配置(2)
本文是solr课程学习系列的第2个课程,对solr基础知识不是很了解的请查看solr课程学习系列-solr的概念与结构(1) 本文以windows的solr6服务器搭建为例. 一.solr的工作环境: ...
- 学习“要件审判九步法”,正确处理五个关系 z
学习“要件审判九步法”,正确处理五个关系 2015-06-29 07:39:07 | 来源:人民法院报第二版 | 作者:阮丹军 “要件审判九步法”,是邹碧华法官总结审判和审判管理双重经验后的心血之作, ...
- 简单的玩玩etimer <contiki学习笔记之九 补充>
这幅图片是对前面 <<contiki学习笔记之九>> 的一个补充说明. 简单的玩玩etimer <contiki学习笔记之九> 或许,自己正在掀开contiki ...
随机推荐
- android 7.0适配(总结)
file_paths.xml <?xml version="1.0" encoding="utf-8"?><paths xmlns:andro ...
- php array_pop()函数 语法
php array_pop()函数 语法 作用:删除数组中的最后一个元素.博智达 语法:array_pop(array) 参数: 参数 描述 array 必需.规定数组. 说明:返回数组的最后 ...
- Mobile的HTML5网页内快速滚动和回弹的效果
style="overflow: auto;-webkit-overflow-scrolling: touch; 这个可以让页面在Native端滚动时模拟原生的弹性滚动效果 下面是微信浏览器 ...
- 设计模式学习笔记——Composite 组合模式
用于描述无限层级的复杂对象,类似于描述资源管理器,抽象出每一个层级的共同特点(文件夹和文件,展开事件) 以前描述一个对象,是将整个对象的全部数据都描述清楚,而组合模式通过在对象中定义自己,描述自己的下 ...
- 重新理解了重定向,利用重定向可以防止用户重复提交表单(兼谈springmvc重定向操作)
自己用springmvc框架有一段时间了,但是都还一直分不清楚什么时候应该用转发,什么时候应该用重定向.可能用转发的情形太多了,以致于自己都忘记了还有重定向. 当用户提交post请求之后,刷新页面就会 ...
- Springboot-H2DB
为什么在Springboot中用H2DB 用Springboot开发需要连接数据库的程序的时候,使用H2DB作为内存数据库可以很方便的调试程序. 怎么用 1.加入依赖 <dependency&g ...
- 使用OpenLayers 勾画地图
<!DOCTYPE html> <html xmlns=http://www.w3.org/1999/xhtml> <head> <meta charset= ...
- (转)oracle触发器使用:after insert 与before insert的简单使用注意
本文转载自:http://blog.csdn.net/kuangfengbuyi/article/details/41446125 创建触发器时,触发器类型为after insert , 在begin ...
- 无法绕开的cut, awk, sed命令
linux命令的选项和选项后面的值的方式: 如果用 短选项, 选项值就放在短选项的后面, 如果用长选项, 值就用等于的方式. 最重要的是, 短选项后面的值, 跟短选项之间, 可以用空格, 也可以紧接着 ...
- CAS KVM 虚拟机的保护与恢复
目录 目录 方式一 方式二 方式一 思路:以 QCOW2 格式来备份和恢复被保护的 KVM 虚拟机 Step1:centos7_0(base qcow2) 以 qcow2 格式写入到 iSCSI 设备 ...