MarkLogic-XQuery-使用可变长度序列或映射的cts:element-range-query [英] MarkLogic - XQuery - cts:element-range-query using variable length sequence or map
问题描述
我收集了100,000条这样的记录:
I have a collection of 100,000 records structured like this:
<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>
我已在ID上设置了范围索引.
I have setup a range index on id.
我想在XQuery中编写一个查询,使我可以传递可变长度的序列或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.
必须能够让我传递任意数量的ID.另外,它还需要利用范围索引(就像在快速中一样).
It needs to be such that I can pass in any number of id's. Also, it needs to take advantage of the range index (as in fast).
推荐答案
CTS搜索是您的朋友.他们将使用您的索引.
CTS搜索有几种不同的选择.我的第一个想法是尝试这样的事情:
CTS searches are your friend. They will use your indexes.
You have a few different options with your CTS search. 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 :)
文档显示,您可以将序列指定为cts:element-value-query
中的第二个参数,并且您的序列本质上是可变长度的.当您将序列传递到该cts:element-value-query
时,就好像在说"ID == 3 OR ID == 9 OR ID == 13",等等.
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. 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.
http://docs.marklogic.com/7.0/cts:element-值查询
您还可以使用元素范围查询: http://docs.marklogic .com/7.0/cts:element-range-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.
请注意,在上面的代码中,我将id设置为xs:string
.您当然可以将它们作为xs:integer
,但是无论哪种方式,当将它们传递给参数时,它们都将被解析为字符串.
Note that in my code above, I have put the ids as xs:string
s. 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.
这篇关于MarkLogic-XQuery-使用可变长度序列或映射的cts:element-range-query的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!