Solr - how to “group by” and “limit”?

后端 未结 4 1593
悲哀的现实
悲哀的现实 2021-01-12 03:39

Say I indexed the following from my database:

======================================
| Id |  Code | Description           |
=================================         


        
4条回答
  •  盖世英雄少女心
    2021-01-12 04:06

    The simplest way to achieve what you want is to use Solr grouping capabilities also called Field Collapsing. You would have to add the following parameters to your query:

    • group=true - that would turn on the grouping module
    • group.field=Code - that would tell Solr on which field the grouping should be done
    • rows=10 - that would tell Solr to limit the number of unique groups to 10 at max

    If you would like to page through groups you should use the rows and start parameter. To control the results inside the groups themselves you would use group.limit and group.offset.

    Hopefully that helps :)

提交回复
热议问题