<!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>5.3. 補完 — 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="5. サジェスト" href="../suggest.html" /> <link rel="next" title="5.4. 補正" href="correction.html" /> <link rel="prev" title="5.2. チュートリアル" href="tutorial.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/suggest/completion.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="correction.html" title="5.4. 補正" accesskey="N">次へ</a> |</li> <li class="right" > <a href="tutorial.html" title="5.2. チュートリアル" accesskey="P">前へ</a> |</li> <li><a href="../index.html">groonga v3.0.5ドキュメント</a> »</li> <li><a href="../suggest.html" accesskey="U">5. サジェスト</a> »</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body"> <div class="section" id="completion"> <h1>5.3. 補完<a class="headerlink" href="#completion" title="このヘッドラインへのパーマリンク">¶</a></h1> <p>このセクションでは以下の補完機能について説明します。:</p> <ul class="simple"> <li><p class="first">どのように動作するか</p> </li> <li><p class="first">使い方</p> </li> <li><p class="first">学習方法</p> </li> </ul> <div class="section" id="how-it-works"> <h2>5.3.1. どのように動作するか<a class="headerlink" href="#how-it-works" title="このヘッドラインへのパーマリンク">¶</a></h2> <p>補完機能は補完される語を計算するために3種類の検索を使います。</p> <blockquote> <div><ol class="arabic simple"> <li><p class="first">登録されている語を前方一致RK検索。</p> </li> <li><p class="first">学習したデータを共起検索。</p> </li> <li><p class="first">登録されている語を前方一致検索。(実行しないこともある)</p> </li> </ol> </div></blockquote> <div class="section" id="prefix-rk-search"> <h3>5.3.1.1. 前方一致RK検索<a class="headerlink" href="#prefix-rk-search" title="このヘッドラインへのパーマリンク">¶</a></h3> <p>RKはローマ字(Romaji)とカタカナ(Katakana)を意味しています。前方一致RK検索は登録されている語をユーザの入力から前方一致検索します。このとき、ユーザの入力はローマ字でもカタカナでもひらがなでも構いません。この機能は日本語を検索するときに便利です。</p> <p>例えば、"日本"という語が登録されているとします。そして、その読みとして"ニホン"(カタカナにしないといけません)が登録されているとします。このとき、ユーザの入力が"ni"でも"二"でも"に"でも"日本"を見つけることができます。</p> </div> <div class="section" id="cooccurrence-search"> <h3>5.3.1.2. 共起検索<a class="headerlink" href="#cooccurrence-search" title="このヘッドラインへのパーマリンク">¶</a></h3> <p>共起検索は入力途中のユーザのクエリから登録されている語を見つけます。共起検索では検索データベースとしてユーザの入力シーケンスを使います。これはクエリログやアクセスログなどから学習します。</p> <p>例えば、以下のようなユーザの入力シーケンスがあるとします。</p> <table border="1" class="docutils"> <colgroup> <col width="50%" /> <col width="50%" /> </colgroup> <thead valign="bottom"> <tr class="row-odd"><th class="head"><p class="first last">入力</p> </th> <th class="head"><p class="first last">検索実行</p> </th> </tr> </thead> <tbody valign="top"> <tr class="row-even"><td>s</td> <td><p class="first last">していない</p> </td> </tr> <tr class="row-odd"><td>se</td> <td><p class="first last">していない</p> </td> </tr> <tr class="row-even"><td>sea</td> <td><p class="first last">していない</p> </td> </tr> <tr class="row-odd"><td>sear</td> <td><p class="first last">していない</p> </td> </tr> <tr class="row-even"><td>searc</td> <td><p class="first last">していない</p> </td> </tr> <tr class="row-odd"><td>search</td> <td><p class="first last">した</p> </td> </tr> <tr class="row-even"><td>e</td> <td><p class="first last">していない</p> </td> </tr> <tr class="row-odd"><td>en</td> <td><p class="first last">していない</p> </td> </tr> <tr class="row-even"><td>eng</td> <td><p class="first last">していない</p> </td> </tr> <tr class="row-odd"><td>engi</td> <td><p class="first last">していない</p> </td> </tr> <tr class="row-even"><td>engin</td> <td><p class="first last">していない</p> </td> </tr> <tr class="row-odd"><td>engine</td> <td><p class="first last">していない</p> </td> </tr> <tr class="row-even"><td>enginen</td> <td><p class="first last">していない(入力ミス!)</p> </td> </tr> <tr class="row-odd"><td>engine</td> <td><p class="first last">した</p> </td> </tr> </tbody> </table> <p>groongaは以下のような補完ペアを作ります。:</p> <table border="1" class="docutils"> <colgroup> <col width="33%" /> <col width="67%" /> </colgroup> <thead valign="bottom"> <tr class="row-odd"><th class="head"><p class="first last">入力</p> </th> <th class="head"><p class="first last">補完語</p> </th> </tr> </thead> <tbody valign="top"> <tr class="row-even"><td>s</td> <td>search</td> </tr> <tr class="row-odd"><td>se</td> <td>search</td> </tr> <tr class="row-even"><td>sea</td> <td>search</td> </tr> <tr class="row-odd"><td>sear</td> <td>search</td> </tr> <tr class="row-even"><td>searc</td> <td>search</td> </tr> <tr class="row-odd"><td>e</td> <td>engine</td> </tr> <tr class="row-even"><td>en</td> <td>engine</td> </tr> <tr class="row-odd"><td>eng</td> <td>engine</td> </tr> <tr class="row-even"><td>engi</td> <td>engine</td> </tr> <tr class="row-odd"><td>engin</td> <td>engine</td> </tr> <tr class="row-even"><td>engine</td> <td>engine</td> </tr> <tr class="row-odd"><td>enginen</td> <td>engine</td> </tr> </tbody> </table> <p>ユーザが検索を実行する前のすべての入力(例では"s"、"se"など)を検索を実行した語(例では"search")に対応付けます。</p> <p>厳密に言うとこの説明は正しくありません。なぜならタイムスタンプに関することを省略しているからです。groongaは本当は「ユーザが検索を実行する前のすべての入力を」使いません。厳密には「ユーザが検索を実行する前の1分以内の入力のみ」を使います。検索実行時から1分より前の入力は使われません。</p> <p>ユーザが"sea"と入力したら、共起検索は"search"を返します。なぜなら、「入力」カラムには"sea"という値があり、対応する「補完語」カラムには"search"という値が入っているからです。</p> </div> <div class="section" id="prefix-search"> <h3>5.3.1.3. 前方一致検索<a class="headerlink" href="#prefix-search" title="このヘッドラインへのパーマリンク">¶</a></h3> <p>前方一致検索はユーザが入力した文字列から始まる登録済みの語を検索します。この検索は前方一致RK検索とは違ってローマ字、カタカナ、ひらがなを特別扱いしません。</p> <p>この検索はいつも実行されるわけではありません。この検索は明示的に実行するように指示するか、前方一致RK検索と共起検索の両方がなにもヒットしないときのみ実行されます。</p> <p>例えば、"search"が登録されているとします。ユーザは"s"、"se"、"sea"、"sear"、"searc"、"search"のどれでも"search"を補完候補として利用できます。</p> </div> </div> <div class="section" id="how-to-use"> <h2>5.3.2. 使い方<a class="headerlink" href="#how-to-use" title="このヘッドラインへのパーマリンク">¶</a></h2> <p>groongaは補完機能を使うために <a class="reference internal" href="../reference/commands/suggest.html"><em>suggest</em></a> コマンドを用意しています。 <cite>--type complete</cite> オプションを使うと補完機能を利用できます。</p> <p>例えば、"en"と入力したときの補完結果を取得するコマンドは以下のようになります。:</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>suggest --table item_query --column kana --types complete --frequency_threshold 1 --query en # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # { # "complete": [ # [ # 1 # ], # [ # [ # "_key", # "ShortText" # ], # [ # "_score", # "Int32" # ] # ], # [ # "engine", # 1 # ] # ] # } # ] </pre></div> </div> </div> <div class="section" id="how-it-learns"> <h2>5.3.3. 学習方法<a class="headerlink" href="#how-it-learns" title="このヘッドラインへのパーマリンク">¶</a></h2> <p>共起検索は学習データを使います。学習データはクエリログやアクセスログなどを元に作成します。学習データを作成するには、タイムスタンプ付きの入力シーケンスと、タイムスタンプ付きの検索実行時の入力内容が必要です。</p> <p>例えば、ユーザが"engine"で検索したいとします。ユーザが以下のようなシーケンスで検索クエリを入力したとします。:</p> <blockquote> <div><ol class="arabic simple"> <li>2011-08-10T13:33:23+09:00: e</li> <li>2011-08-10T13:33:23+09:00: en</li> <li>2011-08-10T13:33:24+09:00: eng</li> <li>2011-08-10T13:33:24+09:00: engi</li> <li>2011-08-10T13:33:24+09:00: engin</li> <li><p class="first">2011-08-10T13:33:25+09:00: engine (検索実行!)</p> </li> </ol> </div></blockquote> <p>以下のコマンドでこの入力シーケンスから学習できます。:</p> <div class="highlight-none"><div class="highlight"><pre>load --table event_query --each 'suggest_preparer(_id, type, item, sequence, time, pair_query)' [ {"sequence": "1", "time": 1312950803.86057, "item": "e"}, {"sequence": "1", "time": 1312950803.96857, "item": "en"}, {"sequence": "1", "time": 1312950804.26057, "item": "eng"}, {"sequence": "1", "time": 1312950804.56057, "item": "engi"}, {"sequence": "1", "time": 1312950804.76057, "item": "engin"}, {"sequence": "1", "time": 1312950805.86057, "item": "engine", "type": "submit"} ] </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="#">5.3. 補完</a><ul> <li><a class="reference internal" href="#how-it-works">5.3.1. どのように動作するか</a><ul> <li><a class="reference internal" href="#prefix-rk-search">5.3.1.1. 前方一致RK検索</a></li> <li><a class="reference internal" href="#cooccurrence-search">5.3.1.2. 共起検索</a></li> <li><a class="reference internal" href="#prefix-search">5.3.1.3. 前方一致検索</a></li> </ul> </li> <li><a class="reference internal" href="#how-to-use">5.3.2. 使い方</a></li> <li><a class="reference internal" href="#how-it-learns">5.3.3. 学習方法</a></li> </ul> </li> </ul> <h4>前のトピックへ</h4> <p class="topless"><a href="tutorial.html" title="前の章へ">5.2. チュートリアル</a></p> <h4>次のトピックへ</h4> <p class="topless"><a href="correction.html" title="次の章へ">5.4. 補正</a></p> <h3>このページ</h3> <ul class="this-page-menu"> <li><a href="../_sources/suggest/completion.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="correction.html" title="5.4. 補正" >次へ</a> |</li> <li class="right" > <a href="tutorial.html" title="5.2. チュートリアル" >前へ</a> |</li> <li><a href="../index.html">groonga v3.0.5ドキュメント</a> »</li> <li><a href="../suggest.html" >5. サジェスト</a> »</li> </ul> </div> <div class="footer"> © Copyright 2009-2013, Brazil, Inc. </div> </body> </html>