【问题标题】:How do I read a nested structure from solr?如何从 solr 读取嵌套结构?
【发布时间】:2016-11-21 00:20:44
【问题描述】:

我迷路了,需要你的建议。我有一个嵌套的 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 但它将结果展平为只是图书馆和所有其他文档作为孩子:

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

【问题讨论】:

    标签: solr


    【解决方案1】:

    很遗憾,solr 目前不支持。

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

    不确定是否有解决方法。

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

      • 你能提供一个创建虚拟关系的例子吗?
      猜你喜欢
      • 1970-01-01
      • 2021-06-13
      • 2021-09-18
      • 1970-01-01
      • 1970-01-01
      • 2020-12-15
      • 2017-02-06
      • 1970-01-01
      • 2022-11-17
      相关资源
      最近更新 更多