开发者

Solr Mulivalued Problem

Consider The following is the json response i'm getting from the solr if i use multivalued = true for the fields.

  {
    "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

more than one level then only the problem arises. right now i'm putting the entire response here to make it clear.

{
 "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开发者_StackOverflow.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":{}}}

look at the mediaId , mediatype ,ansTS arrays. Its one to many relationship.But they are grouped by column names.Thanks in advance.


You mentioned that you will consume this JSON from a browser. So you can use jQuery or any other javascript library to convert the raw Solr JSON response into the structure that you need.


If the first snippet is the actual solr response you're getting, then chances are you have a bug in your feeder (connector/crawler/etc). It looks like you only have one indexed document (that matches your query), which has all the values that you expect from 3 documents.

Assuming you have 3 documents, analogous with your expected output, then the actual solr wt=json result would contain:

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

If this assumption is correct, then I would suggest looking over your indexing logic.


This output is produced by Solr's JSONResponseWriter. Its output can't be altered via configuration. But what you can do is create your own version of JSONResponseWriter to produce your desired output. You can registered your new ResponseWriter by adding a queryResponseWriter tag in solrconfig.xml.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜