我正在尝试计算复杂匹配查询的分数。 例如:
if conditionA and conditionB and (conditionC or conditionD)
then score = 10
else score = 0
这是我提出的解决方案:
let $idReq := cts:register(
cts:and-query((
cts:path-range-query("/person/name", "=", 'val1', ("score-function=linear", "collation=http://marklogic.com/collation//S1")),
cts:path-range-query("/person/country", "=", 'country', ("score-function=linear", "collation=http://marklogic.com/collation//S1")),
cts:or-query((
cts:path-range-query("/person/city", "=", 'city', ("score-function=linear", "collation=http://marklogic.com/collation//S1")),
cts:path-range-query("/person/school", "=", '', ("score-function=linear", "collation=http://marklogic.com/collation//S1"))
))
))
)
return
cts:score(cts:search(fn:doc(), cts:registered-query($idReq, ("unfiltered"), 10)))
所有索引都存在,也是整理。
当我执行此注册查询时,我总是得到0分数。
EDITED
我已经缩小了问题范围,可以通过组合cts来复制:使用cts注册:path-range-query。
let $query := cts:path-range-query("/person/name", "=", "val1", ("score-function=linear", "collation=http://marklogic.com/collation//S1"))
let $idReq := cts:register($query)
return
cts:score(
cts:search(fn:doc(),
cts:registered-query($idReq,("unfiltered"), 10)
(: $query :)
)
)
EDITED
设置索引配置以进行测试:
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";
let $dbid := xdmp:database("Documents")
let $config :=
admin:database-add-range-path-index(
admin:get-configuration(), $dbid,
admin:database-range-path-index(
$dbid, "string", "/person/name",
"http://marklogic.com/collation//S1",
fn:false(), "ignore"))
return admin:save-configuration($config)
示例数据:
xdmp:document-insert(
'/test/person1.xml',
<person>
<name>val1</name>
<city>city</city>
<country>country</country>
</person>
)