MarkLogic - Extending the Search, return specific object node

拥有回忆 提交于 2019-12-12 15:12:05

问题


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.

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?


回答1:


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.



来源:https://stackoverflow.com/questions/42260518/marklogic-extending-the-search-return-specific-object-node

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!