【问题标题】:Solr Nested Document w/ Field Labelled Relationship: Single Elements Not Stored In Arrays具有字段标签关系的 Solr 嵌套文档:未存储在数组中的单个元素
【发布时间】: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 的数组,这样我就不必在迭代之前检查数据?


uuidgenerator.net, uinames.com

【问题讨论】:

    标签: solr nested-documents


    【解决方案1】:

    我终于想到,我用 PHP 编写的数组操作(array_maparray_merge、...)正在创建带有奇怪索引的数组。

    为了解决这个问题,我不得不调用array_values,它会创建原始的零索引数组。

    【讨论】:

      【解决方案2】:

      从我的updateRequestProcessorChain in solrconfig.xml 中删除"solr.TrimFieldUpdateProcessorFactory" 为我解决了这个问题。 (Solr 8.8.1)

      【讨论】:

      • 请提供更多详细信息如何解决问题。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多