开发者

Can we have multiple entity in solr result structure

currently my result of solr is

{
 "responseHeader":{
  "status":0,
  "QTime":0,
  "params":{
    "indent":"on",
    "start":"0",
    "q":"deepak\r\n",
    "wt":"json",
    "rows":"10",
    "version":"2.2"}},
 "response":{"numFound":1,"start":0,"docs":[
    {
     "summary":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vel porta odio. Maecenas ligula erat, ullamcorper ut iaculis non, vulputate vel velit. Cras facilisis, lectus a cursus accumsan, nunc libero aliquam magna, eu porta nulla risus quis nisi.",
     "id":"1",
     "text":"Indian Cellular Market Report and Forcasts 2010 - 2015",
     "price":1225.0,
     "pages":"1",
     "release_date":"2011-03-03T00:00:00Z",
     "product_type":"Report",
     "publisher":"deepak upadhyay",
     "regionText":[
      "Asia"],
     "catagoryId":["2","3"],
     "catagoryText":[
      "Banking & finance",
      "ATM"],
     "regionId":["1"]}]
 }}

i want my result set should look like this

{
 "responseHeader":{
  "status":0,
  "QTime":0,
  "params":{
    "indent":"on",
    "start":"0",
    "q":"deepak\r\n",
    "wt":"json",
    "rows":"10",
    "version":"2.2"}},
 "response":{"numFound":1,"start":0,"docs":[
    {
     "summary":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vel porta odio. Maecenas ligula erat, ullamcorper ut iaculis non, vulputate vel velit. Cras facilisis, lectus a cursus accumsan, nunc libero aliquam magna, eu porta nulla risus quis nisi.",
     "id":"1",
     "text":"Indian Cellular Market Report and Forcasts 2010 - 开发者_JAVA百科2015",
     "price":1225.0,
     "pages":"1",
     "release_date":"2011-03-03T00:00:00Z",
     "product_type":"Report",
     "publisher":"deepak upadhyay",
     "regionText":[
      "Asia"],
     "catagoryId":["2","3"],
     "catagoryText":[
      "Banking & finance",
      "ATM"],
     "regionId":["1"]}]
 }
    "categories": [
        {
            "text": "the newly launched..",
            "link": "#",
            "id": "12"
        },
        {
            "text": "the newly launched..",
            "link": "#",
            "id": "13"
        }
    ],
    "region": [
        {
            "text": "the newly launched..",
            "link": "#",
            "id": "14"
        },
        {
            "text": "the newly launched..",
            "link": "#",
            "id": "15"
        }
    ]
}

Hhere the categories and regions listed below is a union of all the categories found in search result, similarly with the regions.


The solr index format is "flat". That means you can not easily model parent/child or other hierarchical information without heavily denormalizing your data. Although there is no built-in way to retrieve documents in the format you described, there are several solutions to the problem. Which solution is best for you depends on your concrete requirements.

If you just need the child elements for displaying in a GUI you can simply store all information in a single field as JSON or as a concatenated string (see this mailing list post).

If you need to query the child elements you could for instance index category and region information with prefixes like this:

 "catagoryId":["cat1_2","cat2_3"],
 "catagoryText":["cat1_Banking & finance", "cat2_ATM"],

Your result handler could then transform the information back into a nested entity model.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜