使用cts:search在文档属性的基础上对文档进行排序

时间:2017-04-18 04:35:44

标签: marklogic marklogic-8

我有每个文档的文档属性 -

<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对搜索结果进行排序。我要知道的一种方法是use a loop。但是这个循环会对查询的性能产生影响。

有没有其他方法可以使用MarkLogic获取搜索结果?

1 个答案:

答案 0 :(得分:2)

cts:search()允许将订单规范作为其选项之一,您可以使用cts:index-order来设置该选项。

因此,如果您正在prop:last-modified进行搜索,那么距离cts:search documentation中的示例并不远。不幸的是,这个排序选项会被忽略(可能是一个错误)。

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

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

您的解决方法似乎是处理此问题的最有效和最直接的方法。将搜索结果拉入FLWOR语句,并使用普通的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
相关问题