<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>4.5. ドリルダウン — groonga v3.0.5ドキュメント</title> <link rel="stylesheet" href="../_static/groonga.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '../', VERSION: '3.0.5', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: true }; </script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/translations.js"></script> <link rel="shortcut icon" href="../_static/favicon.ico"/> <link rel="top" title="groonga v3.0.5ドキュメント" href="../index.html" /> <link rel="up" title="4. チュートリアル" href="../tutorial.html" /> <link rel="next" title="4.6. タグ検索・参照関係の逆引き" href="index.html" /> <link rel="prev" title="4.4. さまざまな検索条件の指定" href="search.html" /> </head> <body> <div class="header"> <h1 class="title"> <a id="top-link" href="../index.html"> <span class="project">groonga</span> <span class="separator">-</span> <span class="description">オープンソースのカラムストア機能付き全文検索エンジン</span> </a> </h1> <div class="other-language-links"> <ul> <li><a href="../../../en/html/tutorial/drilldown.html"><img src="../_static/us.png" alt="English">English page</a></li> </ul> </div> </div> <div class="related"> <h3>ナビゲーション</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="総合索引" accesskey="I">索引</a></li> <li class="right" > <a href="index.html" title="4.6. タグ検索・参照関係の逆引き" accesskey="N">次へ</a> |</li> <li class="right" > <a href="search.html" title="4.4. さまざまな検索条件の指定" accesskey="P">前へ</a> |</li> <li><a href="../index.html">groonga v3.0.5ドキュメント</a> »</li> <li><a href="../tutorial.html" accesskey="U">4. チュートリアル</a> »</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body"> <div class="section" id="id1"> <h1>4.5. ドリルダウン<a class="headerlink" href="#id1" title="このヘッドラインへのパーマリンク">¶</a></h1> <p>groongaでは、特定のカラム値で検索結果をグループ化することができます。これをドリルダウンと呼びます。</p> <p>Siteテーブルに2つのカラムを追加します。TLDドメイン名を格納するdomainカラムと、国名を格納するcountryカラムです。これらのカラムの型は、それぞれドメイン名を主キーとするSiteDomainテーブルと、国名を主キーとするSiteCountryテーブルとします。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>table_create --name SiteDomain --flags TABLE_HASH_KEY --key_type ShortText # [[0, 1337566253.89858, 0.000355720520019531], true] table_create --name SiteCountry --flags TABLE_HASH_KEY --key_type ShortText # [[0, 1337566253.89858, 0.000355720520019531], true] column_create --table Site --name domain --flags COLUMN_SCALAR --type SiteDomain # [[0, 1337566253.89858, 0.000355720520019531], true] column_create --table Site --name country --flags COLUMN_SCALAR --type SiteCountry # [[0, 1337566253.89858, 0.000355720520019531], true] load --table Site [ {"_key":"http://example.org/","domain":".org","country":"japan"}, {"_key":"http://example.net/","domain":".net","country":"brazil"}, {"_key":"http://example.com/","domain":".com","country":"japan"}, {"_key":"http://example.net/afr","domain":".net","country":"usa"}, {"_key":"http://example.org/aba","domain":".org","country":"korea"}, {"_key":"http://example.com/rab","domain":".com","country":"china"}, {"_key":"http://example.net/atv","domain":".net","country":"china"}, {"_key":"http://example.org/gat","domain":".org","country":"usa"}, {"_key":"http://example.com/vdw","domain":".com","country":"japan"} ] # [[0, 1337566253.89858, 0.000355720520019531], 9] </pre></div> </div> <p>domainカラムとcountryカラムでドリルダウンを行う例を以下に示します。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select --table Site --limit 0 --drilldown domain # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 9 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "_key", # "ShortText" # ], # [ # "country", # "SiteCountry" # ], # [ # "domain", # "SiteDomain" # ], # [ # "link", # "Site" # ], # [ # "links", # "Site" # ], # [ # "location", # "WGS84GeoPoint" # ], # [ # "title", # "ShortText" # ] # ] # ], # [ # [ # 3 # ], # [ # [ # "_key", # "ShortText" # ], # [ # "_nsubrecs", # "Int32" # ] # ], # [ # ".org", # 3 # ], # [ # ".net", # 3 # ], # [ # ".com", # 3 # ] # ] # ] # ] </pre></div> </div> <p>テーブル型を持つカラムに対してドリルダウンを行った場合、参照先のテーブルに存在するカラム値を取得することもできます。ドリルダウンを行ったテーブルには、_nsubrecsという仮想的なカラムが追加されます。このカラムには、グループ化されたレコード数が入ります。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select --table Site --limit 0 --drilldown domain --drilldown_output_columns _id,_key,_nsubrecs # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 9 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "_key", # "ShortText" # ], # [ # "country", # "SiteCountry" # ], # [ # "domain", # "SiteDomain" # ], # [ # "link", # "Site" # ], # [ # "links", # "Site" # ], # [ # "location", # "WGS84GeoPoint" # ], # [ # "title", # "ShortText" # ] # ] # ], # [ # [ # 3 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "_key", # "ShortText" # ], # [ # "_nsubrecs", # "Int32" # ] # ], # [ # 1, # ".org", # 3 # ], # [ # 2, # ".net", # 3 # ], # [ # 3, # ".com", # 3 # ] # ] # ] # ] </pre></div> </div> <p>複数のカラムに対してドリルダウンを行うことができます。複数のカラムに対してドリルダウンを行う場合には、drilldownパラメータにカラム名をカンマ区切りで与えます。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select --table Site --limit 0 --drilldown domain,country # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 9 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "_key", # "ShortText" # ], # [ # "country", # "SiteCountry" # ], # [ # "domain", # "SiteDomain" # ], # [ # "link", # "Site" # ], # [ # "links", # "Site" # ], # [ # "location", # "WGS84GeoPoint" # ], # [ # "title", # "ShortText" # ] # ] # ], # [ # [ # 3 # ], # [ # [ # "_key", # "ShortText" # ], # [ # "_nsubrecs", # "Int32" # ] # ], # [ # ".org", # 3 # ], # [ # ".net", # 3 # ], # [ # ".com", # 3 # ] # ], # [ # [ # 5 # ], # [ # [ # "_key", # "ShortText" # ], # [ # "_nsubrecs", # "Int32" # ] # ], # [ # "japan", # 3 # ], # [ # "brazil", # 1 # ], # [ # "usa", # 2 # ], # [ # "korea", # 1 # ], # [ # "china", # 2 # ] # ] # ] # ] </pre></div> </div> <p>ドリルダウン結果を並びかえることができます。例えば、_nsubrecsパラメータの降順で並び替えることができます。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select --table Site --limit 0 --drilldown country --drilldown_sortby _nsubrecs # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 9 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "_key", # "ShortText" # ], # [ # "country", # "SiteCountry" # ], # [ # "domain", # "SiteDomain" # ], # [ # "link", # "Site" # ], # [ # "links", # "Site" # ], # [ # "location", # "WGS84GeoPoint" # ], # [ # "title", # "ShortText" # ] # ] # ], # [ # [ # 5 # ], # [ # [ # "_key", # "ShortText" # ], # [ # "_nsubrecs", # "Int32" # ] # ], # [ # "brazil", # 1 # ], # [ # "korea", # 1 # ], # [ # "usa", # 2 # ], # [ # "china", # 2 # ], # [ # "japan", # 3 # ] # ] # ] # ] </pre></div> </div> <p>ドリルダウン結果は、デフォルトでは10件のみ表示されます。drilldown_offsetパラメータと、drilldown_limitパラメータによって、offsetとlimitを指定することができます。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select --table Site --limit 0 --drilldown country --drilldown_sortby _nsubrecs --drilldown_limit 2 --drilldown_offset 2 # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 9 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "_key", # "ShortText" # ], # [ # "country", # "SiteCountry" # ], # [ # "domain", # "SiteDomain" # ], # [ # "link", # "Site" # ], # [ # "links", # "Site" # ], # [ # "location", # "WGS84GeoPoint" # ], # [ # "title", # "ShortText" # ] # ] # ], # [ # [ # 5 # ], # [ # [ # "_key", # "ShortText" # ], # [ # "_nsubrecs", # "Int32" # ] # ], # [ # "usa", # 2 # ], # [ # "china", # 2 # ] # ] # ] # ] </pre></div> </div> <p>文字列型のカラムに対するドリルダウンは、他の型でのドリルダウンに比べて低速です。文字列でのドリルダウンを行いたい場合には、このチュートリアルのように、文字列型を主キーとするテーブルを別途作成し、そのテーブルを型とするカラムを作成します。</p> </div> </div> </div> </div> <div class="sphinxsidebar"> <div class="sphinxsidebarwrapper"> <h4>前のトピックへ</h4> <p class="topless"><a href="search.html" title="前の章へ">4.4. さまざまな検索条件の指定</a></p> <h4>次のトピックへ</h4> <p class="topless"><a href="index.html" title="次の章へ">4.6. タグ検索・参照関係の逆引き</a></p> <h3>このページ</h3> <ul class="this-page-menu"> <li><a href="../_sources/tutorial/drilldown.txt" rel="nofollow">ソースコードを表示</a></li> </ul> <div id="searchbox" style="display: none"> <h3>クイック検索</h3> <form class="search" action="../search.html" method="get"> <input type="text" name="q" /> <input type="submit" value="検索" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> <p class="searchtip" style="font-size: 90%"> モジュール、クラス、または関数名を入力してください </p> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> </div> <div class="clearer"></div> </div> <div class="related"> <h3>ナビゲーション</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="総合索引" >索引</a></li> <li class="right" > <a href="index.html" title="4.6. タグ検索・参照関係の逆引き" >次へ</a> |</li> <li class="right" > <a href="search.html" title="4.4. さまざまな検索条件の指定" >前へ</a> |</li> <li><a href="../index.html">groonga v3.0.5ドキュメント</a> »</li> <li><a href="../tutorial.html" >4. チュートリアル</a> »</li> </ul> </div> <div class="footer"> © Copyright 2009-2013, Brazil, Inc. </div> </body> </html>