且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

带有子元素的 Solr 文档?

更新时间:2022-11-14 08:52:52

您可以用不同的方式对此进行建模,具体取决于您的搜索/分面需求.通常您会使用多值或动态字段.在接下来的示例中,我将省略字段类型、索引和存储标志:

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