我们可以在solr结果结构中有多个实体

时间:2011-03-10 06:47:04

标签: java javascript json solr

目前我的solr结果是

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

我希望我的结果集看起来像这样

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

下面列出的类别和区域是搜索结果中找到的所有类别的联合,与区域类似。

1 个答案:

答案 0 :(得分:1)

solr索引格式为“flat”。这意味着,如果不对数据进行严格的非规范化,您就无法轻松地对父/子或其他分层信息进行建模。 虽然没有内置的方法来检索您描述的格式的文档,但是有几种解决方案可以解决问题。哪种解决方案最适合您取决于您​​的具体要求。

如果您只需要在GUI中显示子元素,则只需将所有信息作为JSON或连接字符串(see this mailing list post)存储在单个字段中。

如果您需要查询子元素,您可以使用以下前缀索引类别和区域信息:

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

然后,您的结果处理程序可以将信息转换回嵌套的实体模型。