cam*_*mbo 20 solr document nested structure
是否有可能创建包含子元素的solr文档?
例如,我将如何表示这样的事情:
<person first="Bob" last="Smith">
<children>
<child first="Little" last="Smith" />
<child first="Junior" last="Smith" />
</children>
</person>
Run Code Online (Sandbox Code Playgroud)
解决这个问题的常用方法是什么?
who*_*mer 21
从Solr 4.7和4.8开始,Solr支持嵌套文档:
{
"id": "chapter1",
"title" : "Indexing Child Documents in JSON",
"content_type": "chapter",
"_childDocuments_": [
{
"id": "1-1",
"content_type": "page",
"text": "ho hum... this is page 1 of chapter 1"
},
{
"id": "1-2",
"content_type": "page",
"text": "more text... this is page 2 of chapter 1"
}
]
}
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请参阅Solr发行说明.
Mau*_*fer 13
您可以根据您的搜索/分面需求以不同方式对此进行建模.通常,您将使用多值或动态字段.在下面的例子中,我将省略字段类型,索引和存储的标志:
<field name="first"/>
<field name="last"/>
<field name="child_first" multiValued="true"/>
<field name="child_last" multiValued="true"/>
Run Code Online (Sandbox Code Playgroud)
由您来关联孩子的名字和姓氏.或者你可以把它们放在一个字段中:
<field name="first"/>
<field name="last"/>
<field name="child_first_and_last" multiValued="true"/>
Run Code Online (Sandbox Code Playgroud)
另一个:
<field name="first"/>
<field name="last"/>
<dynamicField name="child_first_*"/>
<dynamicField name="child_last_*"/>
Run Code Online (Sandbox Code Playgroud)
在这里,您将存储字段'child_first_1','child_last_1','child_first_2','child_last_2'等.再次由您来关联值,但至少您有一个索引.使用一些代码,您可以使其透明.
底线:正如Solr wiki所说:"Solr提供了一个表.在索引中存储集合数据库表通常需要对某些表进行非规范化.尝试避免非规范化通常会失败." 您可以根据自己的搜索需求对数据进行反规范化.
更新:从版本4.5开始,Solr直接支持嵌套文档:https://cwiki.apache.org/confluence/display/solr/Other+Parsers#OtherParsers-BlockJoinQueryParsers
为儿童设置单独的字段会导致误报.连接字段在某种意义上起作用,但它确实是有限的方法.我们在http://blog.griddynamics.com/2011/06/solr-experience-search-parent-child.html上发布的类似任务中有很多经验.
| 归档时间: |
|
| 查看次数: |
29395 次 |
| 最近记录: |