如何从solr读取嵌套结构?

时间:2016-11-18 16:18:59

标签: solr

我迷路了,需要你的建议。我有一个包含多级子文档的嵌套Solr文档。这是一个JSON示例,因此您可以看到完整的结构:

{
  "id": "Test Library",
  "description": "example of nested document",
  "content_type": "library",
  "authors": [{
      "id": "author1",
      "content_type": "author",
      "name": "First Author",
      "books": [{
         "id": "book1",
         "content_type": "book",
         "title": "title of book 1"
      }],
      "shortStories": [{
         "id": "shortStory1",
         "content_type": "shortStory",
         "title": "title of short story 1"
      }]
      },
      {
      "id": "author2",
      "content_type": "author",
      "name": "Second Author",
      "books": [{
         "id": "book1",
         "content_type": "book",
         "title": "title of book 1"
          }],
      "shortStories": [{
          "id": "shortStory1",
          "content_type": "shortStory",
          "title": "title of short story 1"
       }]
    }]
}

我想查询文档并检索嵌套结构。我尝试使用ChildDocumentTranformerFactory,但它将结果展平为Library和所有其他文档作为子项:

{
  "id": "Test Library",
  "description": "example of nested document",
  "content_type": "library",
  "_childDocuments_":[
      {"id": "author1",
      "content_type": "author",
      "name": "First Author"
      },
      {"id": "book1",
      "content_type": "book",
      "title": "title of book 1"
      },
      {
       "id": "shortStory1",
       "content_type": "shortStory",
       "title": "title of short story 1"
       },
     {
     "id": "author2",
     "content_type": "author",
     "name": "Second Author"
     },
    {
     "id": "book1",
     "content_type": "book",
     "title": "title of book 1"
     },
     {
     "id": "shortStory1",
     "content_type": "shortStory",
     "title": "title of short story 1"
     }
   ]
}

以下是我使用的查询参数:

q={!parent which='content_type:library'}
df=id
fl=*,[child parentFilter='content_type:library' childFilter='id:*']
wt=json
indent=true

从Solr读取嵌套结构的最佳方法是什么?我需要做某种刻面吗?

我正在使用Solr版本5.2.1

2 个答案:

答案 0 :(得分:0)

不幸的是,solr现在不支持。

  

ChildDocTransformerFactory在嵌套在匹配的父文档中的平面列表中返回与您的查询匹配的每个父文档的所有后代文档

不确定是否有解决方法。

答案 1 :(得分:0)

请查看Block Join以虚拟关联父母和孩子。

https://github.com/lucidworks/solrj-nested-docs