英文:
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:
<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)"
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.
<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", [...]) (: some list supplied from other code:)
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)"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论