简体   繁体   English

xquery 高效谓词与 for...where

[英]xquery efficient predicates versus for…where

I have a series of xml nodes that look like this:我有一系列看起来像这样的 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>

I have a search form that may or may not offer sequence parameters against work/@xml:id , work/author/@corresp , and work/affiliation/$corresp , for example:我有一个搜索表单,它可能会或可能不会针对work/@xml:idwork/author/@correspwork/affiliation/$corresp提供序列参数,例如:

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

or或者

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

I am trying to create an efficient query in Xquery 3.1 (eXist 4.7) to account for the different permutations of parameters, while outputting work/ .我正在尝试在 Xquery 3.1 (eXist 4.7) 中创建一个有效的查询,以考虑参数的不同排列,同时输出work/ This has lead me to build an ugly series of nested if statements which trying to favour predicates over for...where like the following:这导致我构建了一系列丑陋的嵌套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 ...

Is there a more efficient way to build an Xquery accounting for variable present/absent parameters?有没有更有效的方法来构建一个 Xquery 来考虑变量存在/不存在的参数?

Many thanks in advance.提前谢谢了。

I think for the predicates you just want @corresp=$authors or not(exists($authors)) and @corresp=$groups or not(exists($groups)) .我认为对于谓词,您只需要@corresp=$authors or not(exists($authors))@corresp=$groups or not(exists($groups))

For the id call I think you need对于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