gpt4 book ai didi

xquery - 从目录中获取文档时按元素排序

转载 作者:行者123 更新时间:2023-12-02 08:58:05 25 4
gpt4 key购买 nike

我必须从目录中获取所有文档,并使用下面的查询来执行相同的操作。现在我需要返回根据 effectiveDate 元素排序的结果。我们可以将 order by 与此代码一起使用

let $news :=xdmp:directory("/news/","1")
for $d in $news
return $d
-- Result -----

<?xml version="1.0" encoding="UTF-8"?>
<NewsEntity xmlns="http://jnj.com/news">
<uuid xmlns="">868e8a3a-058d-4b2d-8d69-0696f75ec97f</uuid>
<headLine>HeadLine 4</headLine>
<contributor>User 4</contributor>
<effectiveDate>2016-08-31</effectiveDate>
</NewsEntity>
<?xml version="1.0" encoding="UTF-8"?>
<NewsEntity xmlns="http://jnj.com/news">
<uuid xmlns="">311eeede-2560-4142-b882-b666ab08c9f8</uuid>
<headLine>HeadLine 3</headLine>
<contributor>User 3</contributor>
<effectiveDate>2016-08-28</effectiveDate>
</NewsEntity>
<?xml version="1.0" encoding="UTF-8"?>
<NewsEntity xmlns="http://jnj.com/news">
<uuid xmlns="">9bb67977-a217-425f-82e4-b4366e80d7c4</uuid>
<headLine>HeadLine 2</headLine>
<contributor>User 2</contributor>
<effectiveDate>2016-08-30</effectiveDate>
</NewsEntity>

最佳答案

如果您希望对结果进行有效排序,则需要在 effectiveDate 上建立一个 date 范围索引。在某些条件下,查询优化器可以使用 order by 子句利用该索引,但使用 cts:index-order 可能更直接。使用 cts:search。像这样的东西:

cts:search(collection(),
cts:directory-query('/news', 1),
cts:index-order(
cts:element-reference(
fn:QName("http://jnj.com/news", "effectiveDate")
"type=date"
)
)
)

更多详细信息可以在Performance Guide under "Sorting Searches Using Range Indexes"中找到..

呵呵!

关于xquery - 从目录中获取文档时按元素排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39225312/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com