带有子元素的Solr文档? [英] Solr documents with child elements?

查看:220
本文介绍了带有子元素的Solr文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以创建包含子元素的Solr文档?

Is it somehow possible to create a solr document that contains sub-elements?

例如,我将如何表示这样的东西:

For example, how would I represent something like this:

<person first="Bob" last="Smith">
   <children>
      <child first="Little" last="Smith" />
      <child first="Junior" last="Smith" />
   </children>
</person>

解决此问题的常用方法是什么?

What is the usual way to solve this problem?

推荐答案

您可以根据搜索/构面的需要,以不同的方式对此进行建模.通常,您将使用多值或动态字段.在下面的示例中,我将省略字段类型,索引和存储的标志:

You can model this in different ways, depending on your searching/faceting needs. Usually you'll use multivalued or dynamic fields. In the next examples I'll omit the field type, indexed and stored flags:

<field name="first"/>
<field name="last"/>
<field name="child_first" multiValued="true"/>
<field name="child_last" multiValued="true"/>

由您决定将孩子的名字和姓氏相关联.或者,您可以将两者都放在一个字段中:

It's up to you to correlate the children first names and last names. Or you could just put both in a single field:

<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"等.再次取决于您要关联的值,但至少要有一个索引.使用一些代码,您可以使此操作透明化.

Here you would store fields 'child_first_1', 'child_last_1', 'child_first_2', 'child_last_2', etc. Again it's up to you to correlate values, but at least you have an index. With some code you could make this transparent.

底线:正如 Solr Wiki 所说:"Solr提供了一张表.存储一组索引中的数据库表通常需要对某些表进行规范化.为避免进行规范化的尝试通常会失败."您可以根据自己的搜索需求对数据进行非规范化.

Bottom line: as the Solr wiki says: "Solr provides one table. Storing a set database tables in an index generally requires denormalizing some of the tables. Attempts to avoid denormalizing usually fail." It's up to you to denormalize your data according to your search needs.

更新:自4.5左右版本以来,Solr直接支持嵌套文档: https://cwiki.apache.org/confluence/display/solr/Other+Parsers#OtherParsers-BlockJoinQueryParsers

UPDATE: Since version 4.5 or so Solr supports nested documents directly: https://cwiki.apache.org/confluence/display/solr/Other+Parsers#OtherParsers-BlockJoinQueryParsers

这篇关于带有子元素的Solr文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆