Viktor
Viktor

Reputation: 1487

Marklogic cts:document-query

Recently, I have to use MarkLogic and there are some things I don't understand.

I don't want you to clarify all my concerns regarding MarkLogic just one :)

There is an XQuery and I don't understand what it does.

let $pap := cts:uris(
   (), (),
   cts:and-query((
      cts:collection-query("/pageType/collection1"),
   ))
)

let $collection := ("/pageType/Attachment")
return
xdmp:estimate(
   cts:search(
      fn:doc(),
      cts:and-query((
         cts:collection-query(($collection)),
         cts:document-query($pap)
      ))
   )
)

I have huge problems to understand what the document-query function does.

Can somebody enlighten me, please? I am a beginner in MarkLogic who worked with relational databases before.

Thanks,

V.

Upvotes: 2

Views: 560

Answers (2)

DALDEI
DALDEI

Reputation: 3732

I neglected to answer your first question. cts:document-query() is documented here:

https://docs.marklogic.com/cts:document-query

In this case it is acting as a filter for the return of cts:search to include only documents found by the previous query cts:uris()

Upvotes: 2

DALDEI
DALDEI

Reputation: 3732

Dont feel bad for not understanding this. Its a bit obtuse. And inefficient.

If I am reading this right what its really doing is counting the number of documents that belong to both collections "/pageType/Attachement" and "/pageType/collection1"

I believe (offhand not tested) this could be vastly simplified by doing

xdmp:estimate( cts:search( fn:doc(), cts:and-query(( cts:collection-query("/pageType/collection1"), cts:collection-query("/pageType/Attachment") )) ) )

Upvotes: 3

Related Questions