2014-04-02 3 views
0

모든 문서를 cts : uri-match로 반환하려고합니다. 뿐만 아니라 전체 문서. 그래서/app/customer /에 일부 문서를 넣었습니다. 이제이 REST API 확장 엔드 포인트를 만듭니다. 그러나 나는 이것을 얻을 수 없을 때 실제 문서를 반환합니다.REST API 반환 문서 내용

내 쿼리가 작동하는 것처럼 보입니다 ("결과 6 개 생성됨")하지만 출력 형식이 잘못되었습니다.

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

<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> 

내 확장 :

내 오류입니다 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

수 있습니다