是否有可能创建一个包含子元素的solr文档?含有子元素的Solr文档?
例如,我会如何表现是这样的:
<person first="Bob" last="Smith">
<children>
<child first="Little" last="Smith" />
<child first="Junior" last="Smith" />
</children>
</person>
什么是解决这个问题的常用方法?
是否有可能创建一个包含子元素的solr文档?含有子元素的Solr文档?
例如,我会如何表现是这样的:
<person first="Bob" last="Smith">
<children>
<child first="Little" last="Smith" />
<child first="Junior" last="Smith" />
</children>
</person>
什么是解决这个问题的常用方法?
您可以使用不同的方式对其进行建模,具体取决于您的搜索/刻面需求。通常你会使用多值域或动态域。在下面的例子,我会忽略的字段类型,索引和存储标志:
<field name="first"/>
<field name="last"/>
<field name="child_first" multiValued="true"/>
<field name="child_last" multiValued="true"/>
这是给你孩子的名字和姓氏有关。或者你可以把无论是在单场:
<field name="first"/>
<field name="last"/>
<field name="child_first_and_last" multiValued="true"/>
还有一句:
<field name="first"/>
<field name="last"/>
<dynamicField name="child_first_*"/>
<dynamicField name="child_last_*"/>
在这里,您将存储领域 '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
哇。我在两年前回答了这个问题。现在我改变了主意。第一台机器在http://blog.mikemccandless.com/2012/01/searching-relational-content-with.html上有描述,它只是提供给Solr https://issues.apache.org/jira/browse/ SOLR-3076将于4.5发布。并顺便说一句,它支持#ElasticSearch非常长的时间 – mkhludnev 2013-08-30 21:01:53
博客作为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"
}
]
}
链接已损坏。你能更新吗? – elachell 2016-06-17 10:37:23
如何在干草堆中使用这种结构? – 2017-08-18 13:13:18
谢谢Mauricio。选项#1和#2并不真正有用,因为这样就不可能提取单个字段,特别是如果有两个以上的字段。您的第三个建议可能会正常工作,使用动态字段。我将使用DataImportHandler的哪些机制来生成这些动态字段? – cambo 2011-04-11 02:46:09
@ user332523:如果仅限于使用DataImportHandler,则可能不可能,但如果您在自己的编码过程中导入,则很容易。 – 2011-04-11 03:00:34
嗨Mauricio,谢谢你的回复。你只是指使用Solr API将文档添加到索引的自定义数据导入器吗?我在Solr DIH文档中看过一些可以创建动态字段的内容[http://wiki.apache.org/solr/DataImportHandler#TemplateTransformer] – cambo 2011-04-19 04:15:55