Sophie

Sophie

distrib > Fedora > 18 > x86_64 > media > updates > by-pkgid > e450e7f3d6075c4a54de19e68d38177f > files > 341

groonga-doc-3.0.5-1.fc18.x86_64.rpm


<!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. ドリルダウン &mdash; groonga v3.0.5 documentation</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>
    <link rel="shortcut icon" href="../_static/favicon.ico"/>
    <link rel="top" title="groonga v3.0.5 documentation" href="../index.html" />
    <link rel="up" title="4. Tutorial" 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">An open-source fulltext search engine and column store.</span>
    </a>
  </h1>

  <div class="other-language-links">
    <ul>
      <li><a href="../../../ja/html/tutorial/drilldown.html"><img src="../_static/jp.png" alt="日本語">日本語版はこちら</a></li>
    </ul>
  </div>
</div>
  

    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="index.html" title="4.6. タグ検索・参照関係の逆引き"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="search.html" title="4.4. さまざまな検索条件の指定"
             accesskey="P">previous</a> |</li>
        <li><a href="../index.html">groonga v3.0.5 documentation</a> &raquo;</li>
          <li><a href="../tutorial.html" accesskey="U">4. Tutorial</a> &raquo;</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="Permalink to this headline">¶</a></h1>
<p>groongaでは、特定のカラム値で検索結果をグループ化することができます。これをドリルダウンと呼びます。</p>
<p>Siteテーブルに2つのカラムを追加します。TLDドメイン名を格納するdomainカラムと、国名を格納するcountryカラムです。これらのカラムの型は、それぞれドメイン名を主キーとするSiteDomainテーブルと、国名を主キーとするSiteCountryテーブルとします。</p>
<p>Execution example:</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
[
{&quot;_key&quot;:&quot;http://example.org/&quot;,&quot;domain&quot;:&quot;.org&quot;,&quot;country&quot;:&quot;japan&quot;},
{&quot;_key&quot;:&quot;http://example.net/&quot;,&quot;domain&quot;:&quot;.net&quot;,&quot;country&quot;:&quot;brazil&quot;},
{&quot;_key&quot;:&quot;http://example.com/&quot;,&quot;domain&quot;:&quot;.com&quot;,&quot;country&quot;:&quot;japan&quot;},
{&quot;_key&quot;:&quot;http://example.net/afr&quot;,&quot;domain&quot;:&quot;.net&quot;,&quot;country&quot;:&quot;usa&quot;},
{&quot;_key&quot;:&quot;http://example.org/aba&quot;,&quot;domain&quot;:&quot;.org&quot;,&quot;country&quot;:&quot;korea&quot;},
{&quot;_key&quot;:&quot;http://example.com/rab&quot;,&quot;domain&quot;:&quot;.com&quot;,&quot;country&quot;:&quot;china&quot;},
{&quot;_key&quot;:&quot;http://example.net/atv&quot;,&quot;domain&quot;:&quot;.net&quot;,&quot;country&quot;:&quot;china&quot;},
{&quot;_key&quot;:&quot;http://example.org/gat&quot;,&quot;domain&quot;:&quot;.org&quot;,&quot;country&quot;:&quot;usa&quot;},
{&quot;_key&quot;:&quot;http://example.com/vdw&quot;,&quot;domain&quot;:&quot;.com&quot;,&quot;country&quot;:&quot;japan&quot;}
]
# [[0, 1337566253.89858, 0.000355720520019531], 9]
</pre></div>
</div>
<p>domainカラムとcountryカラムでドリルダウンを行う例を以下に示します。</p>
<p>Execution example:</p>
<div class="highlight-none"><div class="highlight"><pre>select --table Site --limit 0 --drilldown domain
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         9
#       ],
#       [
#         [
#           &quot;_id&quot;,
#           &quot;UInt32&quot;
#         ],
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;country&quot;,
#           &quot;SiteCountry&quot;
#         ],
#         [
#           &quot;domain&quot;,
#           &quot;SiteDomain&quot;
#         ],
#         [
#           &quot;link&quot;,
#           &quot;Site&quot;
#         ],
#         [
#           &quot;links&quot;,
#           &quot;Site&quot;
#         ],
#         [
#           &quot;location&quot;,
#           &quot;WGS84GeoPoint&quot;
#         ],
#         [
#           &quot;title&quot;,
#           &quot;ShortText&quot;
#         ]
#       ]
#     ],
#     [
#       [
#         3
#       ],
#       [
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;_nsubrecs&quot;,
#           &quot;Int32&quot;
#         ]
#       ],
#       [
#         &quot;.org&quot;,
#         3
#       ],
#       [
#         &quot;.net&quot;,
#         3
#       ],
#       [
#         &quot;.com&quot;,
#         3
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>テーブル型を持つカラムに対してドリルダウンを行った場合、参照先のテーブルに存在するカラム値を取得することもできます。ドリルダウンを行ったテーブルには、_nsubrecsという仮想的なカラムが追加されます。このカラムには、グループ化されたレコード数が入ります。</p>
<p>Execution example:</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
#       ],
#       [
#         [
#           &quot;_id&quot;,
#           &quot;UInt32&quot;
#         ],
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;country&quot;,
#           &quot;SiteCountry&quot;
#         ],
#         [
#           &quot;domain&quot;,
#           &quot;SiteDomain&quot;
#         ],
#         [
#           &quot;link&quot;,
#           &quot;Site&quot;
#         ],
#         [
#           &quot;links&quot;,
#           &quot;Site&quot;
#         ],
#         [
#           &quot;location&quot;,
#           &quot;WGS84GeoPoint&quot;
#         ],
#         [
#           &quot;title&quot;,
#           &quot;ShortText&quot;
#         ]
#       ]
#     ],
#     [
#       [
#         3
#       ],
#       [
#         [
#           &quot;_id&quot;,
#           &quot;UInt32&quot;
#         ],
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;_nsubrecs&quot;,
#           &quot;Int32&quot;
#         ]
#       ],
#       [
#         1,
#         &quot;.org&quot;,
#         3
#       ],
#       [
#         2,
#         &quot;.net&quot;,
#         3
#       ],
#       [
#         3,
#         &quot;.com&quot;,
#         3
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>複数のカラムに対してドリルダウンを行うことができます。複数のカラムに対してドリルダウンを行う場合には、drilldownパラメータにカラム名をカンマ区切りで与えます。</p>
<p>Execution example:</p>
<div class="highlight-none"><div class="highlight"><pre>select --table Site --limit 0 --drilldown domain,country
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         9
#       ],
#       [
#         [
#           &quot;_id&quot;,
#           &quot;UInt32&quot;
#         ],
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;country&quot;,
#           &quot;SiteCountry&quot;
#         ],
#         [
#           &quot;domain&quot;,
#           &quot;SiteDomain&quot;
#         ],
#         [
#           &quot;link&quot;,
#           &quot;Site&quot;
#         ],
#         [
#           &quot;links&quot;,
#           &quot;Site&quot;
#         ],
#         [
#           &quot;location&quot;,
#           &quot;WGS84GeoPoint&quot;
#         ],
#         [
#           &quot;title&quot;,
#           &quot;ShortText&quot;
#         ]
#       ]
#     ],
#     [
#       [
#         3
#       ],
#       [
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;_nsubrecs&quot;,
#           &quot;Int32&quot;
#         ]
#       ],
#       [
#         &quot;.org&quot;,
#         3
#       ],
#       [
#         &quot;.net&quot;,
#         3
#       ],
#       [
#         &quot;.com&quot;,
#         3
#       ]
#     ],
#     [
#       [
#         5
#       ],
#       [
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;_nsubrecs&quot;,
#           &quot;Int32&quot;
#         ]
#       ],
#       [
#         &quot;japan&quot;,
#         3
#       ],
#       [
#         &quot;brazil&quot;,
#         1
#       ],
#       [
#         &quot;usa&quot;,
#         2
#       ],
#       [
#         &quot;korea&quot;,
#         1
#       ],
#       [
#         &quot;china&quot;,
#         2
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>ドリルダウン結果を並びかえることができます。例えば、_nsubrecsパラメータの降順で並び替えることができます。</p>
<p>Execution example:</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
#       ],
#       [
#         [
#           &quot;_id&quot;,
#           &quot;UInt32&quot;
#         ],
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;country&quot;,
#           &quot;SiteCountry&quot;
#         ],
#         [
#           &quot;domain&quot;,
#           &quot;SiteDomain&quot;
#         ],
#         [
#           &quot;link&quot;,
#           &quot;Site&quot;
#         ],
#         [
#           &quot;links&quot;,
#           &quot;Site&quot;
#         ],
#         [
#           &quot;location&quot;,
#           &quot;WGS84GeoPoint&quot;
#         ],
#         [
#           &quot;title&quot;,
#           &quot;ShortText&quot;
#         ]
#       ]
#     ],
#     [
#       [
#         5
#       ],
#       [
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;_nsubrecs&quot;,
#           &quot;Int32&quot;
#         ]
#       ],
#       [
#         &quot;brazil&quot;,
#         1
#       ],
#       [
#         &quot;korea&quot;,
#         1
#       ],
#       [
#         &quot;usa&quot;,
#         2
#       ],
#       [
#         &quot;china&quot;,
#         2
#       ],
#       [
#         &quot;japan&quot;,
#         3
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>ドリルダウン結果は、デフォルトでは10件のみ表示されます。drilldown_offsetパラメータと、drilldown_limitパラメータによって、offsetとlimitを指定することができます。</p>
<p>Execution example:</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
#       ],
#       [
#         [
#           &quot;_id&quot;,
#           &quot;UInt32&quot;
#         ],
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;country&quot;,
#           &quot;SiteCountry&quot;
#         ],
#         [
#           &quot;domain&quot;,
#           &quot;SiteDomain&quot;
#         ],
#         [
#           &quot;link&quot;,
#           &quot;Site&quot;
#         ],
#         [
#           &quot;links&quot;,
#           &quot;Site&quot;
#         ],
#         [
#           &quot;location&quot;,
#           &quot;WGS84GeoPoint&quot;
#         ],
#         [
#           &quot;title&quot;,
#           &quot;ShortText&quot;
#         ]
#       ]
#     ],
#     [
#       [
#         5
#       ],
#       [
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;_nsubrecs&quot;,
#           &quot;Int32&quot;
#         ]
#       ],
#       [
#         &quot;usa&quot;,
#         2
#       ],
#       [
#         &quot;china&quot;,
#         2
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>文字列型のカラムに対するドリルダウンは、他の型でのドリルダウンに比べて低速です。文字列でのドリルダウンを行いたい場合には、このチュートリアルのように、文字列型を主キーとするテーブルを別途作成し、そのテーブルを型とするカラムを作成します。</p>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h4>Previous topic</h4>
  <p class="topless"><a href="search.html"
                        title="previous chapter">4.4. さまざまな検索条件の指定</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="index.html"
                        title="next chapter">4.6. タグ検索・参照関係の逆引き</a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="../_sources/tutorial/drilldown.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="index.html" title="4.6. タグ検索・参照関係の逆引き"
             >next</a> |</li>
        <li class="right" >
          <a href="search.html" title="4.4. さまざまな検索条件の指定"
             >previous</a> |</li>
        <li><a href="../index.html">groonga v3.0.5 documentation</a> &raquo;</li>
          <li><a href="../tutorial.html" >4. Tutorial</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2009-2013, Brazil, Inc.
    </div>
  </body>
</html>