2013-12-11 39 views
0

我不明白cts:searchcts:element-attribute-values之间的差异。 我可以用这两个函数得到相同的结果。 什么是最好的决心?cts:search和cts:element-attribute-values有什么区别?

cts:search(/t:ancestors-list/t:concept/t:concept-ancestor, cts:element-value-query(xs:QName("t:concept-ancestor"), $concept/id))/@subject 

cts:element-attribute-values(
    xs:QName("t:concept-ancestor"), 
    xs:QName("subject"), 
(), 
    ("collation=http://marklogic.com/collation/codepoint"), 
    cts:element-value-query(
    xs:QName("t:concept-ancestor"), 
    $concept/id 
) 
) 

AR:概念的祖先是元件范围索引和元素属性范围索引。

而且XML结构这样

<t:ancestors-list xmlns:ar="http://test.com"> 
    <t:concept subject="http://test.com/concept#1c5cd7082ac908c62e9176770ae0fb53"> 
     <t:concept-ancestor subject="http://test.com/concept#1c5cd7082ac908c62e9176770ae0fb53">4a1f650290103d39863bf7bc22ef18aa</t:concept-ancestor> 
    </t:concept> 
    <t:concept subject="http://test.com/concept#05b707457f79f42c93bf778915e4a589"> 
     <t:concept-ancestor subject="http://test.com/concept#05b707457f79f42c93bf778915e4a589">4a1f650290103d39863bf7bc22ef18aa</t:concept-ancestor> 
     <t:concept-ancestor subject="http://test.com/concept#05b707457f79f42c93bf778915e4a589">1c5cd7082ac908c62e9176770ae0fb53</t:concept-ancestor> 
    </t:concept> 
    ... 
</t:ancestors-list> 

谢谢!

回答

3

cts:element-attribute-values要求在要查询的值上配置元素属性范围索引,并且它仅返回原子类型(xs:anyAtomicType*)。 cts:search返回文档节点,cts:element-value-query不需要索引。

如果您只需要值(不是XML)并且您已经有索引,那么cts:element-attribute-values查询将会更快。

+1

构面是您可能想要其中一个cts的示例:* - values functions - 来自索引的值列表,可帮助用户浏览。 –

+0

我可能是错的,但根据我的理解,如果有索引,'cts:element-value-query'会更加准确和快速。除此之外,不从数据库中检索节点,而是使用索引值而不是更高性能,并且缩放好得多。 – grtjn

+0

'更准确'我的意思是关于xdmp:estimate .. – grtjn

2

的根本区别在于cts:search返回节点在其内cts:element-value-query是满意的序列,而cts:element-attribute-values函数返回在索引(其中,值进一步通过cts:element-value-query限制中定义的实际属性值的流你传递给函数)。

我能想到的在速度上的差异几个可能的原因,但是这对我来说似乎是关键:

cts:search操作必须加载并回报给你一个序列满足concept:ancestor节点搜索标准。 cts:element-attribute-values函数调用返回

加载和发送序列节点将是更加时间和内存昂贵比给你原子值。一个序列(不管它是节点()还是原子值)在返回给你之前将被完全加载到内存中,而原子值流是延迟加载的,所以它不会(必然)存储所有的值在内存中一次。

(我只是了解了序列/流的区别,并从该MarkLogic社区博客一个刚刚加入后的cts:element-valuescts:element-attribute-values功能:Result Streams from Range Indexes

底线,不过,在之间进行选择wst已经提出了两种方法:

如果您只需要值(不是XML)并且您已经有索引,那么cts:element-attribute-values查询将会更快。