Solr facet pagination

眉间皱痕 提交于 2019-12-08 03:56:17

问题


How in Solr I can do pagination over a facet count?, I know that I have the facet.offset to skip records, but how I know how many total records has the facet?


回答1:


You need to apply Solr Patch SOLR-2242 to get the Facet distinct count.
The total count can be helpful to paginate.




回答2:


In Solr 5.3 and above use facet to get the total number of documents,

for that simply use,

facet=on

for example

http://<solr-url>/select?facet=on&indent=on&q=*:*&rows=0&wt=json

then you get a facets object in response, it will look like,

{
  "responseHeader":{
    "zkConnected":true,
    "status":0,
    "QTime":3,
    "params":{
      "q":"*:*",
      "indent":"on",
      "rows":"0",
      "facet":"on",
      "wt":"json"}},
  "response":{"numFound":8,"start":0,"maxScore":1.0,"docs":[]
  },
  "facet_counts":{
    "facet_queries":{},
    "facet_fields":{},
    "facet_ranges":{},
    "facet_intervals":{},
    "facet_heatmaps":{}}
}

you get numFound from response, which is the total number of records in that solr core

another way

if you have any facet query, use,

facet=on&json.facet={}

for example

http://<solr-url>/select?facet=on&indent=on&json.facet={}&q=*:*&rows=0&wt=json

then you get a facets object in response, it will look like,

{
  "responseHeader":{
    "zkConnected":true,
    "status":0,
    "QTime":3,
    "params":{
      "json.facet":"{}",
      "q":"*:*",
      "indent":"on",
      "rows":"0",
      "facet":"on",
      "wt":"json"}},
  "response":{"numFound":80,"start":0,"maxScore":1.0,"docs":[]
  },
  "facet_counts":{
    "facet_queries":{},
    "facet_fields":{},
    "facet_ranges":{},
    "facet_intervals":{},
    "facet_heatmaps":{}},
  "facets":{
    "count":80}}

from facets object you get count, which is the maximum number of records



来源:https://stackoverflow.com/questions/10757479/solr-facet-pagination

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!