Search code examples
marklogic

Does MarkLogic search.search in server-side JavaScript support JSON options?


The MarkLogic documentation states that search options can be expressed in JSON for "selected Client APIs, such as the REST Client API":

A set of query options has the following structure. You can only use the JSON form with selected Client APIs, such as the REST Client API.

Ref: https://docs.marklogic.com/guide/search-dev/appendixa#id_94988

I guess this does not cover the search.search function in server-side JavaScript? Because something like search.search('apple', {...}) would result in Invalid coercion: object-node{...} as element(search:options) error.

This is a little odd as many other MarkLogic JavaScript functions support JSON (or JS Object) as the options parameter. Did I miss something?


Solution

  • The REST API supports a JSON equivalent for the XML query options and structured query accepted by the Search API.

    The documentation shows both the XML and JSON serializations for both query options and structured query:

    http://docs.marklogic.com/guide/search-dev/appendixa#id_94988

    http://docs.marklogic.com/guide/search-dev/structured-query#id_85307

    By the way, if you want to search in Server-Side JavaScript, take a look at JSearch:

    http://docs.marklogic.com/guide/search-dev/javascript

    http://docs.marklogic.com/js/jsearch

    JSearch was designed for use in Server-Side JavaScript (where the Search API was designed for use in XQuery).

    Hoping that helps,