2012-09-15 50 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 –

相關問題