简体   繁体   中英

How to search and return document name in Marklogic?

How can I search contents of documents and return the corresponding document name in Marklogic? Suppose my document name is test.doc and it contains a text eg "hello world" . Now I am uploading this document in Marklogic Server and the content processor will generate the corresponding XML files. Now I am searching like this:-

import module namespace search="http://marklogic.com/appservices/search" at "/Marklogic/appservices/search/search.xqy";
declare variable $options:=
<options xmlns="http://marklogic.com/appservices/search">
<transform-results apply="raw"/>
</options>;

for $d in search:search("hello world", $options)/search:result
return tokenize(data($d/@uri), "/")[last()]

It returns the corresponding XML and XHTML file names containing the text " hello world " but I want to return only the original document name ( test.doc ) not the corresponding XML file name.

This information is not retained automatically, so you need to somehow explicitly support it in your content pipeline.

You can modify the pipeline to store the original document name in a document property for the destination XML document, you could store the document name as metadata in the document, or you could store the original document name as part of the URI.

Might be out of date, but useful.

http://docs.marklogic.com/xdmp:node-uri

xdmp:node-uri

xdmp:node-uri(
   $node as node()
) as xs:string?
Summary

Returns the document-uri property of the parameter or its ancestor.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM