我正在尝试使用服务器端 Javascript 用 MarkLogic 9 实现一个简单的集群应用程序。我有一个非常复杂的自定义查询构建器,它已经在 JS 中实现,所以我更愿意在 .sjs 文件中完成所有操作。
我的问题是我无法弄清楚如何将聚类搜索限制为仅查看文档的几个属性(即“标题”和“摘要”)。没有一个属性有孩子。我尝试按照莎士比亚戏剧演示,但它是在 XQuery 中实现的。
我当前的实现是一个 .xqy 文件,它使用 xdmp:javascript-eval 来使用我的 js 查询构建器。这有效并使用以下方法成功返回查询结果:
$qry-results := xdmp:javascript-eval(cts.search(someQueryVariable).toArray())
我认为问题出在我从莎士比亚示例中复制过来的 XQuery 代码中,但我已经使用了很多小时,但无法让它工作。这是我现在的 XQuery:
declare namespace db="http://marklogic.com/xdmp/database" ;
declare namespace cl="cts:cluster" ;
declare namespace dt="cts:distinctive-terms" ;
let $options-node :=
<options xmlns="cts:cluster" >
<overlapping>false</overlapping>
<label-max-terms>1</label-max-terms>
<label-ignore-words>a of the when s as</label-ignore-words>
<max-clusters>10</max-clusters>
<!-- turn all database-level indexing options OFF - only use field terms -->
<db:word-searches>false</db:word-searches>
<db:stemmed-searches>false</db:stemmed-searches>
<db:fast-case-sensitive-searches>false</db:fast-case-sensitive-searches>
<db:fast-diacritic-sensitive-searches>false</db:fast-diacritic-sensitive-searches>
<db:fast-phrase-searches>false</db:fast-phrase-searches>
<db:phrase-throughs/>
<db:phrase-arounds/>
<db:fast-element-word-searches>false</db:fast-element-word-searches>
<db:fast-element-phrase-searches>false</db:fast-element-phrase-searches>
<db:element-word-query-throughs/>
<db:fast-element-character-searches>false</db:fast-element-character-searches>
<db:range-element-indexes/>
<db:range-element-attribute-indexes/>
<db:one-character-searches>false</db:one-character-searches>
<db:two-character-searches>false</db:two-character-searches>
<db:three-character-searches>false</db:three-character-searches>
<db:trailing-wildcard-searches>false</db:trailing-wildcard-searches>
<db:fast-element-trailing-wildcard-searches>false</db:fast-element-trailing-wildcard-searches>
<db:fields>
<field>
<field-name>abstract</field-name>
<include-root>true</include-root>
<stemmed-searches>advanced</stemmed-searches>
<db:fast-phrase-searches>true</db:fast-phrase-searches>
</field>
<field>
<field-name>title</field-name>
<include-root>true</include-root>
<stemmed-searches>advanced</stemmed-searches>
<db:fast-phrase-searches>true</db:fast-phrase-searches>
</field>
<field>
<field-name>institution</field-name>
<include-root>false</include-root>
<stemmed-searches>advanced</stemmed-searches>
<db:fast-phrase-searches>false</db:fast-phrase-searches>
</field>
<field>
<field-name>researcher</field-name>
<include-root>false</include-root>
<stemmed-searches>advanced</stemmed-searches>
<db:fast-phrase-searches>false</db:fast-phrase-searches>
</field>
</db:fields>
</options>
let $res := cts:cluster( $qry-results, $options-node )/cts:cluster
return $res
我最常遇到的错误是这样的:
XDMP-ARGTYPE: (err:XPTY0004) cts:cluster(json:array(<json:array xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" .../>...XDMP-CHILDNODEKIND: element nodes cannot have object node children...), <options xmlns="cts:cluster"><overlapping>false</overlapping><label-max-terms>...</label-max-terms>...</options>) -- arg1 is not of type node()*
in /cluster.xqy, at 113:12 [1.0-ml]
$qry-results = json:array(<json:array xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" .../>...XDMP-CHILDNODEKIND: element nodes cannot have object node children...)
$options-node = <options xmlns="cts:cluster"><overlapping>false</overlapping><label-max-terms>...</label-max-terms>...</options>
我确信这是一些愚蠢的事情,但我没有使用 XQuery 的经验,所以我无法理解它,我现在只是把头撞在墙上。