gpt4 book ai didi

javascript - MarkLogic 9 Clusters - 使用 SJS 限制某些字段

转载 作者:行者123 更新时间:2023-11-29 21:04:48 26 4
gpt4 key购买 nike

我正在尝试使用服务器端 Javascript 通过 MarkLogic 9 实现一个简单的集群应用程序。我有一个非常复杂的自定义查询生成器,它已经在 J​​S 中实现,所以我更愿意在 .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 的经验,所以我无法理解它,我现在只是在用头撞墙。

最佳答案

如果我理解正确的话,你想在 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 示例,这是您想要的吗?

关于javascript - MarkLogic 9 Clusters - 使用 SJS 限制某些字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44537738/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com