MarkLogic,如何在cts字段词查询中向字段增加权重

时间:2019-02-22 11:05:24

标签: xquery marklogic

我有这段代码

declare variable $a as xs:string := "case-insensitive punctuation-insensitive 
unwildcarded";  

declare variable $b as xs:string* := tokenize($a, ' ');

let $d as cts:query := cts:field-word-query("FULL-CASE-NAME", "complaints", 
$b, 30)
return <q>{$d}</q>

产生此结果

<q>
  <cts:field-word-query weight="30" xmlns:cts="http://marklogic.com/cts">
    <cts:field>FULL-CASE-NAME</cts:field>
    <cts:text xml:lang="en">complaints</cts:text>
    <cts:option>case-insensitive</cts:option>
    <cts:option>punctuation-insensitive</cts:option>
    <cts:option>unwildcarded</cts:option>
  </cts:field-word-query>
</q>

但是我想生产的是这个

<q>
  <cts:field-word-query weight="30" xmlns:cts="http://marklogic.com/cts">
    <cts:field weight="10">FULL-CASE-NAME</cts:field>
    <cts:text xml:lang="en">complaints</cts:text>
    <cts:option>case-insensitive</cts:option>
    <cts:option>punctuation-insensitive</cts:option>
    <cts:option>unwildcarded</cts:option>
  </cts:field-word-query>
</q>

这一行的区别在于增加了权重作为属性

<cts:field weight="10">FULL-CASE-NAME</cts:field>

1 个答案:

答案 0 :(得分:2)

cts:field仅保留字段名称。权重(初始代码中为30)已经存在,并作为属性附加到所属的cts:field-word-query上。

HTH!