0
我嘗試通過cts:uri-match返回所有文檔。不僅是整個文檔,還有uri的。 所以我把一些文檔放在/ app/customer /中,現在我創建了這個REST API擴展端點。但是,當我無法得到這個返回實際的文件。REST API返回文檔內容
它看起來像我的查詢工作(「生產6結果」),但輸出格式是錯誤的。
這是我的錯誤:
<rapi:error
xmlns:rapi="http://marklogic.com/rest-api">
<rapi:status-code>400</rapi:status-code>
<rapi:status>Bad Request</rapi:status>
<rapi:message-code>RESTAPI-INVALIDRESULT</rapi:message-code>
<rapi:message>RESTAPI-INVALIDRESULT: (err:FOER0000) Invalid result: reason: GET extension produced 6 results and 1 mime types: customers</rapi:message>
</rapi:error>
這是我的分機:
xquery version "1.0-ml";
module namespace foo = "http://marklogic.com/rest-api/resource/customers";
declare namespace roxy = "http://marklogic.com/roxy";
declare namespace pub = "http://acme.com/foo/publisher/1.0";
declare
%roxy:params("id=xs:string")
function foo:get(
$context as map:map,
$params as map:map
) as document-node()*
{
map:put($context, "output-types", "application/xml"),
xdmp:set-response-code(200, "OK"),
foo:getCustomersByXPath($params)
};
declare function foo:getCustomersByXPath(
$params as map:map
) as document-node()* {
let $set := cts:uri-match("/app/customer/*")
let $id := map:get($params,"id")
for $x in doc($set)
return doc($x)
};
要檢查在目錄中的數據:
http://myserver:myport/v1/search?q=&directory=/app/customer/
[R esults:
<search:response snippet-format="snippet" total="7" start="1" page-length="10"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="" xmlns:search="http://marklogic.com/appservices/search">
<search:result index="1" uri="/app/customer/10848614934359542547.xml" path="fn:doc("/app/customer/10848614934359542547.xml")" score="0" confidence="0" fitness="0" href="/v1/documents?uri=%2Fapp%2Fcustomer%2F10848614934359542547.xml" mimetype="text/xml" format="xml">
<search:snippet/>
</search:result>
<search:result index="2" uri="/app/customer/7883534461919564626.json" path="fn:doc("/app/customer/7883534461919564626.json")" score="0" confidence="0" fitness="0" href="/v1/documents?uri=%2Fapp%2Fcustomer%2F7883534461919564626.json" mimetype="application/json" format="json">
<search:snippet/>
</search:result>
<search:result index="3" uri="/app/customer/10893316875648096464.json" path="fn:doc("/app/customer/10893316875648096464.json")" score="0" confidence="0" fitness="0" href="/v1/documents?uri=%2Fapp%2Fcustomer%2F10893316875648096464.json" mimetype="application/json" format="json">
<search:snippet/>
</search:result>
<search:result index="4" uri="/app/customer/11529967549112309613.json" path="fn:doc("/app/customer/11529967549112309613.json")" score="0" confidence="0" fitness="0" href="/v1/documents?uri=%2Fapp%2Fcustomer%2F11529967549112309613.json" mimetype="application/json" format="json">
<search:snippet/>
</search:result>
<search:result index="5" uri="/app/customer/12616183128326713409.xml" path="fn:doc("/app/customer/12616183128326713409.xml")" score="0" confidence="0" fitness="0" href="/v1/documents?uri=%2Fapp%2Fcustomer%2F12616183128326713409.xml" mimetype="text/xml" format="xml">
<search:snippet/>
</search:result>
<search:result index="6" uri="/app/customer/2938594927859036749.json" path="fn:doc("/app/customer/2938594927859036749.json")" score="0" confidence="0" fitness="0" href="/v1/documents?uri=%2Fapp%2Fcustomer%2F2938594927859036749.json" mimetype="application/json" format="json">
<search:snippet/>
</search:result>
<search:result index="7" uri="/app/customer/1602860626261524046.json" path="fn:doc("/app/customer/1602860626261524046.json")" score="0" confidence="0" fitness="0" href="/v1/documents?uri=%2Fapp%2Fcustomer%2F1602860626261524046.json" mimetype="application/json" format="json">
<search:snippet/>
</search:result>
<search:qtext/>
<search:metrics>
<search:query-resolution-time>PT0.005074S</search:query-resolution-time>
<search:facet-resolution-time>PT0.000077S</search:facet-resolution-time>
<search:snippet-resolution-time>PT0.000938S</search:snippet-resolution-time>
<search:total-time>PT0.182643S</search:total-time>
</search:metrics>
</search:response>