如何通过在Marklogic中动态排序或下降?
let $sortelement := 'Salary'
let $sortby := 'ascending'
for $doc in collection('employee')
order by $doc/*[local-name() eq $sortelement] $sortby
return $doc
此代码抛出和错误,做到这一点的正确方法是什么?
let $sortelement := 'Salary'
let $sortby := 'ascending'
for $doc in collection('employee')
order by $doc/*[local-name() eq $sortelement] $sortby
return $doc
This code throws and error, what is the correct way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您只是想在Flwor语句中动态地构建
订单,则不能。正如迈克尔·凯(Michael Kay)在评论中指出的那样,您可以使用有条件的语句,并决定是否
reververs()
上升
(默认)排序序列。根据您的收藏中有多少个文档,检索每个文档并对其进行排序不会扩展。它可能需要很长时间,并且可以超过扩展的树缓存的内存限制。
如果您在这些元素上有索引,则可以动态构建a
cts:index-order ()
并将其指定为cts:search()
的第三个参数,以便以指定顺序返回它们:If you are just looking to build the
order by
dynamically within a FLWOR statement, you can't. As Michael Kay points out in the comments, you could use a conditional statement and decide whether or not toreverse()
theascending
(default) sorted sequence.Depending upon how many documents are in your collection, retrieving every document and sorting them won't scale. It can take a long time, and can exceed memory limits for expanded tree cache.
If you have indexes on those elements, then you can dynamically build a
cts:index-order()
and specify as the third parameter forcts:search()
in order to get them returned in the specified order: