MarkLogic 结合 cts:query 和 search:query

MarkLogic combine cts:query and search:query

我有一个结构化查询输入,例如:

<query xmlns="http://marklogic.com/appservices/search" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:search="http://marklogic.com/appservices/search" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<and-query>
    <value-query type="string">
        <element ns="" name="AuthorName"/>
        <text>Samantha Bustamante</text>
    </value-query>
    ...
<and-query>

我的 XQuery 查询是这样的:

cts:word-query("word", ("lang=en"), 1)

我想将它们与 cts:and-query($q1, $q2) 结合起来,但结构化查询是 XML。那我该怎么办?

要从结构化查询转到 cts,您可以使用 search:resolve() 函数并将 return-query 选项设置为 true(其余设置为 false)。你可以这样做:

xquery version "1.0-ml";
import module namespace search = "http://marklogic.com/appservices/search"
    at "/MarkLogic/appservices/search/search.xqy";

let $options := 
  <options xmlns="http://marklogic.com/appservices/search">
    <return-query>true</return-query>
    <return-aggregates>false</return-aggregates>
    <return-constraints>false</return-constraints>
    <return-facets>false</return-facets>
    <return-frequencies>false</return-frequencies>
    <return-metrics>false</return-metrics>
    <return-plan>false</return-plan>
    <return-qtext>false</return-qtext>
    <return-results>false</return-results>
    <return-similar>false</return-similar>
    <return-values>false</return-values>
  </options>

let $result :=
  search:resolve(
    <query xmlns="http://marklogic.com/appservices/search">
        <and-query>
            <value-query type="string">
                <element ns="" name="AuthorName"/>
                <text>Samantha Bustamante</text>
            </value-query>
        </and-query>
    </query>,
    $options
  )
let $q1 := cts:query($result/search:query/*)
let $q2 := cts:word-query("word", ("lang=en"), 1)

return cts:and-query(($q1, $q2))