加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

用solr的facet实现聚合标签(转载)

发布时间:2020-12-13 22:27:44 所属栏目:百科 来源:网络整理
导读:Facet,单词意思是侧面,平面。哈哈,怎么学英文单词了…… 好吧,言归正题,solr的Facet是一个什么东西呢?我个人理解,反映一个搜索词的平面(或者说某一个分组),起到标签聚合统计的功能。举个列子说,像我们公司的电商类网站那样的对搜索结果聚合分类,

Facet,单词意思是侧面,平面。哈哈,怎么学英文单词了……

好吧,言归正题,solr的Facet是一个什么东西呢?我个人理解,反映一个搜索词的平面(或者说某一个分组),起到标签聚合统计的功能。举个列子说,像我们公司的电商类网站那样的对搜索结果聚合分类,品牌等属性。如下图

这个是搜索铁观音这个词,统计了分类和品牌2个侧面(分组),铁观音在生活分类下有64个,茗茶里面48……

上面这个说到底,就是某一类型的标签统计,比如xxx年热词等等,只要有记录,也能统计出来,当然,超大数据量提前优化好solr的性能。

介绍了一下facet之后,来说说怎么实现facet。facet的实现其实很简单,主要在搜索参数上带上就OK。

facet=on/true #代表开启facet
facet.field=cate #代表要统计的面(分组),比如上面的分类,品牌,可以多次出现
facet.limit =20 #每个分组最多返回条数
facet.mincount = 1 #这个表示分组下某一条目的最数据量
facet.missing = on/true #统计null的值
facet.method = #默认为fc,fc表示Field Cache
比如:http://localhost/product/select/?q=铁观音&facet=on&facet.field=category&facet.field=brand&facet.mincount=1在搜索结果中返回xml的facet结果

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
< lst name = "facet_counts" >
"facet_queries" />
"facet_fields" >
"category" >
int "2742" >64</ int >
"793" >48</ >
"2741" >12</ >
"801" >6</ >
"1087" >1</ >
</ lst >
"brand" >
"229" >74</ >
"227" >16</ >
"270" >13</ >
"317" >10</ >
"0" >4</ >
"165" >
"203" >3</ >
"147" >2</ >
"166" >
"217" >
"342" >
"343" >
>
>

<lst name="category"> 分组名
<int name="2742">64</int> 分组内条目,name表示条目,64是统计结果数。

用solrJ那就更简单了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
ModifiableSolrParams params = new ModifiableSolrParams();
params.set( "fq" ,fq);
"facet" "on" );
"facet.field" "category" "brand" );
"facet.mincount" "1" );
"facet.limit" "15" );
"q" "铁观音" );
QueryResponse qresponse = queryserver.query(params);
FacetField facetField = qresponse.getFacetField(Facet_CATEGORY);
List<Count> counts = null ;
if (facetField != ) {
counts = facetField.getValues();
(counts != ) {
for (Count count : counts) {
System.out.println(count.getName()+ " " +count.getCount());
}
}
}

Facet应用很简单,schema上的索引字段都可以作为面统计

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

相关内容
推荐文章
站长推荐
热点阅读