Solr --- Group查询

x33g5p2x  于2021-12-20 转载在 其他  
字(4.1k)|赞(0)|评价(0)|浏览(335)

简介

Group查询将包含相同字段的文档进行分组,每组返回得分较高的文档。
例如:在一个电子零售网站搜索”DVD”,可能会返回三个类目”TV and Video”、”Movies”、”Computers”,并且每个类目包含三个文档。查询词”DVD”在这三个类目中都出现了,Group查询可以将它们分组以此来增加与用户的关联。

请求参数

参数类型描述
groupbool设置为true时,查询结果将被分组
group.fieldstringThe name of the field by which to group results. The field must be single-valued, and either be indexed or a field type that has a value source and works in a function query, such as ExternalFileField . It must also be a string-based field, such as StrField or TextField
group.funcqueryGroup based on the unique values of a function query
group.queryqueryReturn a single group of documents that match the given query
rowsintegerThe number of groups to return. The default value is 10.
startintegerSpecifies an initial offset for the list of groups.
group.limitintegerSpecifies the number of results to return for each group. The default value is 1.
group.offsetintegerSpecifies an initial offset for the document list of each group.
sortsortspecSpecifies how Solr sorts the groups relative to each other. For example, sort=popularity desc will cause the groups to be sorted according to the highest popularity document in each group. The default value is score desc.
group.sortsortspecSpecifies how Solr sorts documents within each group. The default behavior if group.sort is not specified is to use the same effective value as the sort parameter.
group.formatboolIf this parameter is set to simple, the grouped documents are presented in a single flat list, and the start and rows parameters affect the numbers of documents instead of groups.
group.mainboolIf true, the result of the first field grouping command is used as the main result list in the response, using group.format=simple.
group.ngroupsboolIf true, Solr includes the number of groups that have matched the query in the results. The default value is false.
group.truncateboolIf true, facet counts are based on the most relevant document of each group matching the query. The default value is false.
group.facetboolDetermines whether to compute grouped facets for the field facets specified in facet.field parameters. Grouped facets are computed based on the first specified group. As with 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.
group.cache.percentinteger between 0 and 100Setting this parameter to a number greater than 0 enables caching for result grouping. Result Grouping executes two searches; this option caches the second search. The default value is 0. Testing has shown that group caching only improves search time with Boolean, wildcard, and fuzzy queries. For simple queries like term or “match all” queries, group caching degrades performance.

查询事例

基于字段manu_exact对查询结果进行分组:
http://localhost:8983/solr/techproducts/select?wt=json&indent=true&fl=id,name&q=solr+memory&group=true&group.field=manu_exact

查询结果:

{
...
"grouped":{
"manu_exact":{
"matches":6,
"groups":[{
"groupValue":"Apache Software Foundation",
"doclist":{"numFound":1,"start":0,"docs":[
{
"id":"SOLR1000",
"name":"Solr, the Enterprise Search Server"}]
}},
{
"groupValue":"Corsair Microsystems Inc.",
"doclist":{"numFound":2,"start":0,"docs":[
{
"id":"VS1GB400C3",
"name":"CORSAIR ValueSelect 1GB 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) System Memory - Retail"}]
}},
{
"groupValue":"A-DATA Technology Inc.",
"doclist":{"numFound":1,"start":0,"docs":[
{
"id":"VDBDB1A16",
"name":"A-DATA V-Series 1GB 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) System Memory - OEM"}]
}},
{
"groupValue":"Canon Inc.",
"doclist":{"numFound":1,"start":0,"docs":[
{
"id":"0579B002",
"name":"Canon PIXMA MP500 All-In-One Photo Printer"}]
}},
{
"groupValue":"ASUS Computer Inc.",
"doclist":{"numFound":1,"start":0,"docs":[
{
"id":"EN7800GTX/2DHTV/256M",
"name":"ASUS Extreme N7800GTX/2DHTV (256 MB)"}]
} } ] } }

查询共命中了6个文档,其中有5个唯一的值只在一个文档中出现(numFound=1)。每个组中文档的排列顺序是按照group.sort=score desc参数确定的。整个Group查询结果中文档的排列顺序是按照sort=score desc参数确定的。

参考

apache-solr-ref-guide-6.0

相关文章

微信公众号

最新文章

更多