MarkLogic结合了cts:query和search:query

时间:2018-09-11 10:08:57

标签: marklogic marklogic-8

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

<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。那我该怎么办?

1 个答案:

答案 0 :(得分:3)

要从结构化查询转换为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))