繁体   English   中英

xquery 高效谓词与 for...where

[英]xquery efficient predicates versus for…where

我有一系列看起来像这样的 xml 节点:

let $x := 
 <works>
   <work xml:id="W1">
      <author corresp="AU08"/>
      <group corresp="GR03"/>
   </work>
   <work xml:id="W2">
      <author corresp="AU09"/>
      <group corresp="GR10"/>
   </work>
   <work xml:id="W3">
      <author corresp="AU08"/>
      <group corresp="GR05"/>
   </work>
    ....
 </works>

我有一个搜索表单,它可能会或可能不会针对work/@xml:idwork/author/@correspwork/affiliation/$corresp提供序列参数,例如:

let $xmlids := ("W1")
let $authors := ()
let $groups := ("GR05","GR08")

或者

let $xmlids := ()
let $authors := ("AU01","AU08")
let $groups := ("GR05")

我正在尝试在 Xquery 3.1 (eXist 4.7) 中创建一个有效的查询,以考虑参数的不同排列,同时输出work/ 这导致我构建了一系列丑陋的嵌套if语句,它们试图支持谓词而不是for...where如下所示:

if (count($xmlids) gt 0 and count($authors) gt 0 and count($groups) gt 0)
   then 
      $x/id($xmlids)/author[@corresp=$authors]/parent::work/group[@corresp=$groups]/parent::work
else if (count($xmlids) gt 0 and count($authors) gt 0 and count($groups) eq 0)
   then 
      $x/id($xmlids)/author[@corresp=$authors]/parent::work
else if ...

有没有更有效的方法来构建一个 Xquery 来考虑变量存在/不存在的参数?

提前谢谢了。

我认为对于谓词,您只需要@corresp=$authors or not(exists($authors))@corresp=$groups or not(exists($groups))

对于id呼叫,我认为您需要

let $work-items := if ($x/id($xmlids)) then $x/id($xmlids) else $x/work
return $work-items[author[@corresp=$authors or not(exists($authors))] and group[@corresp=$groups or not(exists($groups))]]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM