※試用版を使っています。
(入門ガイド)Getting Started With MarkLogic Server — Chapter 6
サンプルを読み込む
MarkLogicと一緒にインストールされたサンプルで遊ぶ。
クエリが描ける画面を呼び出す。(マニュアル上は:8000だが、:8002が正解のようだ)
http://localhost:8002/
サンプルクエリでデータを参照する
1991年以降に発売された「Addison-Wesley」の書籍の発売年とタイトルを表示。
XQueryは初だが、シンプルなforループの処理なので解りやすい。
Q1.1_Value_Constraints.xq
(: __________________________________________________________
:: (Q1.1)
:: List books published by Addison-Wesley after 1991
:: including their year and title.
:: __________________________________________________________
:)
<bib>
{
for $b in doc("http://bstore1.example.com/bib.xml")/bib/book
where $b/publisher = "Addison-Wesley" and $b/@year > 1991
return
<book year="{ $b/@year }">
{ $b/title }
</book>
}
</bib>
条件を変更して実行してみた
- 1991以降 → 1993以降
- priceの値を追加表示
Q1.1_Value_Constraints.xq
<bib>
{
for $b in doc("http://bstore1.example.com/bib.xml")/bib/book
where $b/publisher = "Addison-Wesley" and $b/@year > 1993
return
<book year="{ $b/@year }">
{ $b/title }
{ $b/price }
</book>
}
</bib>
まとめ(やったこと)
- xdmpを利用して任意のURLを持つ文書をデータベースへ登録
- URLを利用してデータを検索
【参考】データソース
bstore1.example.com/bib.xml
xdmp:document-insert("http://bstore1.example.com/bib.xml",
<bib>
<book year="1994">
<title>TCP/IP Illustrated</title>
<author><last>Stevens</last><first>W.</first></author>
<publisher>Addison-Wesley</publisher>
<price>65.95</price>
</book>
<book year="1992">
<title>Advanced Programming in the Unix environment</title>
<author><last>Stevens</last><first>W.</first></author>
<publisher>Addison-Wesley</publisher>
<price>65.95</price>
</book>
<book year="2000">
<title>Data on the Web</title>
<author><last>Abiteboul</last><first>Serge</first></author>
<author><last>Buneman</last><first>Peter</first></author>
<author><last>Suciu</last><first>Dan</first></author>
<publisher>Morgan Kaufmann Publishers</publisher>
<price>39.95</price>
</book>
<book year="1999">
<title>The Economics of Technology and Content for Digital TV</title>
<editor>
<last>Gerbarg</last><first>Darcy</first>
<affiliation>CITI</affiliation>
</editor>
<publisher>Kluwer Academic Publishers</publisher>
<price>129.95</price>
</book>
</bib>);