如果您在 BillNo 上有一个范围索引,那么您可以使用 cts:values() 获取不同的 BillingNo 值列表,并使用 cts:frequency() 过滤多次出现的值:
for $value in cts:values(cts:element-reference(xs:QName("BillNo")))
where cts:frequency($value) gt 1
return $value
如果您想列出具有相同 BillingNo 的文档的 URI,那么您可以将 cts:element-value-co-occurrences 用于 BillingNo 和 xdmp:document。如果您使用map 选项将结果作为映射返回,其中BillingNo 作为键,文档URI 作为值,您可以删除只有一个对应URI 的条目,并且然后会有一个地图,其中列出了多个文档中使用的BillingNo 及其 URI。
let $co-occurrences := cts:element-value-co-occurrences(xs:QName("BillNo"), xs:QName("xdmp:document"), "map")
let $_remove_entries_with_only_one_uri :=
for $key in map:keys($co-occurrences)
where map:get($co-occurrences, $key) => tail()
return map:put($co-occurrences, $key, ())
return
$co-occurrences
如果您没有索引,那么您可能可以执行这样的操作,但会冒扩展树缓存错误的风险:
let $dups := map:new()
let $_ :=
for $value in /BillData/BillNo/string()
return map:put($dups, $value, head((map:get($dups, $value), 0)) + 1)
let $values-by-count := -$dups
let $_remove_entries_with_only_one_uri:= map:put($values-by-count, "1", ())
return
(: flip the map back to values as keys, get BillingNo that have occurred multiple times :)
map:keys(-$values-by-count)