solr中facet及facet.pivot理解
Facet['fæsɪt]很难翻译,只能靠例子来理解了。Solr作者Yonik Seeley也给出更为直接的名字:导航(Guided Navigation)、参数化查询(Paramatic Search)。
上面是比较直接的Faceted Search例子,品牌、产品特征、卖家,均是 Facet 。而Apple、Lenovo等品牌,就是 Facet values 或者说 Constraints ,而Facet values所带的统计值就是 Facet count/Constraint count 。
2 、Facet 使用
q = 超级本
facet = true
facet.field = 产品特性
facet.field = 品牌
facet.field = 卖家
http://…/select?q=超级本&facet=true&wt=json
&facet.field=品牌&facet.field=产品特性&facet.field=卖家
也可以提交查询条件,设置fq(filter query)。
q = 电脑
facet = true
fq = 价格:[8000 TO *]
facet.mincount = 1 // fq将不符合的字段过滤后,会显示count为0
facet.field = 产品特性
facet.field = 品牌
facet.field = 卖家
http://…/select?q=超级本&facet=true&wt=json
&fq=价格:[8000 TO *]&facet.mincount=1
&facet.field=品牌&facet.field=产品特性&facet.field=卖家
"facet_counts": { "facet_fields": {"品牌": ["Apple", 4,"Lenovo", 39…]"产品特性": ["显卡", 42,"酷睿", 38…]…}}
如果用户选择了Apple这个分类,查询条件中需要添加另外一个fq查询条件,并移除Apple所在的facet.field。
http://…/select?q=超级本&facet=true&wt=json
&fq=价格:[8000 TO *]&fq=品牌:Apple&facet.mincount=1
&facet.field= 品牌&facet.field=产品特性&facet.field=卖家
3 、Facet 参数
facet.prefix – 限制constaints的前缀
facet.mincount=0 – 限制constants count的最小返回值,默认为0
facet.sort=count – 排序的方式,根据count或者index
facet.offset=0 – 表示在当前排序情况下的偏移,可以做分页
facet.limit=100 – constraints返回的数目
facet.missing=false – 是否返回没有值的field
facet.date – Deprecated, use facet.range
facet.query
指定一个查询字符串作为Facet Constraint
facet.query = rank:[* TO 20]
facet.query = rank:[21 TO *]
"facet_counts": { "facet_fields": {"品牌": ["Apple", 4,"Lenovo", 10…]"产品特性": ["显卡", 11,"酷睿", 20…]…}}
facet.range
http://…/select?&facet=true
&facet.range=price
&facet.range.start=5000
&facet.range.end=8000
&facet.range.gap=1000
<result numFound="27" ... />...<lst name="facet_counts"> <lst name="facet_queries"> <int name="rank:[* TO 20]">2</int> <int name="rank:[21 TO *]">15</int> </lst> ...
WARNING: range范围是左闭右开,[start, end)
facet.pivot
这个是Solr 4.0的新特性,pivot和facet一样难理解,还是用例子来讲吧。
Syntax: facet.pivot=field1,field2,field3...
e.g. facet.pivot=comment_user, grade
#docs |
#docs grade:好 |
#docs 等级:中 |
#docs 等级:差 |
|
comment_user:1 |
10 |
8 |
1 |
1 |
comment_user:2 |
20 |
18 |
2 |
0 |
comment_user:3 |
15 |
12 |
2 |
1 |
comment_user:4 |
18 |
15 |
2 |
1 |
"facet_counts":{ "facet_pivot":{ "comment_user, grade ":[{ "field":"comment_user", "value":"1", "count":10, "pivot":[{ "field":"grade", "value":"好", "count":8}, { "field":"grade", "value":"中", "count":1}, { "field":"grade", "value":"差", "count":1}] }, { "field":" comment_user ", "value":"2", "count":20, "pivot":[{ …
没有pivot机制的话,要做到上面那点可能需要多次查询:
http://...q= comment&fq= grade:好&facet=true&facet.field=comment_user
http://...q=comment&fq=grade:中&facet=true&facet.field=comment_user
http://...q=comment&fq=grade:差&facet=true&facet.field=comment_user
Facet.pivot - Computes a Matrix of Constraint Counts across multiple Facet Fields. by Yonik Seeley.
上面那个解释很不错,只能理解不能翻译。
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, 0);
- 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=0;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 = 0;
- int neg = 0;
- List<PivotField> fieldList = pivot.getPivot();
- if(fieldList != null){
- for(PivotField field:fieldList){
- int proValue = (Integer) field.getValue();
- int count = field.getCount();
- if(proValue == 1){
- 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来统计,不错的东东。
转载于:https://www.cnblogs.com/cuihongyu3503319/p/9395733.html
solr中facet及facet.pivot理解相关推荐
- camel 数据库_使用Camel在来自不同来源的Solr中索引数据
camel 数据库 Apache Solr是建立在Lucene之上的"流行的,快速的开源企业搜索平台". 为了进行搜索(并查找结果),通常需要从不同的源(例如内容管理系统,关系数据 ...
- 使用Camel在来自不同来源的Solr中索引数据
Apache Solr是建立在Lucene之上的"流行的,快速的开源企业搜索平台". 为了进行搜索(并查找结果),通常需要从不同的来源(例如内容管理系统,关系数据库,旧系统)中提取 ...
- React router 的 Route 中 component 和 render 属性理解
React router 的 Route 中 component 和 render 属性理解 Route 标签的三个互斥属性 render.component.children Route 就是用来匹 ...
- Solr 中遇到的问题
1.问题1 :whose UTF8 encoding is longer than the max length 32766 Error from server at http://localhost ...
- python函数def里面嵌套def,python菜鸟求问关于嵌套函数中作用域范围应该怎么理解?,python嵌套,直接上代码def l(l...
python菜鸟求问关于嵌套函数中作用域范围应该怎么理解?,python嵌套,直接上代码def l(l 直接上代码def l(list): def d(): return list return d ...
- solr mysql 导入命令_(solr系列:四)将mysql数据库中的数据导入到solr中及删除solr中导入的数据...
在前面的博文中,已完成了在tomcat中对solr的部署,为solr添加了一个自定义的core,并且引入了ik分词器. 那么该如何将本地的mysql的数据导入到solr中呢? 准备工作: 1.mysq ...
- Solr中Field常用属性
FieldType 实例:<fieldType name="text_ik" class="solr.TextField"></fieldTy ...
- 7.STM32中对DMA_Config()函数的理解(自定义)测试DMA传输数据时CPU还可继续工作其他的事
STM32中对DMA_Config()函数的理解(自定义):
- 4.STM32中对USART1_Config()函数的理解(自定义)
STM32中对USART1_Config()函数的理解
最新文章
- Java基础super关键字、final关键字、static关键字、匿名对象整理
- 无聊的python课程_无聊的钢镚的python学习之路
- java处理XSS过滤的方法
- Intel 64/x86_64/IA-32/x86处理器 - SIMD指令集 - SSE扩展(7) - 混洗指令 解组合指令
- Discuz! 出现“您当前的访问请求当中含有非法字符“解决方法
- java systemoutprint_java – 为什么System.out.print()不起作用?
- 主机和虚拟机复制粘贴失效的解决方案
- 【数据结构和算法笔记】串详解:c实现
- 论文学习: Journaling of Journal is (almost) Free 未整理
- 【收藏】NLP技术学习路线图,值得收藏,附下载
- 《Web漏洞防护》读书笔记——第9章,XSS防护
- 微信小程序开发笔记1——使用npm脚本实现自动化切换环境配置
- 数模--2022华中杯A题(Java实现)
- 基于OpenCV实现的灰度图幻影坦克
- PLC协议宏通信功能介绍
- String源码详解
- 英语c开头语言,C开头的英语短语集锦
- APUE读书笔记-第十一章-线程
- 已解决ImportError: DLL 1oad failed while importing, onnxruntime_pybind11_state: 参数错误。
- python数组除以常数_Python中自我除以数组的乘积
热门文章
- js 随机数_JS常用方法和一些封装:随机数生成
- java miniui datagrid_miniui datagrid 的客户端分页解决方案
- linux 安装mysql 云盘_linux下 安装mysql教程
- 循环在c语言中的表示什么作用,《C语言中的for循环》教案
- CNN训练可视化特征图(tensorflow2.x实现)
- 在C ++中将字符串转换为int
- Java中的守护程序线程
- Android CheckBox
- kotlin函数_Kotlin函数
- 数据库表设计必需元素_HTML5输入,必需,模式,数据列表