2016-11-18 101 views
2

我迷路了,需要你的建議。我有一個包含多級子文檔的嵌套Solr文檔。這裏是一個JSON例子,所以你可以看到完整的結構:如何從solr讀取嵌套結構?

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

回答

0

不幸的是Solr的不支持現在。

ChildDocTransformerFactory回報嵌套匹配父文檔

不知道是否有一個變通的這裏面一個平面列表符合查詢條件的每個父文件的所有後代文件。