Sophie

Sophie

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

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.11. クエリ拡張 &mdash; 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="5. サジェスト" href="../suggest.html" />
    <link rel="prev" title="4.10. マイクロブログ検索システムの作成" href="micro_blog.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/query_expansion.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="../suggest.html" title="5. サジェスト"
             accesskey="N">次へ</a> |</li>
        <li class="right" >
          <a href="micro_blog.html" title="4.10. マイクロブログ検索システムの作成"
             accesskey="P">前へ</a> |</li>
        <li><a href="../index.html">groonga v3.0.5ドキュメント</a> &raquo;</li>
          <li><a href="../tutorial.html" accesskey="U">4. チュートリアル</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="id1">
<h1>4.11. クエリ拡張<a class="headerlink" href="#id1" title="このヘッドラインへのパーマリンク">¶</a></h1>
<p>groongaでは、 <a class="reference internal" href="../reference/commands/select.html"><em>select</em></a> コマンドにquery_expanderパラメータを指定することによって、ユーザが指定した検索文字列を適宜拡張することが可能です。</p>
<p>たとえば、ユーザが'シークヮーサー'という文字列で検索した場合に、'シークヮーサー OR シークァーサー'で検索した場合と同一の結果を返すことによって、本来ユーザが必要とする結果をよりもれなく検索できるようになります。</p>
<div class="section" id="id2">
<h2>4.11.1. 準備<a class="headerlink" href="#id2" title="このヘッドラインへのパーマリンク">¶</a></h2>
<p>クエリ拡張機能を使用するためには、検索対象となる文書を格納するテーブル(ここでは文書テーブルと呼びます)以外に、ユーザの指定した検索文字列を置換するためのテーブル(ここでは置換テーブルと呼びます)を準備します。置換テーブルでは、その主キーが置換前の文字列となり、文字列型(ShortText)のカラムの値が置換後の文字列となります。</p>
<p>TODO: 文字列型のベクターカラムでも可能であり、その場合は各要素をORでつなげたものに置換されるということを記述する。</p>
<p>実際に文書テーブルと置換テーブルを作成してみましょう。</p>
<p>実行例:</p>
<div class="highlight-none"><div class="highlight"><pre>table_create Doc TABLE_PAT_KEY ShortText
# [[0, 1337566253.89858, 0.000355720520019531], true]
column_create Doc body COLUMN_SCALAR ShortText
# [[0, 1337566253.89858, 0.000355720520019531], true]
table_create Term TABLE_PAT_KEY|KEY_NORMALIZE ShortText --default_tokenizer TokenBigram
# [[0, 1337566253.89858, 0.000355720520019531], true]
column_create Term Doc_body COLUMN_INDEX|WITH_POSITION Doc body
# [[0, 1337566253.89858, 0.000355720520019531], true]
table_create Synonym TABLE_PAT_KEY ShortText
# [[0, 1337566253.89858, 0.000355720520019531], true]
column_create Synonym body COLUMN_SCALAR ShortText
# [[0, 1337566253.89858, 0.000355720520019531], true]
load --table Doc
[
{&quot;_key&quot;: &quot;001&quot;, &quot;body&quot;: &quot;すっぱいブドウと甘いシークァーサー&quot;},
{&quot;_key&quot;: &quot;002&quot;, &quot;body&quot;: &quot;シークヮーサージュースとゴーヤチャンプル&quot;},
]
# [[0, 1337566253.89858, 0.000355720520019531], 2]
load --table Synonym
[
{&quot;_key&quot;: &quot;シークァーサー&quot;, &quot;body&quot;: &quot;(シークァーサー OR シークヮーサー)&quot;},
{&quot;_key&quot;: &quot;シークヮーサー&quot;, &quot;body&quot;: &quot;(シークァーサー OR シークヮーサー)&quot;},
]
# [[0, 1337566253.89858, 0.000355720520019531], 2]
</pre></div>
</div>
<p>この例では、ユーザが&quot;シークァーサー&quot;と入力しても、&quot;シークヮーサー&quot;と入力しても、それぞれの異なる表記の文書をもれなく検索するための置換テーブルを作成しています。</p>
</div>
<div class="section" id="id3">
<h2>4.11.2. 検索<a class="headerlink" href="#id3" title="このヘッドラインへのパーマリンク">¶</a></h2>
<p>それでは実際に、準備した置換テーブルを使ってみましょう。まずは、query_expanderパラメータを指定せずにselectコマンドを使って検索してみます。</p>
<p>実行例:</p>
<div class="highlight-none"><div class="highlight"><pre>select Doc --match_columns body --query &quot;シークァーサー&quot;
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         1
#       ],
#       [
#         [
#           &quot;_id&quot;,
#           &quot;UInt32&quot;
#         ],
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;body&quot;,
#           &quot;ShortText&quot;
#         ]
#       ],
#       [
#         1,
#         &quot;001&quot;,
#         &quot;すっぱいブドウと甘いシークァーサー&quot;
#       ]
#     ]
#   ]
# ]
select Doc --match_columns body --query &quot;シークヮーサー&quot;
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         1
#       ],
#       [
#         [
#           &quot;_id&quot;,
#           &quot;UInt32&quot;
#         ],
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;body&quot;,
#           &quot;ShortText&quot;
#         ]
#       ],
#       [
#         2,
#         &quot;002&quot;,
#         &quot;シークヮーサージュースとゴーヤチャンプル&quot;
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>指定された文字列に完全に一致するレコードのみがそれぞれヒットします。次に、query_expanderパラメータに、準備したSynonymテーブルのbodyカラムを指定してみましょう。</p>
<p>実行例:</p>
<div class="highlight-none"><div class="highlight"><pre>select Doc --match_columns body --query &quot;シークァーサー&quot; --query_expander Synonym.body
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         2
#       ],
#       [
#         [
#           &quot;_id&quot;,
#           &quot;UInt32&quot;
#         ],
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;body&quot;,
#           &quot;ShortText&quot;
#         ]
#       ],
#       [
#         1,
#         &quot;001&quot;,
#         &quot;すっぱいブドウと甘いシークァーサー&quot;
#       ],
#       [
#         2,
#         &quot;002&quot;,
#         &quot;シークヮーサージュースとゴーヤチャンプル&quot;
#       ]
#     ]
#   ]
# ]
select Doc --match_columns body --query &quot;シークヮーサー&quot; --query_expander Synonym.body
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         2
#       ],
#       [
#         [
#           &quot;_id&quot;,
#           &quot;UInt32&quot;
#         ],
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;body&quot;,
#           &quot;ShortText&quot;
#         ]
#       ],
#       [
#         1,
#         &quot;001&quot;,
#         &quot;すっぱいブドウと甘いシークァーサー&quot;
#       ],
#       [
#         2,
#         &quot;002&quot;,
#         &quot;シークヮーサージュースとゴーヤチャンプル&quot;
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>どちらのクエリ文字列も、&quot;(シークァーサー OR シークヮーサー)&quot;という文字列に置換されてから検索されるため、表記の揺れを吸収して検索できるようになりました。</p>
</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="#">4.11. クエリ拡張</a><ul>
<li><a class="reference internal" href="#id2">4.11.1. 準備</a></li>
<li><a class="reference internal" href="#id3">4.11.2. 検索</a></li>
</ul>
</li>
</ul>

  <h4>前のトピックへ</h4>
  <p class="topless"><a href="micro_blog.html"
                        title="前の章へ">4.10. マイクロブログ検索システムの作成</a></p>
  <h4>次のトピックへ</h4>
  <p class="topless"><a href="../suggest.html"
                        title="次の章へ">5. サジェスト</a></p>
  <h3>このページ</h3>
  <ul class="this-page-menu">
    <li><a href="../_sources/tutorial/query_expansion.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="../suggest.html" title="5. サジェスト"
             >次へ</a> |</li>
        <li class="right" >
          <a href="micro_blog.html" title="4.10. マイクロブログ検索システムの作成"
             >前へ</a> |</li>
        <li><a href="../index.html">groonga v3.0.5ドキュメント</a> &raquo;</li>
          <li><a href="../tutorial.html" >4. チュートリアル</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2009-2013, Brazil, Inc.
    </div>
  </body>
</html>