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

Mattio Valentino mattio.valentino at gmail.com
Tue Jun 26 10:48:28 PDT 2007


I'm curious about something and I was wondering if anyone has some feedback.

I have a query saved on the file system so I can call it via XCC from
my web application.  The parts of interest are:

let $PARSED_QUERY := cts:and-query( ( cts:word-query("christmas",
("case-insensitive", "diacritic-insensitive")),
cts:word-query("holiday", ("case-insensitive",
"diacritic-insensitive")) ) )
let $SEARCH := cts:search( //(entry | section), $PARSED_QUERY)
let $ESTIMATE := cts:remainder($SEARCH[1])
...go on to do other processing...

This works perfectly fine as is.

I plan on changing $PARSED_QUERY so it's a variable with an external
source.  I attempted this by changing the definition to define
variable $PARSED_QUERY as xs:string external, but I started getting
errors.

After a little debugging, I went back to my test query above and
changed the let definition to be:

let $PARSED_QUERY := 'cts:and-query( ( cts:word-query("christmas",
("case-insensitive", "diacritic-insensitive")),
cts:word-query("holiday", ("case-insensitive",
"diacritic-insensitive")) ) )'

Turns out that treating $PARSED_QUERY as a string throws an error.
That makes sense after looking at the definition for cts:search.

By chance, I tried wrapping $PARSED_QUERY in xdmp:eval() and then I
could pass the value in as a string and have the search execute
properly.  All is well again in my little corner of the world.

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!


More information about the General mailing list