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
$qtextThe query text to parse. This may be a sequence, to accommodate more complex search UI. Multiple query texts will be ANDed together.
$optionsOptions to define the search grammar and control the search. See the description for $options for the function search:search.
$output The format of the parsed query, one of schema-element(cts:query) (default), cts:query, search:query, or cts:annotated-query (deprecated). See the Usage Notes for details.

Usage Notes

Use the $output parameter to specify one of the following output formats. All the formats are suitable for use with search:resolve, but "cts:query" is most efficient if you do not need to transform or traverse the query. Passing a cts:query object avoids an extra parsing step.

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 xmlns:cts="http://marklogic.com/cts">
  <cts:collection-query>
    <cts:uri>technology</cts:uri>
  </cts:collection-query>
  <cts:element-value-query>
    <cts:element xmlns:_1="http://purl.org/dc/elements/1.1/">_1:tag</cts:element>
    <cts:text xml:lang="en">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>

Comments

  • The output of this function seems to be completely useless unless you pass it through cts:query(). Then you can combine it with other queries in the cts: API. e.g. to create an element query that will use google-style parsing : let text:=' .... search text ... ' let $query := cts:element-query( xs:QName('party'), cts:query(search:parse( $text )) ) return cts:search($query) i.e. the search:parse result is NOT suitable for use as a cts:query, but after you send it through the cts:query function, it is.
    • This is meant to be used with the search API. For example, you can pass this into search:resolve. It allows you to separate the parse and resolve parts of search:search.
Powered by MarkLogic Server 7.0-4.1 and rundmc | Terms of Use | Privacy Policy