[MarkLogic Dev General] Invalid coercion and cts:query
Colleen Whitney
Colleen.Whitney at marklogic.com
Fri Mar 19 12:15:10 PST 2010
Or, since the parsed queries are already serialized, you can construct it directly and save a few milliseconds.
<cts:or-query>
{$englishQuery}
{$germanQuery}
<cts:or-query>
--Colleen
________________________________________
From: general-bounces at developer.marklogic.com [general-bounces at developer.marklogic.com] On Behalf Of Wayne Feick [wfeick at marklogic.com]
Sent: Friday, March 19, 2010 11:41 AM
To: General Mark Logic Developer Discussion
Subject: Re: [MarkLogic Dev General] Invalid coercion and cts:query
Oh, and one other thing was pointed out to me offline. The search:resolve() function is expecting an element, not a cts:query, so you do actually need to convert the cts:or-query to an element. If you change your third line to the following I think you'll be in good shape.
$query := <tmp>{cts:or-query((cts:query($englishQuery), cts:query($germanQuery)))}</tmp>/element()
Wayne.
On Fri, 2010-03-19 at 11:24 -0700, Wayne Feick wrote:
Hi Adam,
You don't need that cts:query() wrapper around everything, just use the cts:or-query() directly.
The cts:query() function creates a query from an XML representation of it (e.g. if you had placed a query into a document).
Wayne.
On Fri, 2010-03-19 at 11:06 -0700, Adam Patterson wrote:
Hi, newbie to XQuery and Marklogic here. I’m trying to do something like the following:
...
$englishQuery := search:parse($queryString, $englishOptions),
$germanQuery := search:parse($queryString, $germanOptions),
$query := cts:query( cts:or-query((cts:query($englishQuery), cts:query($germanQuery)))),
$results := search:resolve($query, bhccSearch:getSearchOptions($target, $page))
return ...
I have content which is English, and other content which is German, and I am trying to build queries which will search both the English and German content, and then build a cts:or-query from those, and finally build a cts:query from the cts:or-query which I can use with search:resolve to return results. I keep getting errors like this:
XDMP-ARGTYPE: (err:XPTY0004) cts:query(cts:or-query((cts:word-query("pa", ("lang=en"), 1), cts:word-query("pa", ("lang=de"), 1)))) -- arg1 is not of type element()
So I guess the cts:or-query constructor is not returning me an element as needed by the cts:query constructor. Can someone explain why this is and how I should handle this?
Cheers,
Adam
More information about the General
mailing list