Solr --- Group查询

来源:互联网 发布:苹果手机挣钱软件 编辑:程序博客网 时间:2024/06/06 03:24

简介

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

请求参数

参数 类型 描述 group bool 设置为true时,查询结果将被分组 group.field string The 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.func query Group based on the unique values of a function query group.query query Return a single group of documents that match the given query rows integer The number of groups to return. The default value is 10. start integer Specifies an initial offset for the list of groups. group.limit integer Specifies the number of results to return for each group. The default value is 1. group.offset integer Specifies an initial offset for the document list of each group. sort sortspec Specifies 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.sort sortspec Specifies 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.format bool If 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.main bool If true, the result of the first field grouping command is used as the main result list in the response, using group.format=simple. group.ngroups bool If true, Solr includes the number of groups that have matched the query in the results. The default value is false. group.truncate bool If true, facet counts are based on the most relevant document of each group matching the query. The default value is false. group.facet bool Determines 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.percent integer between 0 and 100 Setting 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 (PC3200) 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

0 0
原创粉丝点击