I believe the $pos is not affected by the order by clause (or a where clause)
its the position of the original sequence before ordered or filtered.

Try this:

let $results := for  $x in cts:search(doc(), $cq2, 
'unfiltered')/content/lookupInfo
order by string-length($x/searchPathEnc) descending return  $x

return
  for $x at $p in $results return
                <x><pos>{$p}</pos>{$x/searchPathEnc}</x>

----------------------------------------
David A. Lee
Senior Principal Software Engineer
Epocrates, Inc.
[email protected]<mailto:[email protected]>
812-482-5224

From: [email protected] 
[mailto:[email protected]] On Behalf Of Gary Larsen
Sent: Wednesday, August 31, 2011 4:01 PM
To: 'General MarkLogic Developer Discussion'
Subject: [MarkLogic Dev General] determine the first result in an order by

I'm also struggling with an order by problem today.  What I need is the first 
of the sorted results from this query:

for  $x at $p in cts:search(doc(), $cq2, 'unfiltered')/content/lookupInfo order 
by string-length($x/searchPathEnc) descending return
<x><pos>{$p}</pos>{$x/searchPathEnc}</x>

<x>
    <pos>2</pos>
    
<searchPathEnc>%2Fcontent%2Fpackage%5B%40name%3D%27Demo%27%5D</searchPathEnc>
</x>
<x>
    <pos>1</pos>
    <searchPathEnc>%2Fcontent</searchPathEnc>
</x>
I would expect that the first result would have a position value of 1 but 
that's not the case.  Is there a way to determine (or get directly) the first 
of the ordered results?

Sorry if this is just my lack of XQuery knowledge,
gary

_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to