[MarkLogic Dev General] Referencing a stringvariablewithincts:search

Mattio Valentino mattio.valentino at gmail.com
Tue Jun 26 18:46:05 PDT 2007


Thanks for all the time you put into this Danny.  I appreciate it!

On 6/26/07, Danny Sokolsky <dsokolsky at marklogic.com> wrote:
> You cannot pass that string in via XCC and have it used as a cts:query.
>
>
> To make this work, you will have to move the code that parses your input
> into a cts:query  from your .net/java code into your XQuery code.  For
> example, you can pass in two string variables from the .net/java side:
>  *  "or" to signify it is an or-query.
>  *  "blues jazz" for the words to be queried.
>
> Your XQuery module on the MarkLogic Server side might then look
> something like this (this is an extremely simple query parser/generator
> that simply tokenizes the input on spaces):
>
>  define variable $query-type as xs:string external
>  define variable $query as xs:string external
>
>  let $query-tokens := fn:tokenize(fn:normalize-space($query), " ")
>  let $ctsquery :=
>      for $x in $query-tokens
>      return
>      cts:word-query($x, ("case-insensitive", "diacritic-insensitive") )
>  let $newquery :=
>     if ( $query-type = "or" )
>     then cts:or-query($ctsquery)
>     else cts:and-query($ctsquery)
>  return
>  <results>
>    <cts-query-expr>{$newquery}</cts-query-expr>
>    <search>{xdmp:estimate(cts:search(doc(), $newquery))}</search>
>  </results>
>
> and you can run this code with something like this:
>
>  xdmp:invoke("invoke.xqy", ((xs:QName("query-type"), "or"),
>                           (xs:QName("query"), "blues jazz")))
>
> The other alternative you have is to construct the entire search on the
> .net/java side, including the cts:search and the cts:query, and then
> send in the whole query to execute via xcc.
>
> -Danny


More information about the General mailing list