Please correct any misunderstanding I may have, but from the documentation I concluded that search:unparse was meant to reverse the action of search:parse and construct a query string functionally identical to the original (functionally identical because it is reconstructed from the cts:query tree and might not have redundant parentheses and such); If the output of search:unparse is indeed functionally identical then one should be able to reparse it and obtain an identical cts:query tree as obtained from the original search:parse.

However it looks to me like there are cases where search:unparse does not properly render even a trivial cts:query tree created via search:parse, even using the default grammar returned by search:get-default-options(). Referring to the output from the attached snippet, where $query := 'pos -(neg1 OR neg2)', with a simplified tree notation:

(a) search:parse( $query, $opts ) => AND( pos, NOT( OR( neg1, neg2 ) ) ) as expected.

(b) search:unparse of (a) => omits the parentheses grouping the target of the NOT eg. 'pos -neg1 OR neg2'

(c) search:parse of ( b ) => parses the misrendering as expected eg. AND( pos, OR( NOT( neg1 ), neg2 ) )

Query trees (a) and (c) are obviously not functionally identical, since in the first case neg1 is prohibited and the second it is required. The same behavior can be seen with -(neg1 neg2), or other cases with a complex cts:not-query target.

As a workaround I created my own implementation of unparse, and it seems simple enough to parenthesize clauses which don't confirm to the default operator precedence simply by passing the parent clause strength down the recursion and parenthesizing whenever a sub-clause's binding strength is less than the parent; it works for a few test cases at least. Can't the built-in search:unparse do that?

- J.J. Larrea

xquery version "1.0-ml";

import module namespace search="http://marklogic.com/appservices/search";
                    at "/MarkLogic/appservices/search/search.xqy";

declare variable $query := 'pos -(neg1 OR neg2)';

let $options := search:get-default-options()
let $parsed := search:parse( $query, $options )
let $unparsed := search:unparse( $parsed )
let $reparsed := search:parse( $unparsed, $options )
return (
    "Original:",
    $query,    
    "Unparsed:",
    $unparsed,
    "Parsed Tree:",
    $parsed,
    "Reparsed Tree:",
    $reparsed,
    "Options (default):",
    $options
)
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to