0

In my custom search options, I have specified a transform-results element.

<options xmlns="http://marklogic.com/appservices/search">
    <transform-results apply="highlighted-person-summary-snippet" ns="http://ir.abbvie.com/people-db/person-query"
                       at="/ext/lib/person-query.xqy">
    </transform-results>
</options>

Is there anyway that the XQuery function that implements the custom snippet can have access to what the accept headers are in the search request and be able to leverage that? I would rather not have two separate options XML files defined with the only difference being that one returns XML while the other one returns JSON.

TJ Tang
  • 921
  • 6
  • 17

1 Answers1

3

Yes, just use xdmp:get-request-header. But if you emit a proper search:match element structure, the REST api should convert that automatically to json if necessary..

HTH!

grtjn
  • 20,254
  • 1
  • 24
  • 35
  • This works for me. Do you know if there is a library somewhere that parses the Accept headers already, like maybe what is used to process the headers before passing to the transform in the $context map? I am handling the simple cases now, but there could be more complex Accept headers. – TJ Tang Jun 08 '16 at 18:44
  • Not that I am aware of. I would just assume relatively simple Accept headers. Programmatic calls usually provide simple ones, as they expect a specific response mime. You can use functions like fn:contains, or fn:matches to allow for fuzzy matching.. – grtjn Jun 08 '16 at 19:19