1

考虑以下是我从 solr获得的 json 响应, 如果我对字段使用multivalued = true

  {
    "id":["1","2","3"],
    "TS":["2010-06-28 00:00:00.0","2010-06-28 00:00:00.0","2010-06-28 00:00:00.0"],
    "Type":["VIDEO","IMAGE","VIDEO"]
    }

but i need the response like this

    {
    "0":["1","2010-06-28 00:00:00.0","VIDEO"],
    "1":["2","2010-06-28 00:00:00.0","IMAGE"],
    "2":["3","2010-06-28 00:00:00.0","VIDEO"]
    }

How can i get this.Any help would be appreciated. Thanks in advance.
 **Update :**
    Actually at the first level its not a problem. When we are going

不止一个级别,那么只会出现问题。现在,我将整个回复放在这里以说明清楚。

{
 "responseHeader":{
  "status":0,
  "QTime":0,
  "params":{
    "facet":"true",
    "indent":"on",
    "start":"0",
    "q":"laptop",
    "wt":["json",
     "json"],
    "rows":"200"}},
 "response":{"numFound":1,"start":0,"docs":[


    {
     "createdBy":"0",
     "id":194,
     "status":"ACTIVE",
     "text":"Can i buy Sony laptop?",
     "ansTS":["2010-07-01 00:00:00.0","2010-08-06 15:11:55.0","2010-08-11 15:28:13.0","2010-08-11 15:30:49.0","2010-08-12 01:45:48.0","2010-08-12 01:46:18.0"],
     "mediaType":["VIDEO","VIDEO","VIDEO"],
     "ansId":["59","76","77","78","80","81"],
     "mediaId":[24,25,26],

       ]},
    ]
 },
 "facet_counts":{
  "facet_queries":{},
  "facet_fields":{
    "catName":[]},
  "facet_dates":{}}}

查看 mediaId 、 mediatype 、ansTS 数组。它是一对多的关系。但它们按列名分组。提前致谢。

4

3 回答 3

2

您提到您将从浏览器中使用此 JSON。因此,您可以使用 jQuery 或任何其他 javascript 库将原始 Solr JSON 响应转换为您需要的结构。

于 2010-08-25T14:30:29.850 回答
0

如果第一个片段是您得到的实际 solr 响应,那么您的馈线(连接器/爬虫/等)中可能存在错误。看起来您只有一个索引文档(与您的查询匹配),其中包含您期望从 3 个文档中获得的所有值。

假设您有 3 个文档,与您的预期输出类似,那么实际的 solrwt=json结果将包含:

[{ 
"id":"1", 
"TS":"2010-06-28 00:00:00.0", 
"Type":"VIDEO"
},

{
"id":"2",
"TS":"2010-06-28 00:00:00.0",
"Type":"IMAGE"
},
{
"id":"3",
"TS":"2010-06-28 00:00:00.0",
"Type":"VIDEO"
}]

如果这个假设是正确的,那么我建议查看您的索引逻辑。

于 2010-08-25T12:15:48.533 回答
0

此输出由 Solr 的 JSONResponseWriter 生成。它的输出不能通过配置改变。但是你可以做的是创建你自己的 JSONResponseWriter 版本来产生你想要的输出。您可以通过在 solrconfig.xml 中添加 queryResponseWriter 标记来注册新的 ResponseWriter 。

于 2010-08-25T12:47:47.347 回答