【发布时间】:2020-05-17 02:14:42
【问题描述】:
在索引我的数据时,我发现一些嵌套文档没有正确存储。我运行 Solr 8.3 并使用 标记的关系 作为described in the docs。
数据
只要根实体Parent 具有任意数量的Child 实体,我就会生成以下PHP 数组:
[
'id' => 'b14ac9a0-e255-468b-a673-e125fd73d6f2',
'entity_type' => 'parent',
'title_t' => 'Andrea Cook',
'children' => [
0 => [
'id' => 'ce10380c-8006-4945-9078-296116ad5ab7',
'entity_type' => 'child',
'title_t' => 'Jordan Gibson',
],
1 => [
'id' => '0c191119-fae9-452e-aca2-b724a381f939',
'entity_type' => 'child',
'title_t' => 'Jane Gordon',
],
]
]
然后将其编码为以下 JSON 对象:
{
"id": "b14ac9a0-e255-468b-a673-e125fd73d6f2",
"entity_type": "parent",
"title_t": "Andrea Cook",
"children": [
{
"id": "ce10380c-8006-4945-9078-296116ad5ab7",
"entity_type": "child",
"title_t": "Jordan Gibson"
},
{
"id": "0c191119-fae9-452e-aca2-b724a381f939",
"entity_type": "child",
"title_t": "Jane Gordon"
}
]
}
这正是 solr 查询返回的内容(加上自动生成的值 __root__、__nest_path__ 等)。
问题
只要Parent 只有一个Child,它们最终会成为 solr 中的一个对象,而不是包含单个对象的数组。
预期的搜索结果
{
"id": "b14ac9a0-e255-468b-a673-e125fd73d6f2",
"entity_type": "parent",
"title_t": "Andrea Cook",
"children": [
{
"id": "ce10380c-8006-4945-9078-296116ad5ab7",
"entity_type": "child",
"title_t": "Jordan Gibson"
}
]
}
真实搜索结果
{
"id": "b14ac9a0-e255-468b-a673-e125fd73d6f2",
"entity_type": "parent",
"title_t": "Andrea Cook",
"children": {
"id": "ce10380c-8006-4945-9078-296116ad5ab7",
"entity_type": "child",
"title_t": "Jordan Gibson"
}
}
断言
我已确保 php 数组和 JSON 对象的格式正确,直到它们被传递到 HTTP 客户端。
我已确保 children 数组的数组键编号并从 0 开始。
问题
这是预期的行为吗?
我是否必须为标记的关系创建一个 <fieldType/>(即创建一个多值 children 字段)?如果是,那我该怎么做?我还没有找到任何解释。
如何在搜索结果中始终获得children 的数组,这样我就不必在迭代之前检查数据?
【问题讨论】:
标签: solr nested-documents