简体   繁体   中英

How to search according to namespaces in Marklogic Server?

Suppose I am having some xml documents with one namespace(http://www.marklogic.com) and another set of xml documents with another namespace(http://www.mynamespce.com). Now I want to search in only those xml documents which are having http://www.marklogic.com namespace. How can I do this ?

You don't say how you are searching, but if you are calling search:search you can set the searchable-expression option to the root element of the documents, including the namespace.

declare variable $query as xs:string external ;
search:search(
  $query,
  <options xmlns="http://marklogic.com/appservices/search">
    <searchable-expression
     xmlns:ns1="http://test/namespace/1">/ns1:doc</searchable-expression>
  </options>)

http://docs.marklogic.com/5.0doc/docapp.xqy#display.xqy?fname=http://pubs/5.0doc/xml/search-dev-guide/search-api.xml%2343671 has more on this option.

Or you could call cts:search directly. The searchable expression is the first argument.

declare namespace ns1="http://test/namespace/1" ;
declare variable $query as cts:query external ;
cts:search(/ns1:doc, $query)

There might be other options, too. For example, you could set up multiple fields and search using field queries.

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