[MarkLogic Dev General] Referencing a string variable within cts:search

Lee Pollington lee.pollington at gmail.com
Tue Jun 26 16:57:18 PDT 2007

Hi Mattio,

The answer depends on how simple or complex you need your query to be. A
simple approach to satisfy just the above could be:

(Assume $query is your external variable)

let $query := "view, contents"
return cts:search(//LINE,   cts:and-query(tokenize($query, ", ")))

This assumes you always want to AND your keywords.

You could pass in XML representing your query and parse it:

define function get-query($query as element(query)) as cts:query {

  let $query-body := $query/*
        case element(and) return process-and-query($query-body)
        (: process or query :)
        default return error("Invalid query type")

define function process-and-query($and-element as element(and)) as
cts:and-query {

let $query :=
return cts:search(//LINE, get-query($query))

You can use xdmp:unquote() to turn your xml sting passed in via your
external variable into a document node.

You might even want to take a look at:


On 26/06/07, Mattio Valentino <mattio.valentino at gmail.com> wrote:
> ....
But, is there a more proper or efficient way to pass in this variable
> so it can be referenced inside of cts:search?  Or is there a way to
> convert it properly using XQuery?
> Thanks!
> _______________________________________________
> General mailing list
> General at developer.marklogic.com
> http://xqzone.com/mailman/listinfo/general
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://xqzone.marklogic.com/pipermail/general/attachments/20070627/2408eca7/attachment.html

More information about the General mailing list