Loading TOC...

search:parse

search:parse(
   $qtext as xs:string+,
   [$options as element(search:options)?],
   [$output as xs:string?]
) as element()?

Summary

This function parses query text according to given options and returns the appropriate cts:query XML.

Parameters
$qtext The query text to parse. This may be a sequence, to accommodate more complex search UI. Multiple query texts will be ANDed together.
$options Options to define the search grammar and control the search. See description for $options for the function search:search.
$output The format of the parsed query, either the string cts:query or search:query. The search:query output is the structured query XML output. The default is cts:query, which is the annotated cts:query XML output.

Example

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

search:parse("tag:technology AND format:pdf",
   <options xmlns="http://marklogic.com/appservices/search">
     <constraint name="tag">
       <collection/>
     </constraint>
     <constraint name="format">
        <value>
          <element ns="http://purl.org/dc/elements/1.1/" name="tag"/>
        </value>
     </constraint>
   </options>
) 
=>

<cts:and-query qtextjoin="AND" strength="20" 
	xmlns:cts="http://marklogic.com/cts">
  <cts:collection-query qtextpre="tag:" qtextref="cts:annotation">
   <cts:annotation qtextref="following-sibling::cts:uri"/>
   <cts:uri>technology</cts:uri>
  </cts:collection-query>
  <cts:element-value-query qtextpre="format:" qtextref="cts:annotation">
   <cts:element xmlns:_1="http://purl.org/dc/elements/1.1/">_1:tag</cts:element>
   <cts:annotation qtextref="following-sibling::cts:text"/>
   <cts:text>pdf</cts:text>
  </cts:element-value-query>
</cts:and-query>

  

Example

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

search:parse("hello tag:technology AND format:pdf",
   <options xmlns="http://marklogic.com/appservices/search">
     <constraint name="tag">
       <collection/>
     </constraint>
     <constraint name="format">
        <value>
          <element ns="http://purl.org/dc/elements/1.1/" name="tag"/>
        </value>
     </constraint>
   </options>, "search:query")

=> the following structured query:

<search:query xmlns:search="http://marklogic.com/appservices/search">
  <search:and-query>
    <search:term-query>
      <search:text>hello</search:text>
    </search:term-query>
    <search:and-query>
      <search:collection-constraint-query>
        <search:constraint-name>tag</search:constraint-name>
        <search:uri>technology</search:uri>
      </search:collection-constraint-query>
      <search:value-constraint-query>
        <search:constraint-name>format</search:constraint-name>
        <search:text>pdf</search:text>
      </search:value-constraint-query>
    </search:and-query>
  </search:and-query>
</search:query>


  

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.