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

Mattio Valentino mattio.valentino at gmail.com
Tue Jun 26 19:00:48 PDT 2007


Hi Lee,

Thanks for these code samples.  I need to allow moderately complex
queries using the operators and, or, not, near unordered and near
ordered ... and potentially an indicator to boost the weight of
selected terms.  I wrote the little parser I have in C# because I
really wasn't sure how to approach it in XQuery, but taking a look at
these I can see how it might be put togther.

Thanks again!
Mattio

On 6/26/07, Lee Pollington <lee.pollington at gmail.com> wrote:
> 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/*
>   return
>     typeswitch($query-body)
>         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 {
>   cts:and-query(data($and-element/word))
> }
>
> let $query :=
> <query><and><word>view</word><word>contents</word></and></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:
> http://www.w3.org/TR/xquery-full-text/#id-xqft-xqueryx
>
> Cheers,
> Lee
>
>
> 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
> >
>
>
> _______________________________________________
> General mailing list
> General at developer.marklogic.com
> http://xqzone.com/mailman/listinfo/general
>
>


More information about the General mailing list