2012-09-15 14 views
2

我使用的是官方文档:http://docs.basex.org/wiki/Commands#String_Syntax,我一直无法找到逻辑运算符列表。我希望能够查询text contains 'A' or 'B'。我也试图找出如何限制返回结果的数量,并且我试图找到一个在BaseX中创建关系表的好指南。我在哪里可以找到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> 

CNC中

现在看看这个代码,它是基于关闭现有的答案:

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> 

CNC中

的另一种尝试:

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

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

-Edit-

最近的尝试非常接近;然而,当我把它应用到数据库实际上,我试图访问,而不是为baseX样本数据库,我得到一个特殊的品牌的错误:

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

DOC(“测试”):=

<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文档,它的格式都非常格式化,就像这样,这是我尝试访问它(重构它)的原因之一。 Next question即将到来:“how do I target same-node-having values in XQuery”?

+0

'[支付包含文本'信用卡'使用区分大小写的词干或支付包含文本'货币顺序'使用区分大小写的词干]'适用于或,但它真的很罗嗦。此外,它限制了我的返回值。我希望能够将“Creditcard”设置为一个变量,将“Money order”作为另一个变量。 –

+0

XQuery可能适用? –

+0

是的这个问题是完全相关的XQuery,我会尽力为您提供一个答案:) – michael

回答

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> 

我希望这可以帮助和回答你的问题,如果它不会随意要求更多的帮助:)

+0

如果我想将$关键字设置为'\ n'分隔值文件,使用JavaScript和XQuery ...,你会碰巧能够为此目的调整剧本吗?我将尽快在问题主体中尽我所能。 –

+0

Ow。头痛! http://en.wikibooks.org/wiki/XQuery/Splitting_Files lol –

+0

我实际上已经能够发现BaseX有专门用于HTTP事件的页面!紧,对吗? :D http://docs.basex.org/wiki/HTTP_Module –

相关问题