Can we have multiple entity in solr result structure

Deadly 提交于 2019-12-25 01:43:32

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/5256389/can-we-have-multiple-entity-in-solr-result-structure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!