English 中文(简体)
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.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.





相关问题
JQuery/MVC Search Issue

I have inherited a piece of work where the entry screen shows a summary of 20 calculated variables. E.g. Var A (250), Var B (79). Clicking on any of these links takes the user to a view with a ...

jQuery quicksearch plug-in tinkering with JSON

I ve implemented the quicksearch plugin by Rik Lomas and I love it for an application in a custom CMS I m building. I was wondering though, since I m going to have a bizillion items in the table if ...

JSON with classes?

Is there a standardized way to store classes in JSON, and then converting them back into classes again from a string? For example, I might have an array of objects of type Questions. I d like to ...

PHP json_decode question

i m trying to use json_decode to combine a few json objects and then re-encode it. my json looks like: { "core": { "segment": [ { "id": 7, "...

Converting JSON data to Java object

I want to be able to access properties from a JSON string within my Java action method. The string is available by simply saying myJsonString = object.getJson(). Below is an example of what the string ...

热门标签