1

我在 solr 中使用多核搜索,结果未混合,为了对结果进行分类,我需要从响应中获取 corename,请考虑以下响应

{
  "responseHeader": {
    "status": 0,
    "QTime": 0,
    "params": {
      "fl": "title,core_name",
      "indent": "true",
      "q": "*:*",
      "_": "1383405269434",
      "wt": "json",
      "rows": "2"
    }
  },
  "response": {
    "numFound": 926,
    "start": 0,
    "docs": [
      {
        "title": "Main Page"
      },
      {
        "title": "Albert Einstein"
      }
    ]
  }
}

如果我给一个参数说 core_name 它应该在每个结果条目中返回核心名称,即

{
  "responseHeader": {
    "status": 0,
    "QTime": 0,
    "params": {
      "fl": "title,core_name",
      "indent": "true",
      "q": "*:*",
      "_": "1383405269434",
      "wt": "json",
      "rows": "2"
    }
  },
  "response": {
    "numFound": 926,
    "start": 0,
    "docs": [
      {
        "title": "Main Page"
        "core_name": "collection1"
      },
      {
        "title": "Albert Einstein"
        "core_name": "collection1"
      }
    ]
  }
}

是否有任何 solr 变量来获取核心名称?

4

1 回答 1

3

当您使用分片时,您可以将 DocTransformer 添加[shard]为参数中的查询字段fl。shard 周围的括号是强制性的,也会出现在响应中。此 DocTransformer 仅在存在 shards 参数时才有效。

为此,您需要像这样更改您的查询

localhost:8983/solr/collection1/select?shards=localhost:8983/solr/collection3,lo‌​calhost:8983/solr/collection2,localhost:8983/solr/collection1&q=*:*&wt=json&‌​fl=title,[shard]

这会让你得到这样的回应

{
  "responseHeader": {
    "status": 0,
    "QTime": 0,
    "params": {
      "fl": "title,[shard]",
      "indent": "true",
      "q": "*:*",
      "_": "1383405269434",
      "wt": "json",
      "rows": "2"
    }
  },
  "response": {
    "numFound": 926,
    "start": 0,
    "docs": [
      {
        "title": "Main Page"
        "[shard]": "localhost:8983/solr/collection1"
      },
      {
        "title": "Albert Einstein"
        "[shard]": "localhost:8983/solr/collection1"
      }
    ]
  }
}

进一步阅读

于 2013-11-04T21:57:47.610 回答