2

We have a list of URIs and which we need to read in the sequence in which it is passed.

Example1

doc(("/doc1", "/doc2", "/doc3"))

above function should return the content of "/doc1" then "/doc2" and then "/doc3" but it is not happening.

The same thing is happening is with the below query also.

Example2

cts:search(doc(), cts:document-query((("/doc1"),("/doc2"),("/doc3"))))

What will be the solution if I want to read the documents in which sequence I pass the URIs ?

Any help is appreciated..!

DevNinja
  • 1,459
  • 7
  • 10

2 Answers2

5

cts:search has its own ordering functionality, which you can trigger using functions like cts:index-order. fn:doc takes an array, and will return them in database order. Neither of them sounds like what you are trying to achieve.

I would suggest explicitly iterating over the uris, and fetching the uris one by one. You could use ! operator for this, for instance:

("/doc1", "/doc2", "/doc3") ! doc(.)

HTH!

grtjn
  • 20,254
  • 1
  • 24
  • 35
4

@grtjn's answer is correct but you could reduce it to one database query and just return the docs in the order that you want with something like

let $uris := ("/doc2", "/doc1", "/doc3")

let $docs := map:new(
  fn:doc($uris) ! map:entry(xdmp:node-uri(.), .)
)

for $i in $uris
return map:get($docs, $i)
James Kerr
  • 506
  • 2
  • 4
  • Or the query can do the sort using the Optic API, as in op.fromLexicons({uri: cts.uriReference()}, null, op.fragmentIdCol('docId')) .where(op.gt(op.col('uri'), lastUriInPreviousPage)) .orderBy('uri') .limit(256) .joinDoc('doc', 'docId') .result(); – ehennum Feb 08 '21 at 17:05