3

I have the following codes:

1)

for $song in cts:search(fn:doc(), "night")
return $song/ts:top-song/ts:title/text() 

2)

cts:search(fn:doc(), "night")/ts:top-song/ts:title/text()

cts:search returns documents as per the relevance. Both the codes, return results in a different order. Which would return the result with the correct relevance and why ?

grtjn
  • 20,254
  • 1
  • 24
  • 35
Yash
  • 510
  • 2
  • 6
  • 14

1 Answers1

5

The first.

In the second, XPath is applied to the entire sequence returned by cts:search, but as per XPath standard the result of that is re-ordered into document-order, which becomes unpredictable when the nodes in the sequence come from different documents.

The first applies a FLWOR iteration on the sequence, which ensures keeping the order, and the XPath is applied to each item in the sequence separately.

HTH!

grtjn
  • 20,254
  • 1
  • 24
  • 35