在查询响应Solr中获取核心名称

时间:2013-11-02 15:17:12

标签: json solr

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

{
  "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变量来获取核心名称?

1 个答案:

答案 0 :(得分:3)

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

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

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"
      }
    ]
  }
}

进一步阅读