简体   繁体   English

MarkLogic-XQuery-使用可变长度序列或映射的cts:element-range-query

[英]MarkLogic - XQuery - cts:element-range-query using variable length sequence or map

I have a collection of 100,000 records structured like this: 我收集了100,000条记录,其结构如下:

<record>
    <pk>1</pk>
    <id>1234</id>
</record>
<record>
    <pk>2</pk>
    <id>1234</id>
</record>
<record>
    <pk>3</pk>
    <id>5678</id>
</record>
<record>
    <pk>4</pk>
    <id>5678</id>
</record>

I have setup a range index on id. 我在ID上设置了范围索引。

I want to write a query in XQuery that will allow me to pass in a variable length sequence or map of id's and get back out all the records with those id's. 我想在XQuery中编写一个查询,该查询将允许我传递可变长度的序列或ID的映射,并检索出所有具有这些ID的记录。

It needs to be such that I can pass in any number of id's. 它必须能够传递任意数量的ID。 Also, it needs to take advantage of the range index (as in fast). 同样,它需要利用范围索引(如快速)。

CTS searches are your friend. CTS搜索是您的朋友。 They will use your indexes. 他们将使用您的索引。
You have a few different options with your CTS search. CTS搜索有几种不同的选择。 My first thought is to try something like this: 我首先想到的是尝试这样的事情:

let $ids as xs:string* := (1, 2, 4, 5, 6, 33, 35.....89)
let $results as element(record)* := cts:search(/record,
    cts:element-value-query(xs:QName("id"), $ids, ("exact"))
    )
return $results
(: This will return all the record elements with their children :)

The documentation shows that you can specify a sequence as the second parameter in your cts:element-value-query , and your sequence by very nature is variable length. 文档显示,您可以在cts:element-value-query中将序列指定为第二个参数,并且序列的性质就是可变长度。 When your sequence is passed into that cts:element-value-query , it is as if to say "ID==3 OR ID==9 OR ID==13", etc. 当您的序列传递到该cts:element-value-query ,就好像在说“ ID == 3 OR ID == 9 OR ID == 13”,等等。

http://docs.marklogic.com/7.0/cts:element-value-query http://docs.marklogic.com/7.0/cts:element-value-query

You can also use an element range query: http://docs.marklogic.com/7.0/cts:element-range-query , though I'm not as good with those so I can't give you very much help on that. 您还可以使用元素范围查询: http : //docs.marklogic.com/7.0/cts :element-range-query,尽管我对它们的评价不高,所以在此方面我不能给您太多帮助。

Note that in my code above, I have put the ids as xs:string s. 请注意,在上面的代码中,我将id设置为xs:string You can of course have them as xs:integer s, and but either way they will be parsed as strings when passed in the parameter. 您当然可以将它们作为xs:integer ,但是以任何一种方式将它们传入参数时都将被解析为字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM