Wagner Michael
Wagner Michael

Reputation: 2192

MarkLogic Search return document collections

Is there a way to return the collections of a document if you are using the search api?

I could not find a option in the Query Options Reference for that use case.

Right now i would have to build my own wrapper around the search api and find the collections of search results by myself:

xquery version "1.0-ml";
import module namespace search = "http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy";

let $docs := search:search("query")

return for $doc in $docs
return xdmp:node-collections(doc($doc/search:result/@uri))

Edit: This should be also availiable with the marklogic java client api.

Upvotes: 0

Views: 134

Answers (2)

ehennum
ehennum

Reputation: 7335

To get only document metadata such as collections and not the document content, write and install a server-side transform that takes calls xdmp:node-collections() on the document and constructs a replacement document. See:

http://docs.marklogic.com/guide/java/transforms

Then call the QueryDefinition.setResponseTransform() method to specify the server-side transform:

http://docs.marklogic.com/javadoc/client/com/marklogic/client/query/QueryDefinition.html#setResponseTransform-com.marklogic.client.document.ServerTransform-

before passing the query definition to the DocumentManager.search() method:

http://docs.marklogic.com/javadoc/client/com/marklogic/client/document/DocumentManager.html#search-com.marklogic.client.query.QueryDefinition-long-

As a footnote, the DocumentManager.search() method can retrieve both the document metadata and content in a single request without a server-side transform by calling DocumentManager.setMetadataCategories() before searching. See:

http://docs.marklogic.com/javadoc/client/com/marklogic/client/document/DocumentManager.html#setMetadataCategories-java.util.Set-

Hoping that helps,

Upvotes: 0

grtjn
grtjn

Reputation: 20414

In case you are using the MarkLogic REST api, you can use the category parameter on /v1/search to pull up metadata instead of content. If you would like to blend it into the search results, you best use a REST transform on /v1/search using the transform parameter. See also:

https://docs.marklogic.com/REST/GET/v1/search

HTH!

Upvotes: 2

Related Questions