Hi, Vikas:
No, the order of listed values in a range query has no influence on document
ordering.
In your second example, the predicate is scanning the entire list of documents
for each sequence value.
Given that the list of documents is in the thousands, you might want to iterate
over the documents once to order them -- something like the following should
work:
let $id-order :=
let $id-map := map:map()
return (
for $id at $i in $seq
return map:put($id-map,$id,$i),
$id-map
)
for $content in
cts:search(fn:doc(),cts:element-attribute-range-query(xs:QName(“emp”)
,xs:QName(“id”),”=”,$seq ))
let $id := $content//emp/@id/string(.)
let $ord := map:get($id-order,$id)
order by $ord
return $content
If you can materialize a value in each document and create a range index over
those values, you can use cts:index-order(), which would be faster yet.
Hoping that helps,
Erik Hennum
________________________________
From: [email protected]
[[email protected]] on behalf of
[email protected] [[email protected]]
Sent: Tuesday, June 21, 2016 1:09 AM
To: [email protected]
Subject: [MarkLogic Dev General] order of cts:search result
Hi All,
I am passing sequence of value to cts:search function as attribute
range-query . Will cts: search return the content in same order of sequence
element passed.
I want to get the result as sorted by “18hduye” ,” 38h34ye” ,” 28h55e”.
Example: let $seq := (“18hduye”,”38h34ye”,”28h55e”)
return
cts:search(fn:doc(),cts:element-attribute-range-query(xs:QName(“emp”)
,xs:QName(“id”),”=”,$seq ))
Will the above function return the Employee in same sequence as above
mentioned in seq variable. Or do we have any other way to sort the content as
passed $seq variable.
As per my understanding order by will work only resultset which we got from
cts:search .
I found one way as :
let $content :=
cts:search(fn:doc(),cts:element-attribute-range-query(xs:QName(“emp”)
,xs:QName(“id”),”=”,$seq ))
for $each in $seq
return $content[@id=$each]
This way I am making sure the correct order but it will slow our process the
get the result set for thousands of object.
Regards,
Vikas Singh
This e-mail and any files transmitted with it are for the sole use of the
intended recipient(s) and may contain confidential and privileged information.
If you are not the intended recipient(s), please reply to the sender and
destroy all copies of the original message. Any unauthorized review, use,
disclosure, dissemination, forwarding, printing or copying of this email,
and/or any action taken in reliance on the contents of this e-mail is strictly
prohibited and may be unlawful. Where permitted by applicable law, this e-mail
and other e-mail communications sent to and from Cognizant e-mail addresses may
be monitored.
_______________________________________________
General mailing list
[email protected]
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general