使用cts:search根据文档属性对文档进行排序 [英] Sort documents on the basis of document property using cts:search

查看:108
本文介绍了使用cts:search根据文档属性对文档进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对每个文档都有文档属性-

I have document properties for each document -

<prop:properties xmlns:prop="http://marklogic.com/xdmp/property">
  <prop:last-modified>2017-04-12T04:55:57Z</prop:last-modified>
</prop:properties>

现在,我想使用prop:last-modified对搜索结果进行排序.我知道的一种方法是使用循环 .但是此循环将影响查询的性能.

Now I want to sort my search results using prop:last-modified. One way which I got to know is to use a loop. But this loop will have an impact on the performance of the query.

是否还有其他方法只能通过MarkLogic获得搜索结果?

Is there any other way to get the search results with-in MarkLogic only?

推荐答案

cts:search()允许使用订单规范作为其选项之一,您可以使用

cts:search() allows an order-specification as one of its options, and you can use cts:index-order to set that option.

因此,如果您要搜索prop:last-modified,则与

So if you're searching on prop:last-modified, it's not far to go from the example in the cts:search documentation. Unfortunately, this sorting option gets ignored (may be a bug).

cts:search(fn:doc(), "hello",
("unfiltered",
 cts:index-order(
     cts:element-reference(
         xs:QName("prop:last-modified")),
         "descending")))[1 to 10]

请注意,您需要为prop:last-modified定义一个元素范围索引.

Note that you need an element range index defined for prop:last-modified.

您的解决方法似乎是处理此问题的最有效,最直接的方法.将搜索结果放入FLWOR语句中,然后使用普通的order by:

Your workaround appears to be the most efficient and straightforward way to handle this. Pull the search results into a FLWOR statement, and sort them using plain old order by:

for $r in cts:search(fn:doc(), cts:true-query())
order by $r/property::prop:last-modified descending
return $r/property::prop:last-modified

这篇关于使用cts:search根据文档属性对文档进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆