MarkLogic - 在不使用 Xpath 的情况下获得不同的结果集

MarkLogic - Get distinct result set without using Xpath

我正在使用下面提到的查询从存储在 MarkLogic 集合中的 XML 文件中获取不同的值。集合包含超过 40k 个文件。

执行查询时需要很长时间才能得到结果。有没有更好的方法来优化以下查询或任何其他选项以在没有 XPath 的情况下使用此查询。

Xquery:

fn:distinct-values(fn:collection(collectionName)//caseml/case[@jur eq in]/@year)

输入XML例子:

<?xml version="1.0" encoding="UTF-8"?>
<caseml>
  <case jur="in" series="mlj" volume="1" year="2016" startpage="129">
    <p num="y" pnum="22">
      <text>
        In view of the aforesaid discussion, we find the writ petition completely devoid
        of any merit and accordingly, we dismiss the same, leaving the parties to bear their
        own costs.
      </text>
    </p>
  </case>
</caseml>

上面的 XQuery 工作正常,但需要更快地获得结果。

为了在大量文档中快速检索原子值,您需要配置一个 范围索引 ,它指示 MarkLogic 在索引时提取值并将它们保存在内存中-驻留数据结构,因此无需接触磁盘即可访问它们。由于您需要特定路径的值,因此您需要配置 路径范围索引 。重建索引后,您可以使用 cts:values 检索值。您可以选择将 cts:query 传递给调用以将内容限制为符合某些条件的文档。