Search code examples
marklogicmarklogic-8

Marklogic out of the box rest API transform query


I am using out of the box ML REST API POST v1/search, and I am using transform? parameter to transform the results produced. But I also want to manipulate the string q that is sent to the endpoint. Is there anything like transform-query or something that will be called to transform the query string. I understand we can write a custom endpoint to do this, but I want to avoid if this can be done out of the box endpoint.


Solution

  • What I did is wrote a custom web service which handles the transform query, but I also like all the params that the out-of-box rest api does, so I copied the xquery code of the out-of-box.. Following is what I did. In my case I am doing just query expansion

    let $search:= map:get($params,"q")
    let $qexpand := repo-searchLib:queryExpand($search)
    let $_ := map:put($params, "q", $qexpand)
    let $headers   := eput:get-request-headers()
    let $env       := eput:response-callback-map(eput:response-type-callback#1)
    let $response := searchmodq:search-post($headers,$params, $env, xdmp:get-request-body(eput:get-content-format($headers,$params)))
    let $has-matches := map:get($env, "has-matches")
    return
        if (exists($response)) then $response
        else if ($has-matches) then ()
        else xdmp:set-response-code(404,"Not Found")
    

    Do any of you think that there might be something that I might be missing ? presently this seems to be working for me.