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

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

Say I indexed the following from my database:

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


        
相关标签:
4条回答
  • 2021-01-12 03:46

    Have a look at field collapsing, available in Solr 4.0. Sorting groups on relevance: group.sort=score desc.

    0 讨论(0)
  • 2021-01-12 03:48

    add the following field to your query

    • 'group':'true',
    • 'group.field':'source',
    • 'group.main':'true',
    • 'group.limit':10,
    0 讨论(0)
  • 2021-01-12 03:56

    http://XXX.XXX.XXX.XXX:8080/solr/autocomplete/select?q=displayterm:new&wt=json&indent=true&q.op=and&fl=displayterm&group=true&group.field=displayterm&rows=3&start=0

    Note:

    Response: start -> response start your id. rows -> how do you wat number of rows .

    Exp 
     1 step 
      &start=0&rows=3
    2 step 
      &start=3&rows=3
    3 step
      &start=6&rows=3
    etc.
    
    
    {
      "responseHeader":{
        "status":0,
        "QTime":1,
        "params":{
          "fl":"displayterm",
          "indent":"true",
          "start":"0",
          "q":"displayterm:new",
          "q.op":"and",
          "group.field":"displayterm",
          "group":"true",
          "wt":"json",
          "rows":"3"}},
      "grouped":{
        "displayterm":{
          "matches":231,
          "groups":[{
              "groupValue":null,
              "doclist":{"numFound":220,"start":0,"docs":[
                  {
                    "displayterm":"Professional News"}]
              }},
            {
              "groupValue":"general",
              "doclist":{"numFound":1,"start":0,"docs":[
                  {
                    "displayterm":"General News"}]
              }},
            {
              "groupValue":"delhi",
              "doclist":{"numFound":2,"start":0,"docs":[
                  {
                    "displayterm":"New Delhi"}]
              }}]}}}
    
    0 讨论(0)
  • 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 :)

    0 讨论(0)
提交回复
热议问题