[MarkLogic Dev General] Referencing a stringvariablewithincts:search

Danny Sokolsky dsokolsky at marklogic.com
Tue Jun 26 15:54:27 PDT 2007


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

-----Original Message-----
From: general-bounces at developer.marklogic.com
[mailto:general-bounces at developer.marklogic.com] On Behalf Of Mattio
Valentino
Sent: Tuesday, June 26, 2007 2:39 PM
To: General Mark Logic Developer Discussion
Subject: Re: [MarkLogic Dev General] Referencing a
stringvariablewithincts:search


I'm going to try this again fresh in the morning, but I'm not having any
luck.

The string I'm passing to the XQuery module is already parsed and ready
to be used within cts:search ... something like:

cts:or-query( ( cts:word-query("blues", ("case-insensitive",
"diacritic-insensitive")), cts:word-query("jazz", ("case-insensitive",
"diacritic-insensitive")) ) )



On 6/26/07, Danny Sokolsky <dsokolsky at marklogic.com> wrote:
> Ah, I missed the bit about using XCC to pass in the variable, sorry.
>
> To pass this in via XCC, I think you will have to take the approach of

> passing in a string (or several strings, if that makes more sense) and

> then, on the XQuery side, have code that parses the string(s) into an 
> appropriate cts:query.  I don't think XCC will currently allow you to 
> pass in a variable of type cts:query.
>
> For example, if you have a form that the user uses to enter a search, 
> you can pass in this string and have the cts:query parsing code turn 
> the string into a cts:query (like the sample in the doc I mentioned 
> earlier).
>
> -Danny
>
_______________________________________________
General mailing list
General at developer.marklogic.com
http://xqzone.com/mailman/listinfo/general


More information about the General mailing list