重构多个 cts:element-value-query 但是 SQL 请求结果

huangapple go评论60阅读模式
英文:

Refacto multiple cts:element-value-query but a SQL request result

问题

在我的MarkLogic数据配置文件中,我有一个功能性实体查询,它执行以下任务:

<entity processor="MarkLogicEntityProcessor" pk="id"
    preImportDeleteQuery="[...]"
    query="
        declare namespace xms='[...]';
        declare namespace gm='[...]';
        declare namespace qc='[...]';
        declare variable $stop as xs:integer external;
        declare variable $start as xs:integer external;
        let $doc_list := cts:search(collection(),
            cts:and-query((
                cts:directory-query(('[...]'),'infinity'),
                cts:or-query((
                    cts:element-value-query(fn:QName('[...]','id'),'id_1'),
                    cts:element-value-query(fn:QName('[...]','id'),'id_2'),
                    cts:element-value-query(fn:QName('[...]','id'),'id_3'),
                    cts:element-value-query(fn:QName('[...]','id'),'id_4'),
                    cts:element-value-query(fn:QName('[...]','id'),'id_5'),
                    [...]
                )),
                cts:element-query(fn:QName('[...]','key'),cts:and-query())
            ))
        ,'unfiltered')
        [$start to $stop]
        return ($doc_list)"

但是否有一种方法可以通过SQL查询获取的自定义ID列表来替换cts:or-query中的多个cts:element-value-query行?

感谢帮助。

英文:

In my marklogic data config file I have a functional entity query who's make the job:

&lt;entity processor=&quot;MarkLogicEntityProcessor&quot; pk=&quot;id&quot;
	preImportDeleteQuery=&quot;[...]&quot;
	query=&quot;
		declare namespace xms=&#39;[...]&#39;;
		declare namespace gm=&#39;[...]&#39;;
		declare namespace qc=&#39;[...]&#39;;
		declare variable $stop as xs:integer external;
		declare variable $start as xs:integer external;
		let $doc_list := cts:search(collection(),
			cts:and-query((
					cts:directory-query((&#39;[...]&#39;),&#39;infinity&#39;),
					cts:or-query((
						cts:element-value-query(fn:QName(&#39;[...]&#39;,&#39;id&#39;),&#39;id_1&#39;),
						cts:element-value-query(fn:QName(&#39;[...]&#39;,&#39;id&#39;),&#39;id_2&#39;),
						cts:element-value-query(fn:QName(&#39;[...]&#39;,&#39;id&#39;),&#39;id_3&#39;),
						cts:element-value-query(fn:QName(&#39;[...]&#39;,&#39;id&#39;),&#39;id_4&#39;),
						cts:element-value-query(fn:QName(&#39;[...]&#39;,&#39;id&#39;),&#39;id_5&#39;),
						[...]
					)),
					cts:element-query(fn:QName(&#39;[...]&#39;,&#39;key&#39;),cts:and-query(()))
			))
		,&#39;unfiltered&#39;)
		[$start to $stop]
		return ($doc_list)&quot;

But is there a way to replace the multiple cts:element-value-query lines of the cts:or-query by a custom list of id comes from a SQL request ?

Thanks for help

答案1

得分: 2

cts:element-value-query()函数的函数签名允许传入多个值。它匹配任何一个值匹配的情况 - 这样你也可以不使用cts:or-query(),如果您将ID作为字符串序列提供,类似以下方式应该能够工作。

<entity processor="MarkLogicEntityProcessor" pk="id"
preImportDeleteQuery="[...]"
query="
    declare namespace xms='[...]';
    declare namespace gm='[...]';
    declare namespace qc='[...]';
    declare variable $stop as xs:integer external;
    declare variable $start as xs:integer external;
    let $ids := ("id_1", "id_2", "id_4", "id_4", "id_5", [...]) (: 从其他代码提供的某个列表 :)
    let $doc_list := cts:search(collection(),
        cts:and-query((
                cts:directory-query(('[...]'),'infinity'),
                cts:element-value-query(fn:QName('[...]','id'), $ids),
                cts:element-query(fn:QName('[...]','key'),cts:and-query()))
        ))
    ,'unfiltered')
    [$start to $stop]
    return ($doc_list)"
英文:

The function signature of cts:element-value-query() allows for more than one value to be passed in. It matches if any value matches - allowing you to also drop the cts:or-query() as well, Something like this shold work if you supply the IDs as a sequence of strings.

&lt;entity processor=&quot;MarkLogicEntityProcessor&quot; pk=&quot;id&quot;
preImportDeleteQuery=&quot;[...]&quot;
query=&quot;
    declare namespace xms=&#39;[...]&#39;;
    declare namespace gm=&#39;[...]&#39;;
    declare namespace qc=&#39;[...]&#39;;
    declare variable $stop as xs:integer external;
    declare variable $start as xs:integer external;
    let $ids := (&quot;id_1&quot;, &quot;id_2&quot;, &quot;id_4&quot;, &quot;id_4&quot;, &quot;id_5&quot;, [...]) (: some list supplied from other code:)
    let $doc_list := cts:search(collection(),
        cts:and-query((
                cts:directory-query((&#39;[...]&#39;),&#39;infinity&#39;),
                cts:element-value-query(fn:QName(&#39;[...]&#39;,&#39;id&#39;), $ids),
                cts:element-query(fn:QName(&#39;[...]&#39;,&#39;key&#39;),cts:and-query(()))
        ))
    ,&#39;unfiltered&#39;)
    [$start to $stop]
    return ($doc_list)&quot;

huangapple
  • 本文由 发表于 2023年2月23日 23:51:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/75547201.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定