强制执行无效:()as xs:string +执行搜索时:搜索($ qtext)(Invalid coercion: () as xs:string+ while performing search:search($qtext))

我向http:// localhost:7040 / index.xqy发送一个http请求到MarkLogic服务器。 使用xdmp:get-request-field("q")来捕获xdmp:get-request-field("q") ,该请求接受查询到一个变量中,比如说$ qtext并将它传递给search:search($qtext) 。 这将返回一个404未找到的错误说明 <error:xquery-version>1.0-ml</error:xquery-version> <error:message>Invalid coercion</error:message> <error:format-string>XDMP-AS: (err:XPTY0004) $qtext as xs:string+ -- Invalid coercion: () as xs:string+</error:format-string>

我在这里做错了什么?

I am sending an http get request to the MarkLogic server, something like - http://localhost:7040/index.xqy. Request is captured using xdmp:get-request-field("q") which accept the query into a variable, say $qtext and pass it on to search:search($qtext). This returns a 404 not found error stating <error:xquery-version>1.0-ml</error:xquery-version> <error:message>Invalid coercion</error:message> <error:format-string>XDMP-AS: (err:XPTY0004) $qtext as xs:string+ -- Invalid coercion: () as xs:string+</error:format-string>

What am I doing wrong here?

最满意答案

我找到了解决方案。 基本上$ qtext是空的序列(),这是不允许在搜索:搜索。 我做的是 - let $query := if(fn:empty($q-text)) then "" else $q-text 。 您还可以将请求更改为localhost:7040/index.xqy?q=此链接有助于http://jaketrent.com/post/unexpected-results-marklogic-xquery-type-corcion/

正如所建议的,这是更好的xdmp:get-request-field("q", "")

I found the solution. Basically $qtext is empty sequence () which is not allowed in search:search. What I did is - let $query := if(fn:empty($q-text)) then "" else $q-text. you can also change the request to something like localhost:7040/index.xqy?q= This link helped http://jaketrent.com/post/unexpected-results-marklogic-xquery-type-coercion/

As suggested, this is better xdmp:get-request-field("q", "")

更多推荐