The other issue that commonly causes sorting to look confusing is when you have multiple instances of an element in the same document. Is there any possibility that this is the case with your data? ________________________________ From: general-boun...@developer.marklogic.com [general-boun...@developer.marklogic.com] on behalf of Erik Hennum [erik.hen...@marklogic.com] Sent: Thursday, May 02, 2013 6:49 AM To: MarkLogic Developer Discussion Subject: Re: [MarkLogic Dev General] search:search and ordering by attribute on root element
Hi, Ryan: cts:search() returns documents, so // will match the root element. In my simple test, search:search() did sort on an attribute on the root element. A few simple things to check -- is the div element in the XHTML namespace? Is there a range index on the attribute in the same collation as the query? Erik Hennum ________________________________ From: general-boun...@developer.marklogic.com [general-boun...@developer.marklogic.com] on behalf of Ryan Dew [ryan.j....@gmail.com] Sent: Wednesday, May 01, 2013 3:02 PM To: MarkLogic Developer Discussion Subject: [MarkLogic Dev General] search:search and ordering by attribute on root element Hello everyone, We have scenario where we are trying to sort on an attribute on the root element being returned. The simple use case is shown below. The div elements that we are returning have an order attribute. let $options := <options xmlns="http://marklogic.com/appservices/search"> <searchable-expression>//div</searchable-expression> <transform-results apply="raw"/> <sort-order type="xs:string" direction="ascending"> <element ns="" name="div"/> <attribute ns="" name="order"/> <annotation>chronology</annotation> </sort-order> </options> return search:search("faith",$options,1,10) We don't get the results we would expect. After looking at the search:search code it appears that the root element isn't included in the XPath expression generated for the order by. It generates "$result//div/@order", but I would expect something like: "$result/descendant-or-self::div/@order". (Sorry if I'm digging more than I should.) Has anyone else encountered this problem and worked around it? Thanks, Ryan Dew
_______________________________________________ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general