我正在尝试使用服务器端Javascript实现MarkLogic 9的简单群集应用程序。我有一个非常复杂的自定义查询构建器,已经在JS中实现,所以我更愿意在.sjs文件中完成所有操作。
我的问题是我无法弄清楚如何将聚类搜索限制为只查看文档的一些属性(即" title"和#34; abstract")。没有一个属性有孩子。我试过跟随莎士比亚戏剧演示,但它是在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没有经验,所以我无法理解它,而我现在只是碰到了我的头。
答案 0 :(得分:2)
如果我理解正确,您希望在SJS中实施搜索,那么您可以通过这种方式构建搜索:
cts.cluster(
cts.search(cts.wordQuery('some terms')).toArray(),
{
overlapping: false,
labelIgnoreWords: ['a', 'of', 'the', 'when', 's', 'as'],
stemmedSearches: false,
fastPhraseSearches: false,
fastElementWordSearches: false,
fastElementPhraseSearches: false,
//add your other options here
}
);
现在这是一个纯粹的JavaScript示例,这是你所追求的吗?