If you're curious, this was the final working version of the snippet.  The 
distinct-values function was giving me an error until I cast the return as a 
string.

Thanks for the tips.  Is there a tutorial for map:map or just RTFN?


xquery version "1.0-ml"; 
declare namespace ec = "http://www.alm.com/event-calendar";;

let $directory:="/data-sources/editorial-calendar/"
let $future-calendar-docs:= 
cts:search(
  xdmp:directory($directory),                                        
  cts:and-query((
    cts:element-attribute-range-query(xs:QName("ec:MaterialsDueDate"), 
xs:QName("date"), ">=", xs:date(fn:current-date()) ),
    cts:element-query(xs:QName("ec:approval_status"),cts:word-query("true"))
  ))
) 
 
for $audience in fn:distinct-values($future-calendar-docs//ec:audience)
order by $audience
return xs:string($audience)



-----Original Message-----
From: general-boun...@developer.marklogic.com 
[mailto:general-boun...@developer.marklogic.com] On Behalf Of Kari Cowan
Sent: Thursday, July 30, 2015 1:59 PM
To: MarkLogic Developer Discussion <general@developer.marklogic.com>
Subject: Re: [MarkLogic Dev General] Sorting and De-duping

Thanks.  I haven't worked with the map function yet.  I was trying to use 
distinct-values in the for loop, but get an error that my value isn't a node 
(which is true)

for $audience in xs:string(fn:distinct-values($these-docs//ec:audience))
order by $audience
return $audience/fn:string()

>> [1.0-ml] XDMP-NOTANODE: (err:XPTY0019) $audience/fn:string(.) -- 
>> "Automotive" is not a node

How would I map this a cts search?

xquery version "1.0-ml";
declare namespace ec = "http://www.alm.com/event-calendar";;
let $directory:="/data-sources/editorial-calendar/"
let $these-docs:=
cts:search(
  xdmp:directory($directory),                                        
  cts:and-query((
    cts:element-attribute-range-query(xs:QName("ec:MaterialsDueDate"), 
xs:QName("date"), ">=", xs:date(fn:current-date()) ),
    cts:element-query(xs:QName("ec:approval_status"),cts:word-query("true"))
  ))
) 

for $audience in $these-docs//ec:audience order by $audience  return 
$audience/fn:string()



-----Original Message-----
From: general-boun...@developer.marklogic.com 
[mailto:general-boun...@developer.marklogic.com] On Behalf Of Christopher Hamlin
Sent: Thursday, July 30, 2015 12:46 PM
To: MarkLogic Developer Discussion <general@developer.marklogic.com>
Subject: Re: [MarkLogic Dev General] Sorting and De-duping

Just to look ahead a little to that next question: fn:distinct-values says "The 
order in which the sequence of values is returned is implementation dependent."

One way to maintain order is to go through your values in order, only pass the 
ones that haven't been seen.  map:map is useful for that kind of side effect.
_______________________________________________
General mailing list
General@developer.marklogic.com
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general



_______________________________________________
General mailing list
General@developer.marklogic.com
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general



_______________________________________________
General mailing list
General@developer.marklogic.com
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to