2014-04-02 56 views
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(&quot;/app/customer/10848614934359542547.xml&quot;)" 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(&quot;/app/customer/7883534461919564626.json&quot;)" 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(&quot;/app/customer/10893316875648096464.json&quot;)" 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(&quot;/app/customer/11529967549112309613.json&quot;)" 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(&quot;/app/customer/12616183128326713409.xml&quot;)" 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(&quot;/app/customer/2938594927859036749.json&quot;)" 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(&quot;/app/customer/1602860626261524046.json&quot;)" 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> 

回答

3

一個get()擴展功能可以返回多個文件,這些文件可以有不同的MIME類型。

嘗試將輸出類型鍵設置爲每個返回文檔具有一個MIME類型字符串的序列。根據你的情況,這可能是每一個字符串是「應用程序/ XML」

希望幫助

埃裏克Hennum

的情況下,