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

查看:27
本文介绍了带有子元素的 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天全站免登陆