marklogiccts-search

Parsed query contains no qtextpre in ML9


I've inherited code that was ported from ML7 to ML9 last year and the facet pane of a search page does not display a facet clear control like it did in the legacy system. The XQuery logic to build the control depends on the result of search:parse() containing a @qtextpre attribute. In the older system, the parsed query is:

<cts:element-range-query qtextpre="Status:" qtextref="cts:annotation" operator="=" xmlns:cts="http://marklogic.com/cts" xmlns:xs="http://www.w3.org/2001/XMLSchema">
 <cts:element xmlns:_1="http://www.marklogic.com/ps/ns/qanda/">_1:Status</cts:element>
 <cts:annotation qtextref="following-sibling::cts:value"></cts:annotation>
 <cts:value xsi:type="xs:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Review</cts:value>
 <cts:option>collation=http://marklogic.com/collation/codepoint</cts:option>
</cts:element-range-query>

But in the new system the same query text with the same options parses to:

<cts:element-range-query operator="=" xmlns:cts="http://marklogic.com/cts">
 <cts:element xmlns:_1="http://www.marklogic.com/ps/ns/qanda/">_1:Status</cts:element>
 <cts:value xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Review</cts:value>
 <cts:option>collation=http://marklogic.com/collation/codepoint</cts:option>
</cts:element-range-query>

I'm not real clear on what that attribute is for, but this application code depends on finding the @qtextpre attribute in the query to decide whether to display the facet clear control in the facet pane. Can anyone explain why it's not there in the ML9 version of the parsed query?


Solution

  • Please refer to the documentation per Marklogic version for usage of the search:parse() function.

    I don't have an answer to why - the actual question you are asking, but I can answer the question: what is different in the latest 2 versions. That sounds like it would be more helpful...

    In version 9 of the documentation, there is an option to get output in what is referred to as cts:annotated-query format as well as cts:query format. It appears that the default is just less verbose. This was deprecated according to the notes, but available in the latest release of 9. With MarkLogic 9 having many changes to search, I am not sure which point release things may have changed. However, I believe that the cts:annotated-query option is will give the results you wish.

    https://docs.marklogic.com/9.0/search:parse

    cts:annotated-query: Equivalent to the output produced by schema-element(cts:query), but with the addition of annotations. THIS FORM IS DEPRECATED and will be removed in a future release.

    search:parse($qText, $options, "cts:annotated-query")
    

    Please note that the docs for MarkLogic 10 also list the option you need as deprecated. So keep a lookout for needing a code change for your feature when you go from 9 to 10 of the options is removed.