facet 自己理解就是分组聚合用的, 如下说明
http://blog.csdn.net/a925907195/article/details/47257243

Solr中的group与facet的区别

如果是简单的使用的话,那么Facet与group都可以用来进行数据的聚合查询,但是他们还是有很大的区别的。

首先上facet跟group的操作:

Facet的例子:

public voidFacetFieldQuery() throws Exception {

solrServer = createSolrServer();

SolrQueryquery = newSolrQuery();//建立一个新的查询

query.setQuery("jobsName:计算机维护");

query.setFacet(true);//设置facet=on

// 分类信息分为:薪水,发布时间,教育背景,工作经验,公司类型,工作类型

query.addFacetField(new String[] {"salary","publishDate",

"educateBackground","jobExperience","companytype","jobsType" });//设置需要facet的字段

query.setFacetLimit(10);// 限制facet返回的数量

query.setFacetMissing(false);//不统计null的值

query.setFacetMinCount(1);// 设置返回的数据中每个分组的数据最小值,比如设置为1,则统计数量最小为1,不然不显示

//query.addFacetQuery("publishDate:[2014-04-11T00:00:00Z TO2014-04-13T00:00:00Z]");

QueryResponseresponse = solrServer.query(query);

System.out.println("查询时间:" + response.getQTime());

List<FacetField>facets = response.getFacetFields();//返回的facet列表

for (FacetField facet :facets) {

System.out.println(facet.getName());

System.out.println("----------------");

List<Count>counts = facet.getValues();

for (Count count : counts){

System.out.println(count.getName()+":"+ count.getCount());

}

System.out.println();

}

}

运行结果如下:

查询时间:66

salary

----------------

面议:6882

2001-4000:1508

其他:671

4001-6000:536

3000-4499:224

2000-2999:181

6001-8000:179

3000-5000:82

1000-2000:81

4500-5999:75

publishDate

----------------

2014-08-05T00:00:00Z:793

2014-08-04T00:00:00Z:775

2014-07-30T00:00:00Z:601

2014-08-07T00:00:00Z:548

2014-08-06T00:00:00Z:539

2014-08-11T00:00:00Z:472

2014-08-20T00:00:00Z:439

2014-08-12T00:00:00Z:438

2014-08-01T00:00:00Z:405

2014-08-03T00:00:00Z:376

educateBackground

----------------

大专:4486

本科:1872

其他:1344

不限:1147

中专:680

高中:472

薪水范围::430

中技:161

初中:140

硕士:94

jobExperience

----------------

其他:2623

不限:2249

1-3年:1770

1年:1301

2年:773

3-4年:528

3-5年:379

应届毕业生:309

5-7年:162

1年以上:136

companytype

----------------

民营公司:3702

民营:2605

国企:835

股份制企业:729

其他:707

合资:632

外资(非欧美):377

外商独资:350

外资(欧美):271

上市公司:228

jobsType

----------------

全职:10734

兼职:59

实习:39

Group查询:

/**group查询

@throws Exception

*/

public void GroupFieldQuery() throws Exception {

solrServer = createSolrServer();

SolrQuery query = new SolrQuery("jobsName:计算机维护");

// 设置通过facet查询为true,表示查询时使用facet机制

query.setParam(GroupParams.GROUP,true);

query.setParam(GroupParams.GROUP_FIELD,"salary");

// 设置每个quality对应的

query.setParam(GroupParams.GROUP_LIMIT,"1");

// 设置返回doc文档数据,因只需要数量,故设置为0

query.setRows(10);

QueryResponse response = solrServer.query(query);

if (response !=null) {

GroupResponse groupResponse =response.getGroupResponse();

if(groupResponse !=null) {

List<GroupCommand> groupList =groupResponse.getValues();

for(GroupCommand groupCommand : groupList){

List<Group> groups =groupCommand.getValues();

for(Group group : groups) {

System.out.println("group查询..."+group.getGroupValue()+"数量为:"+group.getResult().getNumFound());

}

}

}

}

}

group查询...面议数量为:6882

group查询...4500-5999数量为:75

group查询...2001-4000数量为:1508

group查询...其他数量为:671

group查询...2000-2999数量为:181

group查询...4001-6000数量为:536

group查询...2000-4000数量为:19

group查询...2000-3000数量为:34

group查询...3000-4499数量为:224

group查询...3000-5000数量为:82

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

The Grouping feature only works if groups are inthe same shard. You must use the custom sharding feature to use the Groupingfeature.

两者其实用起来还是有比较大的区别的,但是如果说区别的话可以看下wiki上的这段

Field Collapsing and Result Grouping aredifferent ways to think about the same Solr feature.

Field Collapsing collapsesa group of results with the same field value down to a single (or fixed number)of entries. For example, most search engines such as Google collapse on site soonly one or two entries are shown, along with a link to click to see moreresults from that site. Field collapsing can also be used to suppress duplicatedocuments.

Result Grouping groupsdocuments with a common field value into groups, returning the top documentsper group, and the top groups based on what documents are in the groups. Oneexample is a search at Best Buy for a common term such as DVD, that shows thetop 3 results for each category ("TVs &Video","Movies","Computers", etc)

下面这两个查询语句一个是facet的一个是group的

http://localhost:8080/solr/JobsOtherWeb0/select?q=jobsName%3A%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BB%B4%E6%8A%A4&group=true&group.field=salary&group.limit=1&rows=10

http://localhost:8080/solr/JobsOtherWeb0/select?q=jobsName%3A%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BB%B4%E6%8A%A4&facet=true&facet.field=salary&facet.field=publishDate&facet.field=educateBackground&facet.field=jobExperience&facet.field=companytype&facet.field=jobsType&facet.limit=10&facet.missing=false&facet.mincount=1

其中facet查询出的如下:(只截取部分结果)

根据条件查询出的是查询结果,facet是聚类后的信息跟查询条件是分开的,查询结果也跟facet没关系。

但是下面看group查询的

也就是你的查询条件是跟group相关的,返回的查询结果也是跟group相关的,比如说你想要查询的结果在每个分组中 都有数据采集,那么就最好用group,这样出来的数据跟group也是相关的,但是有个问题,比如说你要查询group每个采集1个,ok那么你查询的 时候的条件rows就无效了(也不能说无效,主要是看你怎么使用),就是最多每个分组给你返回一个,多了没有了。

再细说点就是如果你想查询归查询聚类归聚类,那么使用facet,如果想使用类似采集的效果,每个group分组采集多少个,那么使用group查询。

Solr中的group与facet的区别 [转]的更多相关文章

  1. Solr中的group与facet的区别

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

  2. Solr中Facet用法和Group用法

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

  3. Solr中的q与fq参数的区别

    转自:搜索系统5:Solr中的q与fq参数的区别在那儿 1.对结果排序有影响 今天遇到一个问题,把相同的参数比如name:张三,放到q与fq,两者返回的结果完全不一样. 经过debug发现,原因是这两 ...

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

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

  5. Solr中的概念:分析器(analyzer)、字符过滤器(character filter)、分词器(Tokenizer)、词元过滤器(Token Filter)、 词干化(Stemming)

    文本中包含许多文本处理步骤,比如:分词,大写转小写,词干化,同义词转化和许多的文本处理. 文本分析既用于索引时对一文本域的处理,也用于查询时查询字符串的文本处理.文本处理对搜索引擎的搜索结果有着重要的 ...

  6. Solr 中的 docValues=true

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

  7. Oracle中Union与Union All的区别(适用多个数据库)

    Oracle中Union与Union All的区别(适用多个数据库) 如果我们需要将两个select语句的结果作为一个整体显示出来,我们就需要用到union或者union all关键字.union(或 ...

  8. Solr 08 - 在Solr Web管理页面中查询索引数据 (Solr中各类查询参数的使用方法)

    目录 1 Solr管理页面的查询入口 2 Solr查询输入框简介 3 Solr管理页面的查询方案 1 Solr管理页面的查询入口 选中需要查询的SolrCore, 然后在菜单栏选择[Query]: 2 ...

  9. solr中Cache综述

    一.概述 Solr查询的核心类就是SolrIndexSearcher,每个core通常在同一时刻只由当前的SolrIndexSearcher供上层的handler使用(当切换SolrIndexSear ...

随机推荐

  1. 运算符与类型转换 mogondb简介

    运算符与类型转换   1.运算符 (1)分类 算术运算符.关系运算符.逻辑运算符.位运算符.赋值运算符.其他运算符 >.算术运算符: 运算符 描述 + 把两个操作数相加 - 从第一个操作数中减去 ...

  2. hdoj2680 Choose the best route

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission ...

  3. 各种“GND”

    资料来自网上,把个人觉得靠谱的摘取下来 1.地分类: a)直流地:直流电路“地”,零电位参考点: b)交流地:交流电的零线.要与地线区别开,不过,有时候拉电入户之前会把地线和零线接在一起: c)功率地 ...

  4. VS2010打开高版本VS解决方案

    http://blog.csdn.net/backspace110/article/details/62111273 Microsoft Visual Studio Solution File, Fo ...

  5. Hibernate中Criteria的完整用法?

    http://www.cnblogs.com/mabaishui/archive/2009/10/16/1584510.html

  6. ubuntu安装ibus-goolepinyin通用方法

    1:获取安装包 http://code.google.com/p/libgooglepinyin/downloads/list

  7. YTU 2852: 二分查找

    2852: 二分查找 时间限制: 1 Sec  内存限制: 128 MB 提交: 215  解决: 79 题目描述 输入不多于20个升序排列的整数,以及一个待查找的数key,输出key在序列中的位置( ...

  8. java 泛型的理解与应用

    为什么使用泛型? 举个例子: public class GenericTest { public static void main(String[] args) { List list = new A ...

  9. 1.import和include区别 2.NSLog 和printf区别 3.创建对象做的事情 4. 类和对象方法比较 5 匿名对象优缺点 6. 封装 7.作用域范围 8.id和instancetype 9.自定义构造方法规范 10.nil和Nil及NULL、NSNull区别

    1.import和include的区别: import可以防止头文件的重复包含 2.NSLog 和printf的区别: 1,NSLog可以自动换行, 输出调试信息, printf不能. 2,NSLog ...

  10. 【HNOI 2008】 越狱

    [题目链接] 点击打开链接 [算法] 显然,越狱情况数 = 总情况数 - 不能越狱的情况数 很容易发现,总情况数 = M^N 不能越狱的情况数怎么求呢? 我们发现,不能越狱的情况,其实就是第一个人任选 ...