2017-04-18 146 views
0

我的文檔屬性爲每個文檔 -對文檔進行排序:搜索

<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

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 
+0

將在文檔屬性這項工作?我試過了,但它不起作用。它看起來像在文檔上排序而不是文檔屬性。 –

+0

您是否爲文檔屬性定義了元素範圍索引?您需要將其設置爲與文檔元素範圍索引相同的方式。 –

+0

我有一個用 定義的元素範圍索引uri - http://marklogic.com/xdmp/property localname - 最後修改的 類型 - dateTime –

相關問題