Marklogic 8 使用搜索片段对搜索结果进行分组

标签 marklogic marklogic-8

我有一个用例,其中有一个父文档和父文档的一些子文档。当我搜索时,我希望始终返回父文档。假设一个搜索结果命中了 2 个具有相同父文档的子文档,则需要将结果分组到一个搜索结果中,其中的片段来自子文档。我也想应用分页,但分页应该在转换后的搜索结果上。这可能吗?父子关系是属性 <parent-document-location>在子文档上

Parent Document Properties

<?xml version="1.0" encoding="UTF-8"?>
<prop:properties xmlns:prop="http://marklogic.com/xdmp/property">
  <id xmlns="http://ir.abbivenet.com/content-repo/metadata">1e900d1a7210350c0b68973fb0d6dc96f83e161a</id>
  <cpf:processing-status xmlns:cpf="http://marklogic.com/cpf">done</cpf:processing-status>
  <cpf:property-hash xmlns:cpf="http://marklogic.com/cpf">34d0a49cf8835387f6bd213a31732ad4</cpf:property-hash>
  <cpf:last-updated xmlns:cpf="http://marklogic.com/cpf">2016-03-15T21:18:20.521372Z</cpf:last-updated>
  <cpf:state xmlns:cpf="http://marklogic.com/cpf">http://marklogic.com/states/done</cpf:state>
  <cpf:self xmlns:cpf="http://marklogic.com/cpf">/documents/BioEln/1e900d1a7210350c0b68973fb0d6dc96f83e161a.xml</cpf:self>
  <prop:last-modified>2016-03-15T21:50:38Z</prop:last-modified>
</prop:properties>

Child Document 1

<?xml  version="1.0" encoding="UTF-8"?>
<prop:properties xmlns:prop="http://marklogic.com/xdmp/property">
<document-parent-location xmlns="http://ir.abbivenet.com/content-repo/metadata">/documents/BioEln/1e900d1a7210350c0b68973fb0d6dc96f83e161a.xml</document-parent-location>
<context xmlns="http://ir.abbivenet.com/content-repo/metadata">BioEln</context>
<id xmlns="http://ir.abbivenet.com/content-repo/metadata">1e900d1a7210350c0b68973fb0d6dc96f83e161a</id>
<prop:last-modified>2016-03-15T21:50:34Z</prop:last-modified>
</prop:properties>

Child Document 2

<?xml  version="1.0" encoding="UTF-8"?>
<prop:properties xmlns:prop="http://marklogic.com/xdmp/property">
<document-parent-location xmlns="http://ir.abbivenet.com/content-repo/metadata">/documents/BioEln/1e900d1a7210350c0b68973fb0d6dc96f83e161a.xml</document-parent-location>
<context xmlns="http://ir.abbivenet.com/content-repo/metadata">BioEln</context>
<id xmlns="http://ir.abbivenet.com/content-repo/metadata">1e900d1a7210350c0b68973fb0d6dc96f83e161a</id>
<prop:last-modified>2016-03-15T21:50:34Z</prop:last-modified>
</prop:properties>

最佳答案

如果您想在子文档中进行搜索并且只返回每个父文档的结果/片段,那么理想的解决方案可能是在摄取期间将父文档和子文档合并到单个文档中。通过这种方式对数据进行建模,您可以编写查询来搜索子文档数据,然后可以在代码段生成期间转换父文档结果。

任何将这些数据保存在单独文档中的解决方案都需要在运行时“连接”数据并在每页选择更多结果以促进父文档的重复数据删除。与“非规范化”的单个文档相比,每一个都会导致性能损失,并且可能会使实现更加复杂。

关于Marklogic 8 使用搜索片段对搜索结果进行分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36089265/

相关文章:

marklogic - 是否可以从另一个数据库导入模块?

marklogic - 如何使用 MarkLogic API 在 MarkLogic 集群中添加多个引导主机?

xquery - 查询生成 'XDMP-CHILDNODEKIND: $final -- element nodes cannot have binary node children'错误

gradle - 使用ML-Gradle禁用/暂停数据库复制

marklogic - 如何使用 mlcp 加载许多 (100K+) XML 文档而不会遇到 "argument list too long"错误?

node.js - NodeJS 集合中的 Marklogic QueryByExample

eclipse-plugin - XQDT : where did Marklogic option go?

用于安排和删除任务的 Marklogic 管理 API

xquery - 在marklogic 8中对多个 map 进行排序

marklogic - Marklogic 中的分页