views:

65

answers:

3

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.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.

A: 

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.

Karl Johansson
A: 

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.

Pascal Dimassimo
no. that has nothing to do with JSONResponseWriter. Even XML format output also has the same problem.
sathis
Either with XML or JSON, Solr outputs, for all documents, all fields with its associated value (many values in the case of a multi-value). If that is not what you need, you need to have your own ResponseWriter. Now, if this is already the format that you want, and you think that there is a bug in Solr, I suggest first going with scdef's suggestion and make sure your indexation logic is ok.
Pascal Dimassimo
so can i index an entity by referring it in schema.xml ?. if so please show me a example.
sathis
Remember that an entity must be completely de-normalized to work properly in Solr. See this link for some info: http://mysolr.com/tips/denormalized-data-structure/
Pascal Dimassimo
+2  A: 

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.

Mauricio Scheffer
if some values contain null then those values will be discarded by the solr. So it will be very difficult to assume the order.having not nullable columns is not a best solution IMHO.
sathis
@sathis: hmm, then you have a problem in your schema design, which is not related to JSON or how you process it...
Mauricio Scheffer