<!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.11.7. query — 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.11. 関数" href="../function.html" /> <link rel="next" title="8.11.8. rand" href="rand.html" /> <link rel="prev" title="8.11.6. now" href="now.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/functions/query.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="rand.html" title="8.11.8. rand" accesskey="N">次へ</a> |</li> <li class="right" > <a href="now.html" title="8.11.6. now" accesskey="P">前へ</a> |</li> <li><a href="../../index.html">groonga v3.0.5ドキュメント</a> »</li> <li><a href="../../reference.html" >8. リファレンスマニュアル</a> »</li> <li><a href="../function.html" accesskey="U">8.11. 関数</a> »</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body"> <div class="section" id="query"> <h1>8.11.7. query<a class="headerlink" href="#query" title="このヘッドラインへのパーマリンク">¶</a></h1> <div class="section" id="summary"> <h2>8.11.7.1. 概要<a class="headerlink" href="#summary" title="このヘッドラインへのパーマリンク">¶</a></h2> <p><tt class="docutils literal"><span class="pre">query</span></tt> は <tt class="docutils literal"><span class="pre">--match_columns</span></tt> と <tt class="docutils literal"><span class="pre">--query</span></tt> のパラメータを関数の引数として指定することを可能にします。</p> <p><tt class="docutils literal"><span class="pre">query</span></tt> はgroongaの組み込み関数の1つで、複数の <tt class="docutils literal"><span class="pre">query</span></tt> 関数を <tt class="docutils literal"><span class="pre">--filter</span></tt> オプションのパラメータとして指定することができます。</p> <p>そのような柔軟性があるので、 複数の <tt class="docutils literal"><span class="pre">query</span></tt> 関数を組合せることで全文検索の振舞いを制御することができます。</p> <p><tt class="docutils literal"><span class="pre">query</span></tt> は <a class="reference internal" href="../commands/select.html"><em>select</em></a> コマンドの <tt class="docutils literal"><span class="pre">--filter</span></tt> 内でのみ指定できます。</p> </div> <div class="section" id="syntax"> <h2>8.11.7.2. 構文<a class="headerlink" href="#syntax" title="このヘッドラインへのパーマリンク">¶</a></h2> <p><tt class="docutils literal"><span class="pre">query</span></tt> は2つの引数が必要です。 <tt class="docutils literal"><span class="pre">match_column</span></tt> と <tt class="docutils literal"><span class="pre">query_string</span></tt> です。</p> <p>引数の <tt class="docutils literal"><span class="pre">query_expander</span></tt> や <tt class="docutils literal"><span class="pre">substitution_table</span></tt> は省略可能です。</p> <div class="highlight-none"><div class="highlight"><pre>query(match_column, query_string) query(match_column, query_string, query_expander) query(match_column, query_string, substitution_table) </pre></div> </div> </div> <div class="section" id="usage"> <h2>8.11.7.3. 使い方<a class="headerlink" href="#usage" title="このヘッドラインへのパーマリンク">¶</a></h2> <p>使い方を示すために使うスキーマ定義とサンプルデータは以下の通りです。</p> <p>サンプルスキーマ:</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>table_create Documents TABLE_NO_KEY # [[0, 1337566253.89858, 0.000355720520019531], true] column_create Documents content COLUMN_SCALAR Text # [[0, 1337566253.89858, 0.000355720520019531], true] table_create Terms TABLE_PAT_KEY|KEY_NORMALIZE ShortText --default_tokenizer TokenBigram # [[0, 1337566253.89858, 0.000355720520019531], true] column_create Terms documents_content_index COLUMN_INDEX|WITH_POSITION Documents content # [[0, 1337566253.89858, 0.000355720520019531], true] table_create Users TABLE_NO_KEY # [[0, 1337566253.89858, 0.000355720520019531], true] column_create Users name COLUMN_SCALAR ShortText # [[0, 1337566253.89858, 0.000355720520019531], true] column_create Users memo COLUMN_SCALAR ShortText # [[0, 1337566253.89858, 0.000355720520019531], true] table_create Lexicon TABLE_HASH_KEY ShortText \ --default_tokenizer TokenBigramSplitSymbolAlphaDigit \ --normalizer NormalizerAuto column_create Lexicon users_name COLUMN_INDEX|WITH_POSITION Users name # [[0, 1337566253.89858, 0.000355720520019531], true] column_create Lexicon users_memo COLUMN_INDEX|WITH_POSITION Users memo # [[0, 1337566253.89858, 0.000355720520019531], true] </pre></div> </div> <p>サンプルデータ:</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>load --table Users [ {"name": "Alice", "memo": "groonga user"}, {"name": "Alisa", "memo": "mroonga user"}, {"name": "Bob", "memo": "rroonga user"}, {"name": "Tom", "memo": "nroonga user"}, {"name": "Tobby", "memo": "groonga and mroonga user. mroonga is ..."}, ] # [[0, 1337566253.89858, 0.000355720520019531], true] # [[0, 1337566253.89858, 0.000355720520019531], 5] </pre></div> </div> <p><tt class="docutils literal"><span class="pre">--match_columns</span></tt> と <tt class="docutils literal"><span class="pre">--query</span></tt> 引数を使わずにキーワード'alice'を <tt class="docutils literal"><span class="pre">query</span></tt> 関数を使って検索する簡単な使用例です。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select Users --output_columns name,_score --filter 'query("name * 10", "alice")' # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 1 # ], # [ # [ # "name", # "ShortText" # ], # [ # "_score", # "Int32" # ] # ], # [ # "Alice", # 10 # ] # ] # ] # ] </pre></div> </div> <p>上記のクエリを実行する際、'alice'というキーワードには重みづけとして値10を設定します。</p> <p><tt class="docutils literal"><span class="pre">query</span></tt> あり/なしで対照的な例がこちらです。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select Users --output_columns name,memo,_score --match_columns "memo * 10" --query "memo:@groonga OR memo:@mroonga OR memo:@user" --sortby -_score # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 5 # ], # [ # [ # "name", # "ShortText" # ], # [ # "memo", # "ShortText" # ], # [ # "_score", # "Int32" # ] # ], # [ # "Tobby", # "groonga and mroonga user. mroonga is ...", # 4 # ], # [ # "Alice", # "groonga user", # 2 # ], # [ # "Alisa", # "mroonga user", # 2 # ], # [ # "Bob", # "rroonga user", # 1 # ], # [ # "Tom", # "nroonga user", # 1 # ] # ] # ] # ] </pre></div> </div> <p>この場合、'groonga'と'mroonga'と'user'というキーワードは同じ重みづけがされています。この方法ではキーワードごとに異なる重みづけを行うことはできません。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select Users --output_columns name,memo,_score --filter 'query("memo * 10", "groonga") || query("memo * 20", "mroonga") || query("memo * 1", "user")' --sortby -_score # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 5 # ], # [ # [ # "name", # "ShortText" # ], # [ # "memo", # "ShortText" # ], # [ # "_score", # "Int32" # ] # ], # [ # "Tobby", # "groonga and mroonga user. mroonga is ...", # 51 # ], # [ # "Alisa", # "mroonga user", # 21 # ], # [ # "Alice", # "groonga user", # 11 # ], # [ # "Tom", # "nroonga user", # 1 # ], # [ # "Bob", # "rroonga user", # 1 # ] # ] # ] # ] </pre></div> </div> <p>一方、複数の <tt class="docutils literal"><span class="pre">query</span></tt> を指定することで、'groonga'と'mroonga'と'user'それぞれのキーワードに対し異なる重みづけを行えます。</p> <p>結果として、意図した様に異なる重みづけを行いつつ全文検索の振舞いを制御することができます。</p> </div> <div class="section" id="parameters"> <h2>8.11.7.4. 引数<a class="headerlink" href="#parameters" title="このヘッドラインへのパーマリンク">¶</a></h2> <div class="section" id="required-parameter"> <h3>8.11.7.4.1. 必須引数<a class="headerlink" href="#required-parameter" title="このヘッドラインへのパーマリンク">¶</a></h3> <p>必須引数は二つあります。 <tt class="docutils literal"><span class="pre">match_column</span></tt> と <tt class="docutils literal"><span class="pre">query_string</span></tt> です。</p> <div class="section" id="match-column"> <h4>8.11.7.4.1.1. <tt class="docutils literal"><span class="pre">match_column</span></tt><a class="headerlink" href="#match-column" title="このヘッドラインへのパーマリンク">¶</a></h4> <p>It specifies the default target column for fulltext search by <tt class="docutils literal"><span class="pre">query_string</span></tt> parameter value. It is the same role as <tt class="docutils literal"><span class="pre">match_column</span></tt> parameter in <tt class="docutils literal"><span class="pre">select</span></tt>.</p> <p><tt class="docutils literal"><span class="pre">select</span></tt> コマンドの <tt class="docutils literal"><span class="pre">match_column</span></tt> については <a class="reference internal" href="../commands/select.html#select-match-columns"><em>match_columns</em></a> を参照してください。</p> </div> <div class="section" id="query-string"> <h4>8.11.7.4.1.2. <tt class="docutils literal"><span class="pre">query_string</span></tt><a class="headerlink" href="#query-string" title="このヘッドラインへのパーマリンク">¶</a></h4> <p>It specifies the search condition in <a class="reference internal" href="../grn_expr/query_syntax.html"><em>クエリー構文</em></a>. It is the same role as <tt class="docutils literal"><span class="pre">query</span></tt> parameter in <tt class="docutils literal"><span class="pre">select</span></tt>.</p> <p><tt class="docutils literal"><span class="pre">select</span></tt> コマンドの <tt class="docutils literal"><span class="pre">query</span></tt> については <a class="reference internal" href="../commands/select.html#select-match-columns"><em>match_columns</em></a> を参照してください。</p> </div> </div> <div class="section" id="optional-parameter"> <h3>8.11.7.4.2. 省略可能引数<a class="headerlink" href="#optional-parameter" title="このヘッドラインへのパーマリンク">¶</a></h3> <p>いくつか省略可能な引数があります。</p> <div class="section" id="query-expander"> <h4>8.11.7.4.2.1. <tt class="docutils literal"><span class="pre">query_expander</span></tt><a class="headerlink" href="#query-expander" title="このヘッドラインへのパーマリンク">¶</a></h4> <p>クエリ展開に使うプラグイン名を指定します。</p> <p><a class="reference internal" href="../query_expanders/tsv.html"><em>QueryExpanderTSV</em></a> は公式リリースに含まれているプラグインの1つです。</p> <p>詳細については <a class="reference internal" href="../query_expanders/tsv.html"><em>QueryExpanderTSV</em></a> を参照してください。</p> </div> <div class="section" id="substitution-table"> <h4>8.11.7.4.2.2. <tt class="docutils literal"><span class="pre">置換テーブル</span></tt><a class="headerlink" href="#substitution-table" title="このヘッドラインへのパーマリンク">¶</a></h4> <p>置換テーブルとカラム名を <tt class="docutils literal"><span class="pre">${TABLE}.${COLUMN}</span></tt> という書式でクエリ展開のために指定します。</p> <p>詳細については <a class="reference internal" href="../commands/select.html#query-expander"><em>query_expander</em></a> を参照してください。</p> </div> </div> </div> <div class="section" id="return-value"> <h2>8.11.7.5. 戻り値<a class="headerlink" href="#return-value" title="このヘッドラインへのパーマリンク">¶</a></h2> <p><tt class="docutils literal"><span class="pre">query</span></tt> returns whether any record is matched or not. If one or more records are matched, it returns <tt class="docutils literal"><span class="pre">true</span></tt>. Otherwise, it returns <tt class="docutils literal"><span class="pre">false</span></tt>.</p> </div> <div class="section" id="todo"> <h2>8.11.7.6. TODO<a class="headerlink" href="#todo" title="このヘッドラインへのパーマリンク">¶</a></h2> <ul class="simple"> <li><p class="first">query_flagsのサポート</p> </li> </ul> </div> <div class="section" id="see-also"> <h2>8.11.7.7. 参考<a class="headerlink" href="#see-also" title="このヘッドラインへのパーマリンク">¶</a></h2> <ul class="simple"> <li><a class="reference internal" href="../commands/select.html"><em>select</em></a></li> </ul> </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.11.7. query</a><ul> <li><a class="reference internal" href="#summary">8.11.7.1. 概要</a></li> <li><a class="reference internal" href="#syntax">8.11.7.2. 構文</a></li> <li><a class="reference internal" href="#usage">8.11.7.3. 使い方</a></li> <li><a class="reference internal" href="#parameters">8.11.7.4. 引数</a><ul> <li><a class="reference internal" href="#required-parameter">8.11.7.4.1. 必須引数</a><ul> <li><a class="reference internal" href="#match-column">8.11.7.4.1.1. <tt class="docutils literal"><span class="pre">match_column</span></tt></a></li> <li><a class="reference internal" href="#query-string">8.11.7.4.1.2. <tt class="docutils literal"><span class="pre">query_string</span></tt></a></li> </ul> </li> <li><a class="reference internal" href="#optional-parameter">8.11.7.4.2. 省略可能引数</a><ul> <li><a class="reference internal" href="#query-expander">8.11.7.4.2.1. <tt class="docutils literal"><span class="pre">query_expander</span></tt></a></li> <li><a class="reference internal" href="#substitution-table">8.11.7.4.2.2. <tt class="docutils literal"><span class="pre">置換テーブル</span></tt></a></li> </ul> </li> </ul> </li> <li><a class="reference internal" href="#return-value">8.11.7.5. 戻り値</a></li> <li><a class="reference internal" href="#todo">8.11.7.6. TODO</a></li> <li><a class="reference internal" href="#see-also">8.11.7.7. 参考</a></li> </ul> </li> </ul> <h4>前のトピックへ</h4> <p class="topless"><a href="now.html" title="前の章へ">8.11.6. now</a></p> <h4>次のトピックへ</h4> <p class="topless"><a href="rand.html" title="次の章へ">8.11.8. rand</a></p> <h3>このページ</h3> <ul class="this-page-menu"> <li><a href="../../_sources/reference/functions/query.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="rand.html" title="8.11.8. rand" >次へ</a> |</li> <li class="right" > <a href="now.html" title="8.11.6. now" >前へ</a> |</li> <li><a href="../../index.html">groonga v3.0.5ドキュメント</a> »</li> <li><a href="../../reference.html" >8. リファレンスマニュアル</a> »</li> <li><a href="../function.html" >8.11. 関数</a> »</li> </ul> </div> <div class="footer"> © Copyright 2009-2013, Brazil, Inc. </div> </body> </html>