Marklogic - What is the best way to loop throught 10 thousand documents if you know id

时间:2017-06-19 13:53:09

标签: marklogic

I have a list more than ten thousand ids need to retrieve XML data if they are matched. What is a best solution to approach this. I think my code is not the right way to loop through a $listKeyID. Please help. Thanks in advance.

let $listKeyID := ("accid01","accid02",......"accid100000") (: a huge list :)
let $uris := cts:uris((),
                      (),
                     cts:and-query((                          
                           cts:collection-query("/collection/TRIS"),
                           cts:or-query((
                           cts:field-word-query("key",($listKeyID))
                           ))
                     ))
                 )
             )
 return fn:count($uris)

1 个答案:

答案 0 :(得分:0)

实际上,这种方法并没有太大的错误。 cts:field-word-query接受一个序列作为第二个参数,并且对于该序列中的任何匹配将返回正数。我们也将它称为鸟枪式OR查询,效率非常高。

你实际上并不需要额外的cts:or-query,你可能想要使用cts:field-value-query代替整个键值,而不是句子中间代,取决于你的用例。

let $listKeyIDs := (accid01,accid02,......accid100000) (: a huge list :)
let $uris := cts:uris(
    (),
    (),
    cts:and-query((
        cts:collection-query("/collection/TRIS"),
        cts:field-value-query("key", $listKeyIDs)
    ))
)
return fn:count($uris)

HTH!