solr group分组查询
2016-10-26 08:17
323 查看
如:http://localhost:8080/solr/test_core/select?q=*:*&wt=json&indent=true&group=true&group.field=field&group.limit=0
参数说明
Solrj检索代码:
[java] view plain copy
SolrServer server = this.getSolrServer();
SolrQuery param = new SolrQuery();
param.setQuery(QUERY_CONTENT);
param.setRows(QUERY_ROWS);
param.setParam(GroupParams.GROUP, GROUP);
param.setParam(GroupParams.GROUP_FIELD, GROUP_FIELD);
param.setParam(GroupParams.GROUP_LIMIT, GROUP_LIMIT);
QueryResponse response = null;
try {
response = server.query(param);
} catch (SolrServerException e) {
logger.error(e.getMessage(), e);
}
Map<String, Integer> info = new HashMap<String, Integer>();
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) {
info.put(group.getGroupValue(), (int)group.getResult().getNumFound());
}
}
}
参数说明
param name | param value | description |
group | true/false | if true, turn on result grouping |
group.field | [fieldname] | Group based on the unique values of a field. The field must currently be single-valued and must be either indexed, or be another field type that has a value source and works in a function query - such as ExternalFileField. Note: for Solr 3.x versions the field must by a string like field such as StrField or TextField, otherwise a http status 400 is returned. |
group.func | [function query] | Group based on the unique values of a function query. Solr4.0 This parameter only is supported on 4.0 |
group.query | [query] | Return a single group of documents that also match the given query. |
rows | [number] | The number of groups to return. Defaults to 10. |
start | [number] | The offset into the list of groups. |
group.limit | [number] | The number of results (documents) to return for each group. Defaults to 1. |
group.offset | [number] | The offset into the document list of each group. |
sort | [sortspec] | How to sort the groups relative to each other. For example, sort=popularity desc will cause the groups to be sorted according to the highest popularity doc in each group. Defaults to "score desc". |
group.sort | [sortspec] | How to sort documents within a single group. Defaults to the same value as the sort parameter. |
group.format | grouped/simple | if simple, the grouped documents are presented in a single flat list. The start and rows parameters refer to numbers of documents instead of numbers of groups. |
group.main | true/false | If true, the result of the last field grouping command is used as the main result list in the response, using group.format=simple |
group.ngroups | true/false | If true, includes the number of groups that have matched the query. Default is false. Solr4.1 WARNING: If this parameter is set to true on a sharded environment, all the documents that belong to the same group have to be located in the same shard, otherwise the count will be incorrect. If you are using SolrCloud, consider using "custom hashing" |
group.truncate | true/false | If true, facet counts are based on the most relevant document of each group matching the query. Same applies for StatsComponent. Default is false. Solr3.4 Supported from Solr 3.4 and up. |
group.facet | true/false | Whether to compute grouped facets for the field facets specified in facet.field parameters. Grouped facets are computed based on the first specified group. Just like normal field faceting, fields shouldn't be tokenized (otherwise counts are computed for each token). Grouped faceting supports single and multivalued fields. Default is false. Solr4.0 WARNING: If this parameter is set to true on a sharded environment, all the documents that belong to the same group have to be located in the same shard, otherwise the count will be incorrect. If you are using SolrCloud, consider using "custom hashing" |
group.cache.percent | [0-100] | If > 0 enables grouping cache. Grouping is executed actual two searches. This option caches the second search. A value of 0 disables grouping caching. Default is 0. Tests have shown that this cache only improves search time with boolean queries, wildcard queries and fuzzy queries. For simple queries like a term query or a match all query this cache has a negative impact on performance |
[java] view plain copy
SolrServer server = this.getSolrServer();
SolrQuery param = new SolrQuery();
param.setQuery(QUERY_CONTENT);
param.setRows(QUERY_ROWS);
param.setParam(GroupParams.GROUP, GROUP);
param.setParam(GroupParams.GROUP_FIELD, GROUP_FIELD);
param.setParam(GroupParams.GROUP_LIMIT, GROUP_LIMIT);
QueryResponse response = null;
try {
response = server.query(param);
} catch (SolrServerException e) {
logger.error(e.getMessage(), e);
}
Map<String, Integer> info = new HashMap<String, Integer>();
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) {
info.put(group.getGroupValue(), (int)group.getResult().getNumFound());
}
}
}
相关文章推荐
- Solr分组聚合查询之Group
- solr group分组查询
- solr分组查询
- LinQ 标准的查询操作符 分组group by into, select new,orderby descending,from in
- Solr --- Group查询与Facet区别
- SQL group by分组查询
- SQL group 分组查询
- 【Solr4.7.0学习笔记】系列之一:Facet分组查询
- MongoVUE下实现MongoDB的Group分组查询
- mysql 分组查询以及显示各个分组所有的温度和时间要用GROUP_CONCAT
- 8.4Solr API使用(Result Grouping分组查询)
- 分组查询 Group by , Group by all , Having
- sql 嵌套查询,并通过分组 和字段连接函数GROUP_CONCAT 查询出符合业务的结果集
- group分组查询
- Solr之分组查询facet
- Solr Grouping / Field Collapsing(分组查询)
- MongoDB中的一个分组统计的查询(Group ... Distinct)
- SolrNet高级用法(分页、Facet查询、任意分组)
- SQL group by分组查询
- group_concat+case when实现分组查询中,返回每组的特定数据