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两个维度统计:

  1. public List<ReportNewsTypeDTO> queryNewsType(
  2. ReportQuery reportQuery) {
  3. HttpSolrServer solrServer = SolrServer.getInstance().getServer();
  4. SolrQuery sQuery = new SolrQuery();
  5. List<ReportNewsTypeDTO> list = new ArrayList<ReportNewsTypeDTO>();
  6. try {
  7. String para = this.initReportQueryPara(reportQuery, 0);
  8. sQuery.setFacet(true);
  9. sQuery.add("facet.pivot", "newsType,property");//根据这两维度来分组查询
  10. sQuery.setQuery(para);
  11. QueryResponse response = solrServer.query(sQuery,SolrRequest.METHOD.POST);
  12. NamedList<List<PivotField>> namedList = response.getFacetPivot();
  13. System.out.println(namedList);//底下为啥要这样判断,把这个值打印出来,你就明白了
  14. if(namedList != null){
  15. List<PivotField> pivotList = null;
  16. for(int i=0;i<namedList.size();i++){
  17. pivotList = namedList.getVal(i);
  18. if(pivotList != null){
  19. ReportNewsTypeDTO dto = null;
  20. for(PivotField pivot:pivotList){
  21. dto = new ReportNewsTypeDTO();
  22. dto.setNewsTypeId((Integer)pivot.getValue());
  23. dto.setNewsTypeName(News.newsTypeMap.get((Integer)pivot.getValue()));
  24. int pos = 0;
  25. int neg = 0;
  26. List<PivotField> fieldList = pivot.getPivot();
  27. if(fieldList != null){
  28. for(PivotField field:fieldList){
  29. int proValue = (Integer) field.getValue();
  30. int count = field.getCount();
  31. if(proValue == 1){
  32. pos = count;
  33. }else{
  34. neg = count;
  35. }
  36. }
  37. }
  38. dto.setPositiveCount(pos);
  39. dto.setNegativeCount(neg);
  40. list.add(dto);
  41. }
  42. }
  43. }
  44. }
  45.  
  46. return list;
  47. } catch (SolrServerException e) {
  48. log.error("查询solr失败", e);
  49. e.printStackTrace();
  50. } finally{
  51. solrServer.shutdown();
  52. solrServer = null;
  53. }
  54. return list;
  55. }
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中facet及facet.pivot理解的更多相关文章

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

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

  2. Solr中Facet用法和Group用法

    Group分组划分结果,返回的是分组结果: Facet分组统计,侧重统计,返回的是分组后的数量: 一.Group用法: //组查询基础配置params.set(GroupParams.GROUP, & ...

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

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

  4. Solr中的group与facet的区别 [转]

    Solr中的group与facet的区别 facet 自己理解就是分组聚合用的, 如下说明 http://blog.csdn.net/a925907195/article/details/472572 ...

  5. Solr中的group与facet的区别

    Solr中的group与facet的区别 如果是简单的使用的话,那么Facet与group都可以用来进行数据的聚合查询,但是他们还是有很大的区别的. 首先上facet跟group的操作: Facet的 ...

  6. 指尖上的电商---(8)Solr中Facet的使用方法

    在大型电子商务站点中,在商品列表页,我们都能够看到商品按分类,品牌,价格的分类显示,例如以下图,这些我们能够使用solr中的facet功能实现. facet的基本功能就是对搜索结果中的商品进行分类. ...

  7. 7.solr学习速成之facet

    Facet 介绍   Facet 是 solr 的高级搜索功能之一 ,可以给用户提供更友好的搜索体验,在搜索关键字的同时 , 能够按照 Facet 的字段进行分组并统计.        比如你上淘宝, ...

  8. Solr --- Group查询与Facet区别

    简介 facet的查询结果主要是分组信息:有什么分组,每个分组包括多少记录:但是分组中有哪些数据是不可知道的,只有进一步搜索. group则类似于关系数据库的group by,可以用于一个或者几个字段 ...

  9. Solr 中的 docValues=true

    前言:  在Lucene4.x之后,出现一个重大的特性,就是索引支持DocValues,这对于广大的solr和elasticsearch用户,无疑来说是一个福音,这玩意的出现通过牺牲一定的磁盘空间带来 ...

随机推荐

  1. top command-linux下用top命令查看cpu利用率超过100%

    1.  这里显示的所有的cpu加起来的使用率,说明你的CPU是多核,你运行top后按大键盘1看看,可以显示每个cpu的使用率,top里显示的是把所有使用率加起来;    2.查看CPU信息; cat ...

  2. OLED的相关信息

    有2种方式与OLED模块相连接,一种是8080的并口方式,另一种是4线SPI方式. ALIENTEK OLED 模块的 8080 接口方式需要如下一些信号线:CS: OLED 片选信号.WR:向 OL ...

  3. page 分页

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...

  4. aircrack-ng 工具集学习

    一.aircrack-ng简介 aircrack-ng是Aircrack项目的一个分支.是一个与802.11标准的无线网络分析有关的安全软件,主要功能有:网络侦测,数据包嗅探,WEP和WPA/WPA2 ...

  5. git代码回退

    情况1.还没有push可能 git add ,commit以后发现代码有点问题,想取消提交,用: reset git reset [--soft | --mixed | --hard] eg:  gi ...

  6. log4net保存到数据库系列一:WebConfig中配置log4net

    园子里面有很多关于log4net保存到数据库的帖子,但是要动手操作还是比较不易,从头开始学习log4net数据库日志 一.WebConfig中配置log4net 二.独立配置文件中配置log4net ...

  7. 树莓派做下载机+Web服务器(Aria2下载+yaaw做UI+nginx)

    今天收到了小派,UK产的绿板子,还配了个透明盒子,装在里面闪亮亮的很好看,而且只有卡片大小,寻思着用它做什么好呢?想来想去,看到人家拿小派作家庭媒体中心,还有人拿它当下载机,于是就萌生了一个家庭媒体中 ...

  8. [C++] 一个能够定时自毁的类的实现

    试想一下, 有没有这种需求: 对于每一个新的对象, 我们希望它能够在一定时间后自动销毁, 前提是我们没有在这段时间内给它发出重置信号. 这种需求其实是有的, 比如在电影里, 主角知道了一个反派不希望被 ...

  9. vue-router 知识点

    vue-router配置scrollBehavior 第三个参数 savedPosition 当且仅当 popstate 导航 (通过浏览器的 前进/后退 按钮触发) 时才可用. 注意: 这个功能只在 ...

  10. HTMLCanvasElement.toBlob() 兼容性及使用

    toBlob 兼容性: 在最新版chrome和firefox中能正常使用,在Safari中报错:没有这个函数 规避方法: 不使用toBlob,使用toDataURL()将file转成base64编码, ...