Busturdust
Busturdust

Reputation: 2495

MarkLogic - Extending the Search, return specific object node

I am very new getting started with MarkLogic and XQuery.

I am trying to create a Search Transform to return, the actual JSON from a specific level of the document

Here is a sample Document.

enter image description here

I would like to return the whole JSON based segment no matter where the search results are in the lower level (transcript, topics, banners etc.,)


Splashing around in the Query Console...

search:search('trump')/search:result/search:snippet//@path

Successfully Returns the path of the object, wrapped in a fn:doc

fn:doc("/20170120/NBCNightlyNews/1830/nbc")/array-node("segments")/object-node()1/transcript/node("00:00:02")/text("message")

However,

When I try to implment a similar Xpath Expression in a transform.

let $root := $content/*
return document {$root/search:result/search:snippet//@path}

And try to execute it (at no matter what the xpath expression is, besides simply $root itself there is a different failure) it returns

<error-response xmlns="http://marklogic.com/xdmp/error">
<status-code>400</status-code>
<status>Bad Request</status>
<message-code>XDMP-CHILDNODEKIND</message-code>
<message>
XDMP-CHILDNODEKIND: $root/search:result/search:snippet/descendant-or-self::node()/@path -- document nodes cannot have attribute node children
</message>
</error-response>

If I can get the transform to return the path, I can then continue on trying to evaluate the path, grab the appropriate JSON section and return.

Any thoughts?

Upvotes: 3

Views: 191

Answers (1)

Dave Cassel
Dave Cassel

Reputation: 8422

It looks like you've written a REST API service extension to do searches. If so, consider using the /v1/search endpoint instead -- that way you're using the built-in functionality.

I'm not sure exactly what you're trying to do: do you want to return snippets from the "segment" part of the document, or do you want to return that complete part of the document, regardless of where the matches were?

If the former, you can customize the snippeting by specifying the preferred source of matches.

If the latter, you can write a search transform that will give you complete control over what gets returned.

These options are available (and I think the same) whether using the REST API or calling the Search API.

Upvotes: 3

Related Questions