繁体   English   中英

Solr方面等同于group by?

[英]Solr facet equivalent of group by?

如果我有这样的数据:

{"field1":"x", "field2":".."}
{"field1":"x", "field2":".."}
{"field1":"y", "field2":".."}
{"field1":"y", "field2":".."}
{"field1":"y", "field2":".."}

使用简单的group=true&group.field=field1&group.limit=0我得到如下结果:

{
  "responseHeader":{..}
  "grouped":{
        "field1": {
            "matches": 5,
            "groups": [

                {"groupValue": "x", "doclist":{"numFound": 2, ...}}
                {"groupValue": "y", "doclist":{"numFound": 3, ...}}

            ]
        }

  }
}

使用此方法,我知道为每个groupValuenumFound )找到的文档numFound 问题是我需要按降序对结果组进行排序,这两种排序都不可能(简单的sort=numFound会导致异常,表示字段numFound不存在,而group.sort会对内部的文档进行排序每组)。

是否有使用facet的等效项,我可以按计数对结果进行排序?

你可以试试:

http://localhost:8983/solr/your_core/select?facet.field=field1&facet.sort=count&facet.limit=-1&facet=on&indent=on&q=*:*&rows=0&start=0&wt=json

结果将是这样的:

{
  "responseHeader":{
    "status":0,
    "QTime":17,
    "params":{
      "q":"*:*",
      "facet.field":"field1",
      "indent":"on",
      "start":"0",
      "rows":"0",
      "facet":"on",
      "wt":"json"}},
  "response":{"numFound":225364,"start":0,"docs":[]
  },
  "facet_counts":{
    "facet_queries":{},
    "facet_fields":{
      "field1":[
        "x",113550,
        "y",111814]},
    "facet_ranges":{},
    "facet_intervals":{},
    "facet_heatmaps":{}
  }
}

刚刚使用Solr 6.3.0进行了测试。

有关更多信息,您可以检查Solr文档中的相关部分。

如果要同时计算可用构面的数量,则可以使用Solr stats Component(因为字段是数字,字符串或日期类型)。
但是请记住,服务器性能和内存开销问题可能会出现。

运行如下查询:

http://localhost:8983/solr/your_core/select?facet.field=field1&facet.sort=count&facet.limit=10&facet=true&indent=on&q=*:*&rows=0&start=0&wt=json&stats=true&stats.field={!cardinality=true}field1

响应类似于:

{
  "responseHeader":{
    "status":0,
    "QTime":614,
    "params":{
      "facet.limit":"10",
      "q":"*:*",
      "facet.field":"field1",
      "indent":"on",
      "stats":"true",
      "start":"0",
      "rows":"0",
      "facet":"true",
      "wt":"json",
      "facet.sort":"count",
      "stats.field":"{!cardinality=true}field1"}},
  "response":{"numFound":2336315,"start":0,"docs":[]
  },
  "facet_counts":{
    "facet_queries":{},
    "facet_fields":{
      "field1":[
        "Value1",708116,
        "Value2",607088,
        "Value3",493949,
        "Value4",314433,
        "Value5",104478,
        "Value6",41099,
        "Value7",28879,
        "Value8",18767,
        "Value9",9308,
        "Value10",4545]},
    "facet_ranges":{},
    "facet_intervals":{},
    "facet_heatmaps":{}},
  "stats":{
    "stats_fields":{
      "field1":{
        "cardinality":27}}}}

有关stats信息的更多信息,请点击此处

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM