<!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>8.12. インデックス構築 — 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="8. リファレンスマニュアル" href="../reference.html" /> <link rel="next" title="8.13. Log" href="log.html" /> <link rel="prev" title="8.11.10. sub_filter" href="functions/sub_filter.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/reference/indexing.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="log.html" title="8.13. Log" accesskey="N">次へ</a> |</li> <li class="right" > <a href="functions/sub_filter.html" title="8.11.10. sub_filter" accesskey="P">前へ</a> |</li> <li><a href="../index.html">groonga v3.0.5ドキュメント</a> »</li> <li><a href="../reference.html" accesskey="U">8. リファレンスマニュアル</a> »</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body"> <div class="section" id="indexing"> <h1>8.12. インデックス構築<a class="headerlink" href="#indexing" title="このヘッドラインへのパーマリンク">¶</a></h1> <p>groongaは2.0.0から動的なインデックス構築方法と静的なインデックス構築方法を両方サポートしています。</p> <div class="section" id="online-index-construction"> <h2>8.12.1. 動的なインデックス構築方法<a class="headerlink" href="#online-index-construction" title="このヘッドラインへのパーマリンク">¶</a></h2> <p>動的なインデックス構築方法では、登録された文書はインデックス構築中にすぐに検索できるようになります。しかし、静的なインデックス構築方法に比べてコストがかかります。</p> <p>動的なインデックス構築方法は鮮度が重要な検索システムに適しています。例えば、つぶやきやニュースやブログ記事などを検索するシステムは鮮度が重要になるでしょう。動的なインデックス構築方法はできたばかりの文書を検索できるようにし、インデックス構築中も検索できます。</p> </div> <div class="section" id="offline-index-construction"> <span id="id1"></span><h2>8.12.2. 静的なインデックス構築方法<a class="headerlink" href="#offline-index-construction" title="このヘッドラインへのパーマリンク">¶</a></h2> <p>静的なインデックス構築方法では、動的なインデックス構築方法よりもインデックス構築にかかるコストが小さくなります。インデックス構築時間は短くなるでしょう。インデックスは小さくなるでしょう。インデックス構築に必要なリソースは少なくなるでしょう。しかし、登録中の文書は登録しようとしている全ての文書のインデックス構築が終わるまで検索できません。</p> <p>静的なインデックス構築方法は消費リソースが少ないことが重要な検索システムに適しています。鮮度が重要でないシステムであれば静的なインデックス構築方法が適しているでしょう。例えば、リファレンスマニュアルを検索するシステムは鮮度を重視しません。これは、リファレンスマニュアルはリリース時にだけ更新されるだけだからです。</p> </div> <div class="section" id="how-to-use"> <h2>8.12.3. 使い方<a class="headerlink" href="#how-to-use" title="このヘッドラインへのパーマリンク">¶</a></h2> <p>groongaはデフォルトで動的なインデックス構築方法を使います。文書を登録するとすぐに検索できるようになります。</p> <p>すでにデータが格納されているカラムにインデックスを追加した場合は静的なインデックス構築方法を使います。</p> <p>スキーマを定義します。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>table_create Tweets TABLE_NO_KEY # [[0, 1337566253.89858, 0.000355720520019531], true] column_create Tweets content COLUMN_SCALAR ShortText # [[0, 1337566253.89858, 0.000355720520019531], true] table_create Lexicon TABLE_HASH_KEY|KEY_NORMALIZE ShortText --default_tokenizer TokenBigram # [[0, 1337566253.89858, 0.000355720520019531], true] </pre></div> </div> <p>データを登録します:</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>load --table Tweets [ {"content":"Hello!"}, {"content":"I just start it!"}, {"content":"I'm sleepy... Have a nice day... Good night..."} ] # [[0, 1337566253.89858, 0.000355720520019531], 3] </pre></div> </div> <p>インデックスなしで検索します。これは何もヒットしません:</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select Tweets --match_columns content --query 'good nice' # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 0 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "content", # "ShortText" # ] # ] # ] # ] # ] </pre></div> </div> <p><tt class="docutils literal"><span class="pre">Tweets.content</span></tt> 用のインデックスを作成します。すでに <tt class="docutils literal"><span class="pre">Tweets.content</span></tt> に登録されているデータは静的なインデックス構築方法でインデックスを構築します:</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>column_create Lexicon tweet COLUMN_INDEX|WITH_POSITION Tweets content # [[0, 1337566253.89858, 0.000355720520019531], true] </pre></div> </div> <p>インデックスありで検索します。1件ヒットします:</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select Tweets --match_columns content --query 'good nice' # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 1 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "content", # "ShortText" # ] # ], # [ # 3, # "I'm sleepy... Have a nice day... Good night..." # ] # ] # ] # ] </pre></div> </div> <p>もう一度データを登録します。このデータ用のインデックスは動的なインデックス構築方法で構築します。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>load --table Tweets [ {"content":"Good morning! Nice day."}, {"content":"Let's go shopping."} ] # [[0, 1337566253.89858, 0.000355720520019531], 2] </pre></div> </div> <p>検索すると新しく登録されたレコードもヒットします:</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select Tweets --match_columns content --query 'good nice' # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 2 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "content", # "ShortText" # ] # ], # [ # 3, # "I'm sleepy... Have a nice day... Good night..." # ], # [ # 4, # "Good morning! Nice day." # ] # ] # ] # ] </pre></div> </div> </div> </div> </div> </div> </div> <div class="sphinxsidebar"> <div class="sphinxsidebarwrapper"> <h3><a href="../index.html">目次</a></h3> <ul> <li><a class="reference internal" href="#">8.12. インデックス構築</a><ul> <li><a class="reference internal" href="#online-index-construction">8.12.1. 動的なインデックス構築方法</a></li> <li><a class="reference internal" href="#offline-index-construction">8.12.2. 静的なインデックス構築方法</a></li> <li><a class="reference internal" href="#how-to-use">8.12.3. 使い方</a></li> </ul> </li> </ul> <h4>前のトピックへ</h4> <p class="topless"><a href="functions/sub_filter.html" title="前の章へ">8.11.10. sub_filter</a></p> <h4>次のトピックへ</h4> <p class="topless"><a href="log.html" title="次の章へ">8.13. Log</a></p> <h3>このページ</h3> <ul class="this-page-menu"> <li><a href="../_sources/reference/indexing.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="log.html" title="8.13. Log" >次へ</a> |</li> <li class="right" > <a href="functions/sub_filter.html" title="8.11.10. sub_filter" >前へ</a> |</li> <li><a href="../index.html">groonga v3.0.5ドキュメント</a> »</li> <li><a href="../reference.html" >8. リファレンスマニュアル</a> »</li> </ul> </div> <div class="footer"> © Copyright 2009-2013, Brazil, Inc. </div> </body> </html>