设为首页 收藏本站
查看: 766|回复: 0

[经验分享] solr 中的group使用说明

[复制链接]

尚未签到

发表于 2015-11-12 07:18:46 | 显示全部楼层 |阅读模式

参数说明



  


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. DSC0000.png 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







  /**
* @Author fjsh
* @Title SearchGroup
* @Description 按group进行查找
* @param QUERY_CONTENT 查询内容
* @param QUERY_ROWS 查找的数量,默认是10
* @param GROUP true or false 是否按group查询
* @param GROUP_FIELD 查询field
* @param GROUP_LIMIT The number of results (documents) to return for each group. Defaults to 1
* @Return void
* @Throws
* @Date 2015-1-7
* 输出结果的时候,由于定义的数据索引没有做很好是调整,显示的结果并不理想,不过此方法可以作为参考
*/
public void SearchGroup(String QUERY_CONTENT,int QUERY_ROWS, Boolean GROUP, String GROUP_FIELD,String GROUP_LIMIT) {
SolrServer server = createSolrServer();  
SolrQuery param = new SolrQuery();  
param.setQuery("jobsName:"+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());
System.out.println(group.getGroupValue()+&quot;---&quot;+group.getResult().getNumFound());
}  
}  
}  
}




  效果不是很好,如果使用还是好好做好调整

版权声明:本文为博主原创文章,未经博主允许不得转载。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-138076-1-1.html 上篇帖子: solr定时实时重建索引和增量更新 下篇帖子: SolrPhpClient 支持solr4.x 的问题
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表