3

我正在使用官方文档:http ://docs.basex.org/wiki/Commands#String_Syntax ,但我无法找到逻辑运算符列表。我希望能够查询text contains 'A' or 'B'

按照同样的思路,我还试图弄清楚如何限制返回的结果数量,并且我试图找到一个在 BaseX 中创建关系表的好指南。

这就是我正在使用的......我已经想出了如何做“或”,但我还没有想出如何为不同的目标传递变量。

let $items := ('Creditcard', 'Money order')
for $item score $s in doc('xmark')//item
  [payment contains text "$items" using stemming using case sensitive]
order by $s descending
return <item ranking= '{ $s }'>{ $item/payment/text() }</item>

-编辑-

现在查看此代码,该代码基于现有答案:

let $items := ('Creditcard', 'Money order')
for $item in descendant::*:$item | descendant-or-self::*[text() contains text "$item"] | .//item//payment[descendant-or-self::node()/@*:lang = "bnt"][descendant-or-self::node()/@*:lang = "afr"][descendant-or-self::node()/@*:lang = "eng"][descendant-or-self::node()/@*:lang = "chi"]
return <payment>{ .//item//payment/text() }</payment>
       <buyer_name>{ .//item//buyer/text() }</buyer_name>

-编辑-

另一种尝试:

let $list := doc('xmark')
return for $p in $list/payments/item/payment-method[text() = 'Creditcard']
return $p//text()

返回 0 个结果。只是试图从文本中获取“信用卡”,即“付款方式”的值。基本上,我无法找到一致或成功的例子。

-编辑-

最近的尝试非常接近;但是,当我将它应用于我实际尝试访问的数据库而不是 BaseX 示例数据库时,我得到了一个特殊的错误品牌:

通过http://basex.org/products/live-demo/

文档(“测试”):=

<item>
<item_number>1171270</item_number>
<seller_info>
<seller_company_id>6356</seller_company_id>
<seller_rating>C31</seller_rating>
<seller_rating>T150 hr.</seller_rating>
</seller_info>
<product_info>
<unit>2022</unit>
<sinfo>55 cases</sinfo>
<sinfo>Yu-gi-oh trading card pack</sinfo>
<sinfo>.45kg per unit</sinfo>
<sinfo>24.7500kg shipment</sinfo>
</product_info>
<product_info>
<unit>9291</unit>
<sinfo>7 units</sinfo>
<sinfo>Naruto, Classic, action figure</sinfo>
<sinfo>1.8kg per unit</sinfo>
<sinfo>12.6kg shipment</sinfo>
</product_info>
</item>

0:编写您自己的查询... :=

let $doc := doc('test') 
for $v in $doc//item
where contains($v//seller_rating,'C31')
return $v//product_info/sinfo

回报:

Error:
Stopped at line 3, column 39: [XPTY0004] Single item expected, (element seller_rating { ... }, element seller_rating { ... }) found.

我不能说我没想到会遇到这样的问题。不幸的是,我没有格式化 XML 文档,而且它的格式都非常糟糕,就像这样,这也是我试图访问它(重构它)的部分原因。 下一个问题出现了:“我如何在 XQuery 中定位具有相同节点的值”?

4

1 回答 1

2

恕我直言,这与您的问题最相似:

let $results := 
( (: Prepare a sequence of results for each $keyword in $keywords :)
let $keywords := ('Money order', 'Creditcard', 'Personal Check')
for $keyword in $keywords
  (: see http://docs.basex.org/wiki/Full-Text#Scoring for information regarding
  scores :)
  for $item score $s in doc('xmark')//item[
    payment contains text {$keyword} all words using stemming using case sensitive
  ]
  order by $s descending
  return <item ranking= '{ $s }'>{ $item/payment/text() }</item>
)
(: now sort and group these results, grouping is done to eliminate duplicate payment
methods that have been matched by two or more keywords :)
for $result in $results
  group by $val := $result/text()
  order by $result[1]/@ranking descending
return $result[1]

score不过,我认为您可能对包含您的关键字的不同支付方式的总数不感兴趣,以下查询将为您提供这些数据:

let $keywords := ('Cash', 'Personal Check')
for $keyword in $keywords 
return <keyword name="{$keyword}">
{
for $result in //item/payment
  group by $payment-method := $result/text()
  order by count($result) descending
return element {"item"} {
    attribute {"count"} {count($result)},
    $payment-method
  }[. contains text {$keyword} phrase]
}</keyword>

我希望这对您有所帮助并回答您的问题,以防您无法随意寻求更多帮助:)

于 2012-09-15T15:00:14.983 回答