Search code examples
marklogic

Is it possible to get an XML copy of the default search grammar?


I'm doing a translated version of a MarkLogic search application and I want to translate the search grammar (AND, OR, etc.). I'm currently just using the default operators and I realize they are documented, but is there any way to get this in XML or JSON format?

The endpoint that retrieves the default search options only returns a very few elements, of which <grammar> is not one:

https://server:port/v1/config/query/default/

I tried getting the child element itself:

https://server:port/v1/config/query/default/grammar

but I get back

RESTAPI-NODOCUMENT: (err:FOER0000) Resource or document does not exist: category: options message: Child of options node at 'default/grammar' not found


Solution

  • Looking in the MarkLogic installed files, in MarkLogic/Modules/MarkLogic/appservices/search/search-impl.xqy

    you will find the default grammar in the $default-options:

    <search:grammar>
        <search:quotation>"</search:quotation>
        <search:implicit><cts:and-query strength="20"/></search:implicit>
        <search:starter strength="30" apply="grouping" delimiter=")">(</search:starter>
        <search:starter strength="40" apply="prefix" element="cts:not-query">-</search:starter>
        <search:joiner  strength="10" apply="infix" element="cts:or-query" tokenize="word">OR</search:joiner>
        <search:joiner  strength="20" apply="infix" element="cts:and-query" tokenize="word">AND</search:joiner>
        <search:joiner  strength="30" apply="infix" element="cts:near-query" tokenize="word">NEAR</search:joiner>
        <search:joiner  strength="30" apply="near2" consume="2" element="cts:near-query">NEAR/</search:joiner>
        <search:joiner  strength="32" apply="boost" element="cts:boost-query" tokenize="word">BOOST</search:joiner>
        <search:joiner  strength="35" apply="not-in" element="cts:not-in-query" tokenize="word">NOT_IN</search:joiner>
        <search:joiner  strength="50" apply="constraint">:</search:joiner>
        <search:joiner  strength="50" apply="constraint" compare="LT" tokenize="word">LT</search:joiner>
        <search:joiner  strength="50" apply="constraint" compare="LE" tokenize="word">LE</search:joiner>
        <search:joiner  strength="50" apply="constraint" compare="GT" tokenize="word">GT</search:joiner>
        <search:joiner  strength="50" apply="constraint" compare="GE" tokenize="word">GE</search:joiner>
        <search:joiner  strength="50" apply="constraint" compare="NE" tokenize="word">NE</search:joiner>
    </search:grammar>
    

    And even easier, you could use: search:get-default-options() and then XPath to the search:grammar:

    xquery version "1.0-ml";
    import module namespace search = "http://marklogic.com/appservices/search"
        at "/MarkLogic/appservices/search/search.xqy";
    
    search:get-default-options()/search:grammar