Huh. I guess I didn't understand what you wanted after all. I thought you were ordering by an attribute originally and you wanted to keep them in order of first appearance, not just alphabetize.
And it doesn't seem right that distinct-values should care what the return does. Anyway, glad it's working. Regarding maps, there's the doc, and a blog post, which should pretty much cover the subject: http://docs.marklogic.com/guide/app-dev/hashtable https://developer.marklogic.com/blog/im-a-map On Fri, Jul 31, 2015 at 12:32 PM, Kari Cowan <[email protected]> wrote: > 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: [email protected] > [mailto:[email protected]] On Behalf Of Kari Cowan > Sent: Thursday, July 30, 2015 1:59 PM > To: MarkLogic Developer Discussion <[email protected]> > 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: [email protected] > [mailto:[email protected]] On Behalf Of Christopher > Hamlin > Sent: Thursday, July 30, 2015 12:46 PM > To: MarkLogic Developer Discussion <[email protected]> > 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 > [email protected] > Manage your subscription at: > http://developer.marklogic.com/mailman/listinfo/general > > > > _______________________________________________ > General mailing list > [email protected] > Manage your subscription at: > http://developer.marklogic.com/mailman/listinfo/general > > > > _______________________________________________ > General mailing list > [email protected] > Manage your subscription at: > http://developer.marklogic.com/mailman/listinfo/general _______________________________________________ General mailing list [email protected] Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general
