<!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.3.22. select — 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.3. コマンド" href="../command.html" /> <link rel="next" title="8.3.23. shutdown" href="shutdown.html" /> <link rel="prev" title="8.3.21. register" href="register.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/commands/select.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="shutdown.html" title="8.3.23. shutdown" accesskey="N">次へ</a> |</li> <li class="right" > <a href="register.html" title="8.3.21. register" 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="../command.html" accesskey="U">8.3. コマンド</a> »</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body"> <div class="section" id="select"> <h1>8.3.22. <tt class="docutils literal"><span class="pre">select</span></tt><a class="headerlink" href="#select" title="このヘッドラインへのパーマリンク">¶</a></h1> <div class="section" id="summary"> <h2>8.3.22.1. 概要<a class="headerlink" href="#summary" title="このヘッドラインへのパーマリンク">¶</a></h2> <p><tt class="docutils literal"><span class="pre">select</span></tt> はテーブルから指定された条件にマッチするレコードを検索し、見つかったレコードを出力します。</p> <p><tt class="docutils literal"><span class="pre">select</span></tt> は最も重要なgroongaのコマンドです。groongaの力を最大限に活かすためには <tt class="docutils literal"><span class="pre">select</span></tt> を理解する必要があります。</p> </div> <div class="section" id="syntax"> <h2>8.3.22.2. 構文<a class="headerlink" href="#syntax" title="このヘッドラインへのパーマリンク">¶</a></h2> <p><tt class="docutils literal"><span class="pre">select</span></tt> には多くの引数があります。必須の引数は <tt class="docutils literal"><span class="pre">table</span></tt> だけで、残りは省略できます。:</p> <div class="highlight-none"><div class="highlight"><pre>select table [match_columns=null] [query=null] [filter=null] [scorer=null] [sortby=null] [output_columns="_id, _key, *"] [offset=0] [limit=10] [drilldown=null] [drilldown_sortby=null] [drilldown_output_columns=null] [drilldown_offset=0] [drilldown_limit=10] [cache=yes] [match_escalation_threshold=0] [query_expansion=null] [query_flags=ALLOW_PRAGMA|ALLOW_COLUMN|ALLOW_UPDATE|ALLOW_LEADING_NOT|NONE] [query_expander=null] </pre></div> </div> </div> <div class="section" id="usage"> <h2>8.3.22.3. 使い方<a class="headerlink" href="#usage" title="このヘッドラインへのパーマリンク">¶</a></h2> <p>例を使いながら <tt class="docutils literal"><span class="pre">select</span></tt> の使い方を学びましょう。このセクションではよく使われる使い方を紹介します。</p> <p>使い方を示すために使うスキーマ定義とサンプルデータは以下の通りです。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>table_create Entries TABLE_HASH_KEY ShortText # [[0, 1337566253.89858, 0.000355720520019531], true] column_create Entries content COLUMN_SCALAR Text # [[0, 1337566253.89858, 0.000355720520019531], true] column_create Entries n_likes COLUMN_SCALAR UInt32 # [[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 entries_key_index COLUMN_INDEX|WITH_POSITION Entries _key # [[0, 1337566253.89858, 0.000355720520019531], true] column_create Terms entries_content_index COLUMN_INDEX|WITH_POSITION Entries content # [[0, 1337566253.89858, 0.000355720520019531], true] load --table Entries [ {"_key": "The first post!", "content": "Welcome! This is my first post!", "n_likes": 5}, {"_key": "Groonga", "content": "I started to use groonga. It's very fast!", "n_likes": 10}, {"_key": "Mroonga", "content": "I also started to use mroonga. It's also very fast! Really fast!", "n_likes": 15}, {"_key": "Good-bye Senna", "content": "I migrated all Senna system!", "n_likes": 3}, {"_key": "Good-bye Tritonn", "content": "I also migrated all Tritonn system!", "n_likes": 3} ] # [[0, 1337566253.89858, 0.000355720520019531], 5] </pre></div> </div> <p>ブログエントリ用の <tt class="docutils literal"><span class="pre">Entries</span></tt> テーブルがあります。各エントリはタイトルと内容と「いいね!」数を持っています。タイトルは <tt class="docutils literal"><span class="pre">Entries</span></tt> のキーとします。内容は <tt class="docutils literal"><span class="pre">Entries.content</span></tt> カラムの値とします。「いいね!」数は <tt class="docutils literal"><span class="pre">Entries.n_likes</span></tt> カラムの値とします。</p> <p><tt class="docutils literal"><span class="pre">Entries._key</span></tt> カラムと <tt class="docutils literal"><span class="pre">Entries.content</span></tt> カラムには <tt class="docutils literal"><span class="pre">TokenBigram</span></tt> トークナイザーを使ったインデックスを作成します。そのため、 <tt class="docutils literal"><span class="pre">Entries._key</span></tt> と <tt class="docutils literal"><span class="pre">Entries.content</span></tt> は両方とも全文検索できます。</p> <p>これで例を示すためのスキーマとデータの準備ができました。</p> <div class="section" id="simple-usage"> <h3>8.3.22.3.1. 簡単な使い方<a class="headerlink" href="#simple-usage" title="このヘッドラインへのパーマリンク">¶</a></h3> <p>上記のスキーマとデータを使った一番簡単な使い方は以下の通りです。これは <tt class="docutils literal"><span class="pre">Entries</span></tt> テーブルのすべてのレコードを出力します。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select Entries # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 5 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "_key", # "ShortText" # ], # [ # "content", # "Text" # ], # [ # "n_likes", # "UInt32" # ] # ], # [ # 1, # "The first post!", # "Welcome! This is my first post!", # 5 # ], # [ # 2, # "Groonga", # "I started to use groonga. It's very fast!", # 10 # ], # [ # 3, # "Mroonga", # "I also started to use mroonga. It's also very fast! Really fast!", # 15 # ], # [ # 4, # "Good-bye Senna", # "I migrated all Senna system!", # 3 # ], # [ # 5, # "Good-bye Tritonn", # "I also migrated all Tritonn system!", # 3 # ] # ] # ] # ] </pre></div> </div> <p>どうしてこのコマンドがすべてのレコードを出力するのでしょうか?理由は2つです。1つ目の理由はこのコマンドが検索条件を何も指定していないからです。検索条件を指定しないとすべてのレコードがマッチします。2つ目の理由は全レコード数が5だからです。 <tt class="docutils literal"><span class="pre">select</span></tt> コマンドはデフォルトでは最大10レコードを出力します。この例では5レコードしかありません。これは10よりも少ないのですべてのレコードを出力します。</p> </div> <div class="section" id="search-conditions"> <h3>8.3.22.3.2. 検索条件<a class="headerlink" href="#search-conditions" title="このヘッドラインへのパーマリンク">¶</a></h3> <p>検索条件は <tt class="docutils literal"><span class="pre">query</span></tt> または <tt class="docutils literal"><span class="pre">filter</span></tt> で指定します。 <tt class="docutils literal"><span class="pre">query</span></tt> と <tt class="docutils literal"><span class="pre">filter</span></tt> を両方指定することもできます。この場合は <tt class="docutils literal"><span class="pre">query</span></tt> と <tt class="docutils literal"><span class="pre">filter</span></tt> の両方の条件にマッチしたレコードが出力されます。</p> <div class="section" id="search-condition-query"> <h4>8.3.22.3.2.1. 検索条件: <tt class="docutils literal"><span class="pre">query</span></tt><a class="headerlink" href="#search-condition-query" title="このヘッドラインへのパーマリンク">¶</a></h4> <p><tt class="docutils literal"><span class="pre">query</span></tt> はWebページの検索ボックス用に用意されています。例えば、google.co.jpにあるような検索ボックスです。 <tt class="docutils literal"><span class="pre">query</span></tt> の検索条件はスペース区切りでキーワードを指定します。例えば、 <tt class="docutils literal"><span class="pre">検索</span> <span class="pre">エンジン</span></tt> は <tt class="docutils literal"><span class="pre">検索</span></tt> と <tt class="docutils literal"><span class="pre">エンジン</span></tt> という2つのキーワードを含むレコードを検索します。</p> <p>通常は <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> 引数で全文検索条件を指定する場合は、 <tt class="docutils literal"><span class="pre">match_columns</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> の使用例です。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select Entries --match_columns content --query fast # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 2 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "_key", # "ShortText" # ], # [ # "content", # "Text" # ], # [ # "n_likes", # "UInt32" # ] # ], # [ # 2, # "Groonga", # "I started to use groonga. It's very fast!", # 10 # ], # [ # 3, # "Mroonga", # "I also started to use mroonga. It's also very fast! Really fast!", # 15 # ] # ] # ] # ] </pre></div> </div> <p>この <tt class="docutils literal"><span class="pre">select</span></tt> コマンドは <tt class="docutils literal"><span class="pre">Entries</span></tt> テーブルの中から <tt class="docutils literal"><span class="pre">content</span></tt> カラムの値に <tt class="docutils literal"><span class="pre">fast</span></tt> を含んでいるレコードを検索します。</p> <p><tt class="docutils literal"><span class="pre">query</span></tt> はクエリー構文という構文を使いますが、詳細はここでは説明しません。詳細は <a class="reference internal" href="../grn_expr/query_syntax.html"><em>クエリー構文</em></a> を参照してください。</p> </div> <div class="section" id="search-condition-filter"> <h4>8.3.22.3.2.2. 検索条件: <tt class="docutils literal"><span class="pre">filter</span></tt><a class="headerlink" href="#search-condition-filter" title="このヘッドラインへのパーマリンク">¶</a></h4> <p><tt class="docutils literal"><span class="pre">filter</span></tt> は複雑な検索条件を指定するために用意されています。ECMAScriptのような構文で <tt class="docutils literal"><span class="pre">filter</span></tt> に検索条件を指定します。</p> <p>以下は簡単な <tt class="docutils literal"><span class="pre">filter</span></tt> の使用例です。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select Entries --filter 'content @ "fast" && _key == "Groonga"' # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 1 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "_key", # "ShortText" # ], # [ # "content", # "Text" # ], # [ # "n_likes", # "UInt32" # ] # ], # [ # 2, # "Groonga", # "I started to use groonga. It's very fast!", # 10 # ] # ] # ] # ] </pre></div> </div> <p>この <tt class="docutils literal"><span class="pre">select</span></tt> コマンドは <tt class="docutils literal"><span class="pre">Entries</span></tt> テーブルの中の <tt class="docutils literal"><span class="pre">content</span></tt> カラムの値に <tt class="docutils literal"><span class="pre">fast</span></tt> という単語を含んでいて、かつ、 <tt class="docutils literal"><span class="pre">_key</span></tt> が <tt class="docutils literal"><span class="pre">Groonga</span></tt> のレコードを検索します。このコマンドの中には <tt class="docutils literal"><span class="pre">@</span></tt> と <tt class="docutils literal"><span class="pre">&&</span></tt> と <tt class="docutils literal"><span class="pre">==</span></tt> という3つの演算子があります。 <tt class="docutils literal"><span class="pre">@</span></tt> は全文検索用の演算子です。 <tt class="docutils literal"><span class="pre">&&</span></tt> と <tt class="docutils literal"><span class="pre">==</span></tt> はECMAScriptと同じ意味です。 <tt class="docutils literal"><span class="pre">&&</span></tt> が論理積用の演算子で <tt class="docutils literal"><span class="pre">==</span></tt> が等価演算子です。</p> <p><tt class="docutils literal"><span class="pre">filter</span></tt> にはもっと演算子や構文があります。例えば、 <tt class="docutils literal"><span class="pre">(...)</span></tt> を使った検索条件のグループ化などです。しかし、ここでは詳細は説明しません。詳細は <a class="reference internal" href="../grn_expr/script_syntax.html"><em>スクリプト構文</em></a> を参照してください。</p> </div> </div> <div class="section" id="paging"> <h3>8.3.22.3.3. ページング<a class="headerlink" href="#paging" title="このヘッドラインへのパーマリンク">¶</a></h3> <p><tt class="docutils literal"><span class="pre">offset</span></tt> と <tt class="docutils literal"><span class="pre">limit</span></tt> を指定することで出力されるレコードの範囲を指定できます。以下は2番目のレコードだけを出力する例です。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select Entries --offset 1 --limit 1 # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 5 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "_key", # "ShortText" # ], # [ # "content", # "Text" # ], # [ # "n_likes", # "UInt32" # ] # ], # [ # 2, # "Groonga", # "I started to use groonga. It's very fast!", # 10 # ] # ] # ] # ] </pre></div> </div> <p><tt class="docutils literal"><span class="pre">offset</span></tt> は0基点です。 <tt class="docutils literal"><span class="pre">--offset</span> <span class="pre">1</span></tt> は2番目以降のレコードを出力するという意味になります。</p> <p><tt class="docutils literal"><span class="pre">limit</span></tt> は出力レコード数の最大値を指定します。 <tt class="docutils literal"><span class="pre">--limit</span> <span class="pre">1</span></tt> は多くても1レコードを出力するという意味になります。もし、1つもレコードがマッチしていなければ <tt class="docutils literal"><span class="pre">select</span></tt> コマンドはどのレコードも出力しません。</p> </div> <div class="section" id="the-total-number-of-records"> <h3>8.3.22.3.4. 全レコード数<a class="headerlink" href="#the-total-number-of-records" title="このヘッドラインへのパーマリンク">¶</a></h3> <p><tt class="docutils literal"><span class="pre">--limit</span> <span class="pre">0</span></tt> を使うとレコードの内容は取得せずに全レコード数だけを取得できます。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select Entries --limit 0 # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 5 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "_key", # "ShortText" # ], # [ # "content", # "Text" # ], # [ # "n_likes", # "UInt32" # ] # ] # ] # ] # ] </pre></div> </div> <p><tt class="docutils literal"><span class="pre">--limit</span> <span class="pre">0</span></tt> はマッチしたレコード数だけを取得したいときにも便利です。</p> </div> </div> <div class="section" id="parameters"> <h2>8.3.22.4. 引数<a class="headerlink" href="#parameters" title="このヘッドラインへのパーマリンク">¶</a></h2> <p>このセクションではすべての引数について説明します。引数はカテゴリわけしています。</p> <div class="section" id="required-parameter"> <h3>8.3.22.4.1. 必須引数<a class="headerlink" href="#required-parameter" title="このヘッドラインへのパーマリンク">¶</a></h3> <p><tt class="docutils literal"><span class="pre">table</span></tt> だけが必須の引数です。</p> <div class="section" id="table"> <h4>8.3.22.4.1.1. <tt class="docutils literal"><span class="pre">table</span></tt><a class="headerlink" href="#table" title="このヘッドラインへのパーマリンク">¶</a></h4> <p>検索対象のテーブルを指定します。 <tt class="docutils literal"><span class="pre">table</span></tt> は必ず指定しなければいけません。</p> <p>存在しないテーブルを指定するとエラーが返ります。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select Nonexistent # [ # [ # -22, # 1337566253.89858, # 0.000355720520019531, # "invalid table name: <Nonexistent>", # [ # [ # "grn_select", # "proc.c", # 778 # ] # ] # ] # ] </pre></div> </div> </div> </div> <div class="section" id="search-related-parameters"> <h3>8.3.22.4.2. 検索関係の引数<a class="headerlink" href="#search-related-parameters" title="このヘッドラインへのパーマリンク">¶</a></h3> <p>検索関係の引数がいくつかあります。一般的には、検索ボックスを実装するために <tt class="docutils literal"><span class="pre">match_columns</span></tt> と <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> と <tt class="docutils literal"><span class="pre">filter</span></tt> を指定した場合は、 <tt class="docutils literal"><span class="pre">query</span></tt> と <tt class="docutils literal"><span class="pre">filter</span></tt> にマッチしたレコードが選択されます。 <tt class="docutils literal"><span class="pre">query</span></tt> と <tt class="docutils literal"><span class="pre">filter</span></tt> のどちらも指定しなかった場合はすべてのレコードが選択されます。</p> <div class="section" id="match-columns"> <span id="select-match-columns"></span><h4>8.3.22.4.2.1. <tt class="docutils literal"><span class="pre">match_columns</span></tt><a class="headerlink" href="#match-columns" title="このヘッドラインへのパーマリンク">¶</a></h4> <p><tt class="docutils literal"><span class="pre">query</span></tt> 引数の値で全文検索をするときに使うデフォルトの検索対象カラムを指定します。全文検索対象のカラムは <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> で指定する場合の違いは重みを指定できるかどうかです。 <tt class="docutils literal"><span class="pre">match_columns</span></tt> では重みを指定できますが、 <tt class="docutils literal"><span class="pre">query</span></tt> では指定できません。</p> <p>重みは検索対象カラムの相対的な重要度です。重みの大きい検索対象カラムでマッチした場合は小さい検索対象カラムでマッチした場合よりも多くのヒットスコアがつきます。デフォルトの重みは1です。</p> <p>以下は簡単な <tt class="docutils literal"><span class="pre">match_columns</span></tt> の使用例です。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select Entries --match_columns content --query fast --output_columns '_key, _score' # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 2 # ], # [ # [ # "_key", # "ShortText" # ], # [ # "_score", # "Int32" # ] # ], # [ # "Groonga", # 1 # ], # [ # "Mroonga", # 2 # ] # ] # ] # ] </pre></div> </div> <p><tt class="docutils literal"><span class="pre">--match_columns</span> <span class="pre">content</span></tt> はデフォルトの全文検索対象カラムに <tt class="docutils literal"><span class="pre">content</span></tt> カラムを使用し、その重みは1、という意味になります。 <tt class="docutils literal"><span class="pre">--output_columns</span> <span class="pre">'_key,</span> <span class="pre">_score'</span></tt> はこの <tt class="docutils literal"><span class="pre">select</span></tt> コマンドがマッチしたレコードの <tt class="docutils literal"><span class="pre">_key</span></tt> の値と <tt class="docutils literal"><span class="pre">_score</span></tt> の値を出力する、ということを指定しています。</p> <p><tt class="docutils literal"><span class="pre">_score</span></tt> の値に注目してください。 <tt class="docutils literal"><span class="pre">_score</span></tt> の値は <tt class="docutils literal"><span class="pre">query</span></tt> 引数の値に何個マッチしたかになっています。この例では、 <tt class="docutils literal"><span class="pre">query</span></tt> 引数の値は <tt class="docutils literal"><span class="pre">fast</span></tt> です。 <tt class="docutils literal"><span class="pre">_score</span></tt> の値が1ということは <tt class="docutils literal"><span class="pre">content</span></tt> カラムの中に <tt class="docutils literal"><span class="pre">fast</span></tt> が1つだけあるということです。 <tt class="docutils literal"><span class="pre">_score</span></tt> の値が2ということは <tt class="docutils literal"><span class="pre">content</span></tt> カラムの中に <tt class="docutils literal"><span class="pre">fast</span></tt> が2つあるということです。</p> <p>重みを指定するためには <tt class="docutils literal"><span class="pre">column</span> <span class="pre">*</span> <span class="pre">weight</span></tt> という構文を使います。以下は重みの使用例です。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select Entries --match_columns 'content * 2' --query fast --output_columns '_key, _score' # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 2 # ], # [ # [ # "_key", # "ShortText" # ], # [ # "_score", # "Int32" # ] # ], # [ # "Groonga", # 2 # ], # [ # "Mroonga", # 4 # ] # ] # ] # ] </pre></div> </div> <p><tt class="docutils literal"><span class="pre">--match_columns</span> <span class="pre">'content</span> <span class="pre">*</span> <span class="pre">2'</span></tt> はデフォルトの全文検索用カラムとして <tt class="docutils literal"><span class="pre">content</span></tt> カラムを使い、その重みは2という意味です。</p> <p><tt class="docutils literal"><span class="pre">_score</span></tt> の値に注目してください。 <tt class="docutils literal"><span class="pre">_score</span></tt> の値が2倍になっています。これは重みを2にしたからです。</p> <p>デフォルトの全文検索対象カラムとして複数のカラムを指定することができます。複数のカラムを指定した場合はすべてのカラムに対して全文検索が行われ、ヒットスコアが積算されます。つまり、 <tt class="docutils literal"><span class="pre">query</span></tt> 引数の値がどれか1つでも全文検索対象カラムにマッチしたら、そのレコードはマッチしたものとして扱われます。</p> <p>複数のカラムを指定するには <tt class="docutils literal"><span class="pre">column1</span> <span class="pre">*</span> <span class="pre">weight1</span> <span class="pre">||</span> <span class="pre">column2</span> <span class="pre">*</span> <span class="pre">weight2</span> <span class="pre">||</span> <span class="pre">...</span></tt> という構文を使います。 <tt class="docutils literal"><span class="pre">*</span> <span class="pre">weight</span></tt> は省略することができます。省略した場合は重みが1になります。以下は複数カラムの使用例です。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select Entries --match_columns '_key * 10 || content' --query groonga --output_columns '_key, _score' # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 1 # ], # [ # [ # "_key", # "ShortText" # ], # [ # "_score", # "Int32" # ] # ], # [ # "Groonga", # 11 # ] # ] # ] # ] </pre></div> </div> <p><tt class="docutils literal"><span class="pre">--match_columns</span> <span class="pre">'_key</span> <span class="pre">*</span> <span class="pre">10</span> <span class="pre">||</span> <span class="pre">content'</span></tt> はデフォルト検索対象カラムが <tt class="docutils literal"><span class="pre">_key</span></tt> カラムと <tt class="docutils literal"><span class="pre">content</span></tt> カラムで、 <tt class="docutils literal"><span class="pre">_key</span></tt> カラムの重みは10、 <tt class="docutils literal"><span class="pre">content</span></tt> カラムの重みは1という意味です。この重み付けは <tt class="docutils literal"><span class="pre">_key</span></tt> カラムの値は <tt class="docutils literal"><span class="pre">content</span></tt> カラムの値よりも重要だという意味になります。この例では、ブログエントリのタイトルはブログエントリの内容よりも重要だということです。</p> </div> <div class="section" id="query"> <span id="select-query"></span><h4>8.3.22.4.2.2. <tt class="docutils literal"><span class="pre">query</span></tt><a class="headerlink" href="#query" title="このヘッドラインへのパーマリンク">¶</a></h4> <p>クエリーテキストを指定します。通常、全文検索をするために <tt class="docutils literal"><span class="pre">match_columns</span></tt> 引数と一緒に使います。 <tt class="docutils literal"><span class="pre">query</span></tt> 引数はWebページにある全文検索フォームで使いやすいように設計されています。クエリーテキストは <a class="reference internal" href="../grn_expr/query_syntax.html"><em>クエリー構文</em></a> という書式を使います。この書式はGoogleの検索フォームのように一般的な検索フォームと似ています。例えば、 <tt class="docutils literal"><span class="pre">word1</span> <span class="pre">word2</span></tt> は <tt class="docutils literal"><span class="pre">word1</span></tt> と <tt class="docutils literal"><span class="pre">word2</span></tt> を含んでいるレコードを検索するという意味になります。 <tt class="docutils literal"><span class="pre">word1</span> <span class="pre">OR</span> <span class="pre">word2</span></tt> は <tt class="docutils literal"><span class="pre">word1</span></tt> または <tt class="docutils literal"><span class="pre">word2</span></tt> を含んでいるレコードを検索するという意味になります。</p> <p>以下は論理積を使った検索の簡単な例です。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select Entries --match_columns content --query "fast groonga" # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 1 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "_key", # "ShortText" # ], # [ # "content", # "Text" # ], # [ # "n_likes", # "UInt32" # ] # ], # [ # 2, # "Groonga", # "I started to use groonga. It's very fast!", # 10 # ] # ] # ] # ] </pre></div> </div> <p>この <tt class="docutils literal"><span class="pre">select</span></tt> コマンドは <tt class="docutils literal"><span class="pre">Entries</span></tt> テーブルの中から <tt class="docutils literal"><span class="pre">content</span></tt> カラムの値に <tt class="docutils literal"><span class="pre">fast</span></tt> と <tt class="docutils literal"><span class="pre">groonga</span></tt> の2つの単語を含んでいるレコードを検索します。</p> <p>以下は論理和を使った検索の簡単な例です。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select Entries --match_columns content --query "groonga OR mroonga" # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 2 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "_key", # "ShortText" # ], # [ # "content", # "Text" # ], # [ # "n_likes", # "UInt32" # ] # ], # [ # 2, # "Groonga", # "I started to use groonga. It's very fast!", # 10 # ], # [ # 3, # "Mroonga", # "I also started to use mroonga. It's also very fast! Really fast!", # 15 # ] # ] # ] # ] </pre></div> </div> <p>この <tt class="docutils literal"><span class="pre">select</span></tt> コマンドは <tt class="docutils literal"><span class="pre">Entries</span></tt> テーブルの中から <tt class="docutils literal"><span class="pre">content</span></tt> カラムの値に <tt class="docutils literal"><span class="pre">fast</span></tt> または <tt class="docutils literal"><span class="pre">groonga</span></tt> のどちらかの単語を含んでいるレコードを検索します。</p> <p>他の構文は <a class="reference internal" href="../grn_expr/query_syntax.html"><em>クエリー構文</em></a> を参照してください。</p> <p><tt class="docutils literal"><span class="pre">query</span></tt> では全文検索だけではなく他の条件も使えます。例えば、 <tt class="docutils literal"><span class="pre">column:value</span></tt> は <tt class="docutils literal"><span class="pre">column</span></tt> の値が <tt class="docutils literal"><span class="pre">value</span></tt> と等しいという意味です。 <tt class="docutils literal"><span class="pre">column:<value</span></tt> は <tt class="docutils literal"><span class="pre">column</span></tt> の値が <tt class="docutils literal"><span class="pre">value</span></tt> より小さいという意味です。</p> <p>以下は等価演算子を使った検索の簡単な例です。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select Entries --query _key:Groonga # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 1 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "_key", # "ShortText" # ], # [ # "content", # "Text" # ], # [ # "n_likes", # "UInt32" # ] # ], # [ # 2, # "Groonga", # "I started to use groonga. It's very fast!", # 10 # ] # ] # ] # ] </pre></div> </div> <p>この <tt class="docutils literal"><span class="pre">select</span></tt> コマンドは <tt class="docutils literal"><span class="pre">Entries</span></tt> テーブルの中から <tt class="docutils literal"><span class="pre">_key</span></tt> カラムの値が <tt class="docutils literal"><span class="pre">Groonga</span></tt> であるレコードを検索します。</p> <p>以下は比較演算子を使った検索の簡単な例です。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select Entries --query n_likes:<11 # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 4 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "_key", # "ShortText" # ], # [ # "content", # "Text" # ], # [ # "n_likes", # "UInt32" # ] # ], # [ # 1, # "The first post!", # "Welcome! This is my first post!", # 5 # ], # [ # 2, # "Groonga", # "I started to use groonga. It's very fast!", # 10 # ], # [ # 4, # "Good-bye Senna", # "I migrated all Senna system!", # 3 # ], # [ # 5, # "Good-bye Tritonn", # "I also migrated all Tritonn system!", # 3 # ] # ] # ] # ] </pre></div> </div> <p>この <tt class="docutils literal"><span class="pre">select</span></tt> コマンドは <tt class="docutils literal"><span class="pre">Entries</span></tt> テーブルの中から <tt class="docutils literal"><span class="pre">n_likes</span></tt> カラムの値が <tt class="docutils literal"><span class="pre">11</span></tt> より小さいレコードを検索します。</p> <p>他の演算子は <a class="reference internal" href="../grn_expr/query_syntax.html"><em>クエリー構文</em></a> を参照してください。</p> </div> <div class="section" id="filter"> <h4>8.3.22.4.2.3. <tt class="docutils literal"><span class="pre">filter</span></tt><a class="headerlink" href="#filter" title="このヘッドラインへのパーマリンク">¶</a></h4> <p>フィルターテキストを指定します。通常、 <tt class="docutils literal"><span class="pre">filter</span></tt> は複雑な条件を指定するために使います。 <tt class="docutils literal"><span class="pre">filter</span></tt> は <tt class="docutils literal"><span class="pre">query</span></tt> 引数と一緒に使うこともできます。 <tt class="docutils literal"><span class="pre">filter</span></tt> と <tt class="docutils literal"><span class="pre">query</span></tt> を両方指定した場合はそれらを論理積で組み合わせます。つまり、マッチするレコードは <tt class="docutils literal"><span class="pre">filter</span></tt> にも <tt class="docutils literal"><span class="pre">query</span></tt> にもマッチしなければいけないということです。</p> <p><tt class="docutils literal"><span class="pre">filter</span></tt> 引数は複雑な条件用に設計されています。フィルターテキストは <a class="reference internal" href="../grn_expr/script_syntax.html"><em>スクリプト構文</em></a> 書式で指定します。この書式はECMAScriptに似ています。例えば、 <tt class="docutils literal"><span class="pre">column</span> <span class="pre">==</span> <span class="pre">"value"</span></tt> は <tt class="docutils literal"><span class="pre">column</span></tt> カラムの値が <tt class="docutils literal"><span class="pre">"value"</span></tt> と等しいという意味です。 <tt class="docutils literal"><span class="pre">column</span> <span class="pre"><</span> <span class="pre">value</span></tt> は <tt class="docutils literal"><span class="pre">column</span></tt> カラムの値が <tt class="docutils literal"><span class="pre">value</span></tt> よりも小さいという意味です。</p> <p>以下は等価演算子を使った検索の簡単な例です。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select Entries --filter '_key == "Groonga"' # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 1 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "_key", # "ShortText" # ], # [ # "content", # "Text" # ], # [ # "n_likes", # "UInt32" # ] # ], # [ # 2, # "Groonga", # "I started to use groonga. It's very fast!", # 10 # ] # ] # ] # ] </pre></div> </div> <p>この <tt class="docutils literal"><span class="pre">select</span></tt> コマンドは <tt class="docutils literal"><span class="pre">Entries</span></tt> テーブルの中から <tt class="docutils literal"><span class="pre">_key</span></tt> カラムの値が <tt class="docutils literal"><span class="pre">Groonga</span></tt> であるレコードを検索します。</p> <p>以下は比較演算子を使った検索の簡単な例です。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select Entries --filter 'n_likes < 11' # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 4 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "_key", # "ShortText" # ], # [ # "content", # "Text" # ], # [ # "n_likes", # "UInt32" # ] # ], # [ # 1, # "The first post!", # "Welcome! This is my first post!", # 5 # ], # [ # 2, # "Groonga", # "I started to use groonga. It's very fast!", # 10 # ], # [ # 4, # "Good-bye Senna", # "I migrated all Senna system!", # 3 # ], # [ # 5, # "Good-bye Tritonn", # "I also migrated all Tritonn system!", # 3 # ] # ] # ] # ] </pre></div> </div> <p>この <tt class="docutils literal"><span class="pre">select</span></tt> コマンドは <tt class="docutils literal"><span class="pre">Entries</span></tt> テーブルの中から <tt class="docutils literal"><span class="pre">n_likes</span></tt> カラムの値が <tt class="docutils literal"><span class="pre">11</span></tt> より小さいレコードを検索します。</p> <p>他の演算子は <a class="reference internal" href="../grn_expr/script_syntax.html"><em>スクリプト構文</em></a> を参照してください。</p> </div> </div> <div class="section" id="advanced-search-parameters"> <h3>8.3.22.4.3. 高度な検索のための引数<a class="headerlink" href="#advanced-search-parameters" title="このヘッドラインへのパーマリンク">¶</a></h3> <div class="section" id="match-escalation-threshold"> <span id="id1"></span><h4>8.3.22.4.3.1. <tt class="docutils literal"><span class="pre">match_escalation_threshold</span></tt><a class="headerlink" href="#match-escalation-threshold" title="このヘッドラインへのパーマリンク">¶</a></h4> <p>検索方法をエスカレーションするかどうかを決定するための閾値を指定します。この閾値はマッチしたレコード数との比較に使われます。マッチしたレコード数がこの閾値以下の場合は検索方法をエスカレーションします。検索方法のエスカレーションについては <a class="reference internal" href="../../spec/search.html"><em>検索</em></a> を参照してください。</p> <p>デフォルトの閾値は0です。これは1つもレコードがマッチしなかったときだけ検索方法をエスカレーションするということです。</p> <p>デフォルトの閾値は以下の方法でカスタマイズできます。</p> <blockquote> <div><ul class="simple"> <li><p class="first">configureの <tt class="docutils literal"><span class="pre">--with-match-escalation-threshold</span></tt> オプション</p> </li> <li><p class="first">groongaコマンドの <tt class="docutils literal"><span class="pre">--match-escalation-threshold</span></tt> オプション</p> </li> <li><p class="first">設定ファイルの <tt class="docutils literal"><span class="pre">match-escalation-threshold</span></tt> 設定項目</p> </li> </ul> </div></blockquote> <p>以下は簡単な <tt class="docutils literal"><span class="pre">match_escalation_threshold</span></tt> の使用例です。最初の <tt class="docutils literal"><span class="pre">select</span></tt> は <tt class="docutils literal"><span class="pre">match_escalation_threshold</span></tt> 引数がありません。2番目の <tt class="docutils literal"><span class="pre">select</span></tt> は <tt class="docutils literal"><span class="pre">match_escalation_threshold</span></tt> 引数があります。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select Entries --match_columns content --query groo # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 1 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "_key", # "ShortText" # ], # [ # "content", # "Text" # ], # [ # "n_likes", # "UInt32" # ] # ], # [ # 2, # "Groonga", # "I started to use groonga. It's very fast!", # 10 # ] # ] # ] # ] select Entries --match_columns content --query groo --match_escalation_threshold -1 # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 0 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "_key", # "ShortText" # ], # [ # "content", # "Text" # ], # [ # "n_likes", # "UInt32" # ] # ] # ] # ] # ] </pre></div> </div> <p>最初の <tt class="docutils literal"><span class="pre">select</span></tt> コマンドは <tt class="docutils literal"><span class="pre">Entries</span></tt> テーブルから <tt class="docutils literal"><span class="pre">content</span></tt> カラムの値に <tt class="docutils literal"><span class="pre">groo</span></tt> という単語を含むレコードを検索します。しかし、この検索ではどのレコードにもマッチしません。これは、 <tt class="docutils literal"><span class="pre">TokenBigram</span></tt> トークナイザーは <tt class="docutils literal"><span class="pre">groonga</span></tt> を <tt class="docutils literal"><span class="pre">gr|ro|oo|on|ng|ga</span></tt> ではなく <tt class="docutils literal"><span class="pre">groonga</span></tt> にトークナイズするからです。( <tt class="docutils literal"><span class="pre">TokenBigramSplitSymbolAlpha</span></tt> は <tt class="docutils literal"><span class="pre">groonga</span></tt> を <tt class="docutils literal"><span class="pre">gr|ro|oo|on|ng|ga</span></tt> にトークナイズします。詳細は <a class="reference internal" href="../tokenizers.html"><em>Tokenizers</em></a> を見てください。)つまり、 <tt class="docutils literal"><span class="pre">groonga</span></tt> はインデックスに登録されていますが、 <tt class="docutils literal"><span class="pre">groo</span></tt> はインデックスに登録されていないということです。インデックスに登録されていないので完全一致検索では <tt class="docutils literal"><span class="pre">groo</span></tt> はどのレコードにもマッチしません。このケースでは検索方法のエスカレーションが行われています。なぜならばマッチしたレコード数(0)が <tt class="docutils literal"><span class="pre">match_escalation_threshold</span></tt> (0)の値と等しいからです。非分かち書き検索では <tt class="docutils literal"><span class="pre">groo</span></tt> で1つのレコードがマッチします。</p> <p>2番目の <tt class="docutils literal"><span class="pre">select</span></tt> コマンドも <tt class="docutils literal"><span class="pre">Entries</span></tt> テーブルから <tt class="docutils literal"><span class="pre">content</span></tt> カラムの値に <tt class="docutils literal"><span class="pre">groo</span></tt> という単語を含むレコードを検索します。そして、この <tt class="docutils literal"><span class="pre">select</span></tt> コマンドもマッチしません。この場合、マッチしたレコード数(0)が <tt class="docutils literal"><span class="pre">match_escalation_threshold</span></tt> (-1)より大きいので、検索方法をエスカレーションしません。そして、1つもレコードがマッチしません。</p> </div> <div class="section" id="query-expansion"> <span id="id2"></span><h4>8.3.22.4.3.2. <tt class="docutils literal"><span class="pre">query_expansion</span></tt><a class="headerlink" href="#query-expansion" title="このヘッドラインへのパーマリンク">¶</a></h4> <p>Deprecated. Use <a class="reference internal" href="#query-expander"><em>query_expander</em></a> instead.</p> </div> <div class="section" id="query-flags"> <span id="id3"></span><h4>8.3.22.4.3.3. <tt class="docutils literal"><span class="pre">query_flags</span></tt><a class="headerlink" href="#query-flags" title="このヘッドラインへのパーマリンク">¶</a></h4> <p><tt class="docutils literal"><span class="pre">query</span></tt> パラメーターの構文をカスタマイズします。デフォルトでは <tt class="docutils literal"><span class="pre">query</span></tt> パラメーターでカラムの値を更新することはできません。しかし、 <tt class="docutils literal"><span class="pre">query_flags</span></tt> に <tt class="docutils literal"><span class="pre">ALLOW_COLUMN|ALLOW_UPDATE</span></tt> を指定することで <tt class="docutils literal"><span class="pre">query</span></tt> でカラムの値を更新することができます。</p> <p>指定可能な値は以下の通りです。</p> <ul class="simple"> <li><tt class="docutils literal"><span class="pre">ALLOW_PRAGMA</span></tt></li> <li><tt class="docutils literal"><span class="pre">ALLOW_COLUMN</span></tt></li> <li><tt class="docutils literal"><span class="pre">ALLOW_UPDATE</span></tt></li> <li><tt class="docutils literal"><span class="pre">ALLOW_LEADING_NOT</span></tt></li> <li><tt class="docutils literal"><span class="pre">NONE</span></tt></li> </ul> <p><tt class="docutils literal"><span class="pre">ALLOW_PRAGMA</span></tt> を指定すると <tt class="docutils literal"><span class="pre">query</span></tt> の先頭でプラグマを指定することができます。この機能はまだ実装されていません。</p> <p><tt class="docutils literal"><span class="pre">ALLOW_COLUMN</span></tt> を指定すると <tt class="docutils literal"><span class="pre">match_columns</span></tt> で指定していないカラムでも検索できるように成ります。カラムを指定するには <tt class="docutils literal"><span class="pre">COLUMN:...</span></tt> というような構文を使います。</p> <p><tt class="docutils literal"><span class="pre">ALLOW_UPDATE</span></tt> を指定すると <tt class="docutils literal"><span class="pre">COLUMN:=NEW_VALUE</span></tt> という構文を使って <tt class="docutils literal"><span class="pre">query</span></tt> でカラムの値を更新できます。カラム更新用の構文ではカラムを指定する必要があるため、 <tt class="docutils literal"><span class="pre">ALLOW_COLUMN</span></tt> も一緒に指定する必要があります。</p> <p><tt class="docutils literal"><span class="pre">ALLOW_LEADING_NOT</span></tt> を指定すると <tt class="docutils literal"><span class="pre">-WORD</span></tt> という構文を使って最初の条件として否定条件を指定できます。このクエリーは <tt class="docutils literal"><span class="pre">WORD</span></tt> にマッチしないレコードを検索します。最初の条件に否定条件を使ったクエリーは多くの場合重いクエリーになります。これは多くのレコードにマッチするからです。そのため、このフラグはデフォルトでは無効になっています。もし、このフラグを使う場合は重いクエリーとなるということを十分気をつけてください。</p> <p><tt class="docutils literal"><span class="pre">NONE</span></tt> は単に無視されます。フラグを指定しないときに <tt class="docutils literal"><span class="pre">NONE</span></tt> を使えます。</p> <p>これらのフラグは <tt class="docutils literal"><span class="pre">ALLOW_COLUMN|ALLOW_UPDATE</span></tt> のように <tt class="docutils literal"><span class="pre">|</span></tt> で区切って同時に指定することができます。</p> <p>デフォルト値は <tt class="docutils literal"><span class="pre">ALLOW_PRAGMA|ALLOW_COLUMN</span></tt> です。</p> <p>以下は <tt class="docutils literal"><span class="pre">ALLOW_COLUMN</span></tt> の使用例です。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select Entries --query content:@mroonga --query_flags ALLOW_COLUMN # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 1 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "_key", # "ShortText" # ], # [ # "content", # "Text" # ], # [ # "n_likes", # "UInt32" # ] # ], # [ # 3, # "Mroonga", # "I also started to use mroonga. It's also very fast! Really fast!", # 15 # ] # ] # ] # ] </pre></div> </div> <p>この <tt class="docutils literal"><span class="pre">select</span></tt> コマンドは <tt class="docutils literal"><span class="pre">Entries</span></tt> テーブルの中から <tt class="docutils literal"><span class="pre">content</span></tt> カラムの値に <tt class="docutils literal"><span class="pre">mroonga</span></tt> を含んでいるレコードを検索します。</p> <p>以下は <tt class="docutils literal"><span class="pre">ALLOW_UPDATE</span></tt> の使用例です。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>table_create Users TABLE_HASH_KEY ShortText # [[0, 1337566253.89858, 0.000355720520019531], true] column_create Users age COLUMN_SCALAR UInt32 # [[0, 1337566253.89858, 0.000355720520019531], true] load --table Users [ {"_key": "alice", "age": 18}, {"_key": "bob", "age": 20} ] # [[0, 1337566253.89858, 0.000355720520019531], 2] select Users --query age:=19 --query_flags ALLOW_COLUMN|ALLOW_UPDATE # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 2 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "_key", # "ShortText" # ], # [ # "age", # "UInt32" # ] # ], # [ # 1, # "alice", # 19 # ], # [ # 2, # "bob", # 19 # ] # ] # ] # ] select Users # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 2 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "_key", # "ShortText" # ], # [ # "age", # "UInt32" # ] # ], # [ # 1, # "alice", # 19 # ], # [ # 2, # "bob", # 19 # ] # ] # ] # ] </pre></div> </div> <p>最初の <tt class="docutils literal"><span class="pre">select</span></tt> コマンドは全てのレコードの <tt class="docutils literal"><span class="pre">age</span></tt> カラムの値を <tt class="docutils literal"><span class="pre">19</span></tt> にします。二番目の <tt class="docutils literal"><span class="pre">select</span></tt> コマンドは <tt class="docutils literal"><span class="pre">age</span></tt> カラムの値を出力します。</p> <p>以下は <tt class="docutils literal"><span class="pre">ALLOW_LEADING_NOT</span></tt> の使用例です。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select Entries --match_columns content --query -mroonga --query_flags ALLOW_LEADING_NOT # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 4 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "_key", # "ShortText" # ], # [ # "content", # "Text" # ], # [ # "n_likes", # "UInt32" # ] # ], # [ # 1, # "The first post!", # "Welcome! This is my first post!", # 5 # ], # [ # 2, # "Groonga", # "I started to use groonga. It's very fast!", # 10 # ], # [ # 4, # "Good-bye Senna", # "I migrated all Senna system!", # 3 # ], # [ # 5, # "Good-bye Tritonn", # "I also migrated all Tritonn system!", # 3 # ] # ] # ] # ] </pre></div> </div> <p>この <tt class="docutils literal"><span class="pre">select</span></tt> コマンドは <tt class="docutils literal"><span class="pre">Entries</span></tt> テーブルの中から <tt class="docutils literal"><span class="pre">content</span></tt> カラムの値に <tt class="docutils literal"><span class="pre">mroonga</span></tt> を含んでいないレコードを検索します。</p> <p>以下は <tt class="docutils literal"><span class="pre">NONE</span></tt> の使用例です。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select Entries --match_columns content --query 'mroonga OR _key:Groonga' --query_flags NONE # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 1 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "_key", # "ShortText" # ], # [ # "content", # "Text" # ], # [ # "n_likes", # "UInt32" # ] # ], # [ # 3, # "Mroonga", # "I also started to use mroonga. It's also very fast! Really fast!", # 15 # ] # ] # ] # ] </pre></div> </div> <p>この <tt class="docutils literal"><span class="pre">select</span></tt> コマンドは <tt class="docutils literal"><span class="pre">Entries</span></tt> テーブルの中から <tt class="docutils literal"><span class="pre">content</span></tt> カラムの値に <tt class="docutils literal"><span class="pre">mroonga</span></tt> または <tt class="docutils literal"><span class="pre">_key:Groonga</span></tt> のどちらかの単語を含んでいるレコードを検索します。 <tt class="docutils literal"><span class="pre">_key:Groonga</span></tt> が <tt class="docutils literal"><span class="pre">_key</span></tt> カラムの値が <tt class="docutils literal"><span class="pre">Groonga</span></tt> という条件にはならないことに注意してください。これは <tt class="docutils literal"><span class="pre">ALLOW_COLUMN</span></tt> フラグが指定されていないからです。</p> <p><a class="reference internal" href="../grn_expr/query_syntax.html"><em>クエリー構文</em></a> も見てください。</p> </div> <div class="section" id="query-expander"> <span id="id4"></span><h4>8.3.22.4.3.4. <tt class="docutils literal"><span class="pre">query_expander</span></tt><a class="headerlink" href="#query-expander" title="このヘッドラインへのパーマリンク">¶</a></h4> <p>クエリー展開用の引数です。クエリー展開はクエリー中の特定の単語を別の単語に置換します。通常は類義語検索に使います。</p> <p><tt class="docutils literal"><span class="pre">query</span></tt> 引数の値を置換するために使うカラムを指定します。この引数の値の書式は「 <tt class="docutils literal"><span class="pre">${TABLE}.${COLUMN}</span></tt> 」です。例えば、 「 <tt class="docutils literal"><span class="pre">Terms.synonym</span></tt> 」は <tt class="docutils literal"><span class="pre">Terms</span></tt> テーブルの <tt class="docutils literal"><span class="pre">synonym</span></tt> カラムを指定しています。</p> <p>クエリー展開用のテーブルを「置換テーブル」と呼びます。置換テーブルのキーは <tt class="docutils literal"><span class="pre">ShortText</span></tt> にしてください。そのため、配列テーブル( <tt class="docutils literal"><span class="pre">TABLE_NO_KEY</span></tt> )は置換テーブルに使うことはできません。なぜなら、配列テーブルにはキーがないからです。</p> <p>クエリー展開用のカラムを「置換カラム」と呼びます。置換カラムの値の型は <tt class="docutils literal"><span class="pre">ShortText</span></tt> にしてください。カラムの種類はベクター( <tt class="docutils literal"><span class="pre">COLUMN_VECTOR</span></tt> )にしてください。</p> <p>クエリー展開はクエリーの中にある置換テーブルのキーを置換カラムの値で置換します。 <tt class="docutils literal"><span class="pre">query</span></tt> の中にある単語が置換テーブルのキーだったら、キーに対応する置換カラムの値でその単語を置換します。置換は再帰的に実行しません。これは、置換されたクエリー内に置換対象の単語があっても置換されないということです。</p> <p>以下は <tt class="docutils literal"><span class="pre">query_expander</span></tt> の簡単な使用例を示すためのサンプル置換テーブルです。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>table_create Thesaurus TABLE_PAT_KEY|KEY_NORMALIZE ShortText # [[0, 1337566253.89858, 0.000355720520019531], true] column_create Thesaurus synonym COLUMN_VECTOR ShortText # [[0, 1337566253.89858, 0.000355720520019531], true] load --table Thesaurus [ {"_key": "mroonga", "synonym": ["mroonga", "tritonn", "groonga mysql"]}, {"_key": "groonga", "synonym": ["groonga", "senna"]} ] # [[0, 1337566253.89858, 0.000355720520019531], 2] </pre></div> </div> <p><tt class="docutils literal"><span class="pre">Thesaurus</span></tt> 置換テーブルは2つの類義語があります。 <tt class="docutils literal"><span class="pre">"mroonga"</span></tt> と <tt class="docutils literal"><span class="pre">"groonga"</span></tt> です。ユーザが <tt class="docutils literal"><span class="pre">"mroonga"</span></tt> で検索すると、groongaは <tt class="docutils literal"><span class="pre">"((mroonga)</span> <span class="pre">OR</span> <span class="pre">(tritonn)</span> <span class="pre">OR</span> <span class="pre">(groonga</span> <span class="pre">mysql))"</span></tt> で検索します。ユーザーが <tt class="docutils literal"><span class="pre">"groonga"</span></tt> で検索すると、groongaは <tt class="docutils literal"><span class="pre">"((groonga)</span> <span class="pre">OR</span> <span class="pre">(senna))"</span></tt> で検索します。通常、置換テーブルには <tt class="docutils literal"><span class="pre">KEY_NORMALIZE</span></tt> フラグをつけた方がよいです。このフラグを使うと、置換対象の単語が大文字小文字区別せずにマッチするようになります。</p> <p>これらの類義語の値の中に <tt class="docutils literal"><span class="pre">"mroonga"</span></tt> や <tt class="docutils literal"><span class="pre">"groonga"</span></tt> といったキーの値も含まれていることに注意してください。このように類義語にキーの値も含めることを推奨します。もしキーの値を含めないと、置換した値には元の置換対象の値が含まれません。通常、元の値が含まれていた方がよい検索結果になります。もし、検索してほしくない単語がある場合は、元の単語を含めないでください。例えば、空のベクター値を指定することで「ストップワード」機能を実現することもできます。</p> <p>以下は簡単な <tt class="docutils literal"><span class="pre">query_expander</span></tt> の使用例です。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select Entries --match_columns content --query "mroonga" # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 1 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "_key", # "ShortText" # ], # [ # "content", # "Text" # ], # [ # "n_likes", # "UInt32" # ] # ], # [ # 3, # "Mroonga", # "I also started to use mroonga. It's also very fast! Really fast!", # 15 # ] # ] # ] # ] select Entries --match_columns content --query "mroonga" --query_expander Thesaurus.synonym # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 2 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "_key", # "ShortText" # ], # [ # "content", # "Text" # ], # [ # "n_likes", # "UInt32" # ] # ], # [ # 3, # "Mroonga", # "I also started to use mroonga. It's also very fast! Really fast!", # 15 # ], # [ # 5, # "Good-bye Tritonn", # "I also migrated all Tritonn system!", # 3 # ] # ] # ] # ] select Entries --match_columns content --query "((mroonga) OR (tritonn) OR (groonga mysql))" # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 2 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "_key", # "ShortText" # ], # [ # "content", # "Text" # ], # [ # "n_likes", # "UInt32" # ] # ], # [ # 3, # "Mroonga", # "I also started to use mroonga. It's also very fast! Really fast!", # 15 # ], # [ # 5, # "Good-bye Tritonn", # "I also migrated all Tritonn system!", # 3 # ] # ] # ] # ] </pre></div> </div> <p>最初の <tt class="docutils literal"><span class="pre">select</span></tt> コマンドはクエリー展開を使いません。そのため、 <tt class="docutils literal"><span class="pre">"tritonn"</span></tt> という単語を含んでいるレコードは見つかりません。2番目の <tt class="docutils literal"><span class="pre">select</span></tt> コマンドはクエリー展開を使っています。そのため、 <tt class="docutils literal"><span class="pre">"tritonn"</span></tt> という単語を含んでいるレコードが見つかります。3番目の <tt class="docutils literal"><span class="pre">select</span></tt> コマンドはクエリー展開を使っていませんが、2番目の <tt class="docutils literal"><span class="pre">select</span></tt> コマンドと同じ結果になります。これは、3番目の <tt class="docutils literal"><span class="pre">select</span></tt> コマンドは展開後のクエリーを使っているからです。</p> <p>それぞれの置換する値は <tt class="docutils literal"><span class="pre">(...)</span></tt> や <tt class="docutils literal"><span class="pre">OR</span></tt> といった <a class="reference internal" href="../grn_expr/query_syntax.html"><em>クエリー構文</em></a> を使えます。これらの構文を使うことにより複雑な置換をすることができます。</p> <p>以下はクエリー構文を使った複雑な置換の使用例です。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>load --table Thesaurus [ {"_key": "popular", "synonym": ["popular", "n_likes:>=10"]} ] # [[0, 1337566253.89858, 0.000355720520019531], 1] select Entries --match_columns content --query "popular" --query_expander Thesaurus.synonym # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 2 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "_key", # "ShortText" # ], # [ # "content", # "Text" # ], # [ # "n_likes", # "UInt32" # ] # ], # [ # 2, # "Groonga", # "I started to use groonga. It's very fast!", # 10 # ], # [ # 3, # "Mroonga", # "I also started to use mroonga. It's also very fast! Really fast!", # 15 # ] # ] # ] # ] </pre></div> </div> <p>この <tt class="docutils literal"><span class="pre">load</span></tt> コマンドは新しく <tt class="docutils literal"><span class="pre">"popular"</span></tt> という類義語を登録しています。これは <tt class="docutils literal"><span class="pre">((popular)</span> <span class="pre">OR</span> <span class="pre">(n_likes:>=10))</span></tt> に置換されます。置換されたクエリーは、「popular」というのは「popular」という単語を含んでいるか10以上の「いいね!」数を持つエントリという意味になります。</p> <p>この <tt class="docutils literal"><span class="pre">select</span></tt> コマンドは <tt class="docutils literal"><span class="pre">Entries</span></tt> テーブルの中から <tt class="docutils literal"><span class="pre">n_likes</span></tt> カラムの値が <tt class="docutils literal"><span class="pre">10</span></tt> 以上のレコードを出力します。</p> </div> </div> <div class="section" id="output-related-parameters"> <h3>8.3.22.4.4. 出力関連の引数<a class="headerlink" href="#output-related-parameters" title="このヘッドラインへのパーマリンク">¶</a></h3> <div class="section" id="output-columns"> <h4>8.3.22.4.4.1. <tt class="docutils literal"><span class="pre">output_columns</span></tt><a class="headerlink" href="#output-columns" title="このヘッドラインへのパーマリンク">¶</a></h4> <p>出力するカラムを <tt class="docutils literal"><span class="pre">,</span></tt> 区切りで指定します。</p> <p>以下は簡単な <tt class="docutils literal"><span class="pre">output_columns</span></tt> の使用例です。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select Entries --output_columns '_id, _key' --limit 1 # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 5 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "_key", # "ShortText" # ] # ], # [ # 1, # "The first post!" # ] # ] # ] # ] </pre></div> </div> <p>この <tt class="docutils literal"><span class="pre">select</span></tt> コマンドは <tt class="docutils literal"><span class="pre">_id</span></tt> と <tt class="docutils literal"><span class="pre">_key</span></tt> カラムの値だけを出力します。</p> <p><tt class="docutils literal"><span class="pre">*</span></tt> is a special value. It means that all columns that are not <a class="reference internal" href="../pseudo_column.html"><em>疑似カラム (pseudo_column)</em></a>.</p> <p>以下は <tt class="docutils literal"><span class="pre">*</span></tt> の使用例です。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select Entries --output_columns '_key, *' --limit 1 # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 5 # ], # [ # [ # "_key", # "ShortText" # ], # [ # "content", # "Text" # ], # [ # "n_likes", # "UInt32" # ] # ], # [ # "The first post!", # "Welcome! This is my first post!", # 5 # ] # ] # ] # ] </pre></div> </div> <p>この <tt class="docutils literal"><span class="pre">select</span></tt> コマンドは <tt class="docutils literal"><span class="pre">_key</span></tt> 擬似カラム、 <tt class="docutils literal"><span class="pre">content</span></tt> カラム、 <tt class="docutils literal"><span class="pre">n_likes</span></tt> カラムの値を出力しますが、 <tt class="docutils literal"><span class="pre">_id</span></tt> 擬似カラムの値は出力しません。</p> <p>デフォルト値は <tt class="docutils literal"><span class="pre">_id,</span> <span class="pre">_key,</span> <span class="pre">*</span></tt> です。これは <tt class="docutils literal"><span class="pre">_score</span></tt> 以外の全てのカラムを出力するという意味です。</p> </div> <div class="section" id="sortby"> <h4>8.3.22.4.4.2. <tt class="docutils literal"><span class="pre">sortby</span></tt><a class="headerlink" href="#sortby" title="このヘッドラインへのパーマリンク">¶</a></h4> <p>ソートキーを <tt class="docutils literal"><span class="pre">,</span></tt> 区切りで指定します。それぞれのソートキーはカラム名を指定します。</p> <p>以下は簡単な <tt class="docutils literal"><span class="pre">sortby</span></tt> の使用例です。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select Entries --sortby 'n_likes, _id' # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 5 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "_key", # "ShortText" # ], # [ # "content", # "Text" # ], # [ # "n_likes", # "UInt32" # ] # ], # [ # 4, # "Good-bye Senna", # "I migrated all Senna system!", # 3 # ], # [ # 5, # "Good-bye Tritonn", # "I also migrated all Tritonn system!", # 3 # ], # [ # 1, # "The first post!", # "Welcome! This is my first post!", # 5 # ], # [ # 2, # "Groonga", # "I started to use groonga. It's very fast!", # 10 # ], # [ # 3, # "Mroonga", # "I also started to use mroonga. It's also very fast! Really fast!", # 15 # ] # ] # ] # ] </pre></div> </div> <p>この <tt class="docutils literal"><span class="pre">select</span></tt> コマンドは <tt class="docutils literal"><span class="pre">n_likes</span></tt> カラムの値で昇順にソートします。 <tt class="docutils literal"><span class="pre">n_likes</span></tt> の値が同じレコードについては <tt class="docutils literal"><span class="pre">_id</span></tt> カラムの値で昇順にソートします。 <tt class="docutils literal"><span class="pre">"Good-bye</span> <span class="pre">Senna"</span></tt> と <tt class="docutils literal"><span class="pre">"Good-bye</span> <span class="pre">Tritonn"</span></tt> が <tt class="docutils literal"><span class="pre">_id</span></tt> カラムの値でソートしているケースです。</p> <p>降順でソートしたい場合はカラム名の前に <tt class="docutils literal"><span class="pre">-</span></tt> をつけてください。</p> <p>以下は降順の <tt class="docutils literal"><span class="pre">sortby</span></tt> の使用例です。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select Entries --sortby '-n_likes, _id' # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 5 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "_key", # "ShortText" # ], # [ # "content", # "Text" # ], # [ # "n_likes", # "UInt32" # ] # ], # [ # 3, # "Mroonga", # "I also started to use mroonga. It's also very fast! Really fast!", # 15 # ], # [ # 2, # "Groonga", # "I started to use groonga. It's very fast!", # 10 # ], # [ # 1, # "The first post!", # "Welcome! This is my first post!", # 5 # ], # [ # 4, # "Good-bye Senna", # "I migrated all Senna system!", # 3 # ], # [ # 5, # "Good-bye Tritonn", # "I also migrated all Tritonn system!", # 3 # ] # ] # ] # ] </pre></div> </div> <p>この <tt class="docutils literal"><span class="pre">select</span></tt> コマンドは <tt class="docutils literal"><span class="pre">n_likes</span></tt> カラムの値で降順にソートします。しかし、 <tt class="docutils literal"><span class="pre">_id</span></tt> でソートするときは昇順でソートします。</p> <p>もし、 <tt class="docutils literal"><span class="pre">query</span></tt> または <tt class="docutils literal"><span class="pre">filter</span></tt> 引数を使っているときは、 <tt class="docutils literal"><span class="pre">sortby</span></tt> の中で <tt class="docutils literal"><span class="pre">_score</span></tt> 擬似カラムを使うことができます。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select Entries --match_columns content --query fast --sortby -_score --output_columns '_key, _score' # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 2 # ], # [ # [ # "_key", # "ShortText" # ], # [ # "_score", # "Int32" # ] # ], # [ # "Mroonga", # 2 # ], # [ # "Groonga", # 1 # ] # ] # ] # ] </pre></div> </div> <p>この <tt class="docutils literal"><span class="pre">select</span></tt> コマンドはマッチしたレコードをヒットスコアで降順にソートし、レコードのキーとヒットスコアを出力します。</p> <p><tt class="docutils literal"><span class="pre">query</span></tt> 引数も <tt class="docutils literal"><span class="pre">filter</span></tt> 引数も指定しないで <tt class="docutils literal"><span class="pre">_score</span></tt> を使った場合は、 <tt class="docutils literal"><span class="pre">_score</span></tt> を無視して、ログファイルに警告を出力します。</p> </div> <div class="section" id="offset"> <h4>8.3.22.4.4.3. <tt class="docutils literal"><span class="pre">offset</span></tt><a class="headerlink" href="#offset" title="このヘッドラインへのパーマリンク">¶</a></h4> <p>出力するレコードの範囲を決めるためのオフセットを指定します。オフセットは0基点です。 <tt class="docutils literal"><span class="pre">--offset</span> <span class="pre">1</span></tt> は2番目以降のレコードを出力するという意味になります。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select Entries --sortby _id --offset 3 --output_columns _key # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 5 # ], # [ # [ # "_key", # "ShortText" # ] # ], # [ # "Good-bye Senna" # ], # [ # "Good-bye Tritonn" # ] # ] # ] # ] </pre></div> </div> <p>この <tt class="docutils literal"><span class="pre">select</span></tt> コマンドは4番目以降のレコードを出力します。</p> <p>負の値を指定することもできます。負の値の場合は <tt class="docutils literal"><span class="pre">マッチしたレコード数</span> <span class="pre">+</span> <span class="pre">offset</span></tt> 番目のレコードから始まる範囲という意味になります。もし、マッチしたレコードが3つあり、 <tt class="docutils literal"><span class="pre">--offset</span> <span class="pre">-2</span></tt> を指定した場合は1番目( <tt class="docutils literal"><span class="pre">3</span> <span class="pre">+</span> <span class="pre">-2</span> <span class="pre">=</span> <span class="pre">1</span></tt> ) のレコードから3番目のレコードが出力されます。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select Entries --sortby _id --offset -2 --output_columns _key # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 5 # ], # [ # [ # "_key", # "ShortText" # ] # ], # [ # "Good-bye Senna" # ], # [ # "Good-bye Tritonn" # ] # ] # ] # ] </pre></div> </div> <p>この <tt class="docutils literal"><span class="pre">select</span></tt> コマンドは4番目以降のレコードを出力します。なぜなら、全レコード数が <tt class="docutils literal"><span class="pre">5</span></tt> だからです。</p> <p>デフォルト値は <tt class="docutils literal"><span class="pre">0</span></tt> です。</p> </div> <div class="section" id="limit"> <h4>8.3.22.4.4.4. <tt class="docutils literal"><span class="pre">limit</span></tt><a class="headerlink" href="#limit" title="このヘッドラインへのパーマリンク">¶</a></h4> <p><tt class="docutils literal"><span class="pre">limit</span></tt> は出力レコード数の最大値を指定します。 もし、マッチしたレコード数が <tt class="docutils literal"><span class="pre">limit</span></tt> よりも小さい場合はすべてのレコードが出力されます。</p> <p>以下は簡単な <tt class="docutils literal"><span class="pre">limit</span></tt> の使用例です。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select Entries --sortby _id --offset 2 --limit 3 --output_columns _key # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 5 # ], # [ # [ # "_key", # "ShortText" # ] # ], # [ # "Mroonga" # ], # [ # "Good-bye Senna" # ], # [ # "Good-bye Tritonn" # ] # ] # ] # ] </pre></div> </div> <p>この <tt class="docutils literal"><span class="pre">select</span></tt> コマンドは3番目、4番目、5番目のレコードを出力します。</p> <p>負の値を指定することもできます。負の値の場合は、最大で <tt class="docutils literal"><span class="pre">マッチしたレコード数</span> <span class="pre">+</span> <span class="pre">limit</span> <span class="pre">+</span> <span class="pre">1</span></tt> 件のレコードを出力するという意味になります。 例えば、 <tt class="docutils literal"><span class="pre">--limit</span> <span class="pre">-1</span></tt> はすべてのレコードを出力します。これはすべてのレコードを表示する場合にとても便利です。</p> <p>以下は負の値を使った <tt class="docutils literal"><span class="pre">limit</span></tt> の簡単な使用例です。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>select Entries --limit -1 # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 5 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "_key", # "ShortText" # ], # [ # "content", # "Text" # ], # [ # "n_likes", # "UInt32" # ] # ], # [ # 1, # "The first post!", # "Welcome! This is my first post!", # 5 # ], # [ # 2, # "Groonga", # "I started to use groonga. It's very fast!", # 10 # ], # [ # 3, # "Mroonga", # "I also started to use mroonga. It's also very fast! Really fast!", # 15 # ], # [ # 4, # "Good-bye Senna", # "I migrated all Senna system!", # 3 # ], # [ # 5, # "Good-bye Tritonn", # "I also migrated all Tritonn system!", # 3 # ] # ] # ] # ] </pre></div> </div> <p>この <tt class="docutils literal"><span class="pre">select</span></tt> コマンドはすべてのレコードを出力します。</p> <p>デフォルト値は <tt class="docutils literal"><span class="pre">10</span></tt> です。</p> </div> <div class="section" id="scorer"> <h4>8.3.22.4.4.5. <tt class="docutils literal"><span class="pre">scorer</span></tt><a class="headerlink" href="#scorer" title="このヘッドラインへのパーマリンク">¶</a></h4> <p>TODO: write in English and add example.</p> <p>検索条件にマッチする全てのレコードに対して適用するgrn_exprをscript形式で指定します。</p> <p>scorerは、検索処理が完了し、ソート処理が実行される前に呼び出されます。従って、各レコードのスコアを操作する式を指定しておけば、検索結果のソート順序をカスタマイズできるようになります。</p> </div> </div> <div class="section" id="facet-related-parameters"> <h3>8.3.22.4.5. ファセット関連の引数<a class="headerlink" href="#facet-related-parameters" title="このヘッドラインへのパーマリンク">¶</a></h3> <div class="section" id="drilldown"> <h4>8.3.22.4.5.1. <tt class="docutils literal"><span class="pre">drilldown</span></tt><a class="headerlink" href="#drilldown" title="このヘッドラインへのパーマリンク">¶</a></h4> <p>TODO: write in English and add example.</p> <p>グループ化のキーとなるカラム名のリストをカンマ(',')区切りで指定します。検索条件にマッチした各レコードを出力したのちに、drilldownに指定されたカラムの値が同一であるレコードをとりまとめて、それぞれについて結果レコードを出力します。</p> </div> <div class="section" id="drilldown-sortby"> <h4>8.3.22.4.5.2. <tt class="docutils literal"><span class="pre">drilldown_sortby</span></tt><a class="headerlink" href="#drilldown-sortby" title="このヘッドラインへのパーマリンク">¶</a></h4> <p>TODO: write in English and add example.</p> <p>drilldown条件に指定されたカラムの値毎にとりまとめられたレコードについて、ソートキーとなるカラム名のリストをカンマ(',')区切りで指定します。sortbyパラメータと同様に昇降順を指定できます。</p> </div> <div class="section" id="drilldown-output-columns"> <h4>8.3.22.4.5.3. <tt class="docutils literal"><span class="pre">drilldown_output_columns</span></tt><a class="headerlink" href="#drilldown-output-columns" title="このヘッドラインへのパーマリンク">¶</a></h4> <p>TODO: write in English and add example.</p> <p>drilldown条件に指定されたカラムの値毎にとりまとめられたレコードについて、出力するカラム名のリストをカンマ(',')区切りで指定します。</p> </div> <div class="section" id="drilldown-offset"> <h4>8.3.22.4.5.4. <tt class="docutils literal"><span class="pre">drilldown_offset</span></tt><a class="headerlink" href="#drilldown-offset" title="このヘッドラインへのパーマリンク">¶</a></h4> <p>TODO: write in English and add example.</p> <p>drilldown条件に指定されたカラムの値毎にとりまとめられたレコードについて、出力対象となる最初のレコードの番号を0ベースで指定します。デフォルト値は0です。drilldown_offsetに負の値を指定した場合は、ヒットした件数 + drilldown_offsetによって算出される値が指定されたものとみなされます。</p> </div> <div class="section" id="drilldown-limit"> <h4>8.3.22.4.5.5. <tt class="docutils literal"><span class="pre">drilldown_limit</span></tt><a class="headerlink" href="#drilldown-limit" title="このヘッドラインへのパーマリンク">¶</a></h4> <p>TODO: write in English and add example.</p> <p>drilldown条件に指定されたカラムの値毎にとりまとめられたレコードについて、出力を行うレコードの件数を指定します。デフォルト値は10です。実際には、drilldown_offset + drilldown_limit がヒットした件数を超えない範囲でレコードが出力されます。drilldown_limitに負の値を指定した場合は、ヒットした件数 + drilldown_limit + 1 によって算出される値が指定されたものとみなされます。</p> </div> </div> <div class="section" id="cache-related-parameter"> <h3>8.3.22.4.6. キャッシュ関連の引数<a class="headerlink" href="#cache-related-parameter" title="このヘッドラインへのパーマリンク">¶</a></h3> <div class="section" id="cache"> <h4>8.3.22.4.6.1. <tt class="docutils literal"><span class="pre">cache</span></tt><a class="headerlink" href="#cache" title="このヘッドラインへのパーマリンク">¶</a></h4> <p>TODO: write in English and add example.</p> <p>クエリキャッシュに関する動作を設定します。</p> <p><tt class="docutils literal"><span class="pre">no</span></tt></p> <blockquote> <div>検索結果をクエリキャッシュに残しません。キャッシュして再利用される可能性が低いクエリに対して用います。キャッシュ容量は有限です。有効なキャッシュが多くヒットするために、このパラメータは有効です。</div></blockquote> </div> </div> </div> <div class="section" id="id5"> <h2>8.3.22.5. 返値<a class="headerlink" href="#id5" title="このヘッドラインへのパーマリンク">¶</a></h2> <p>TODO: write in English and add example.</p> <p>以下のようなjson形式で値が返却されます。</p> <div class="highlight-none"><div class="highlight"><pre>[[リターンコード, 処理開始時間, 処理時間], [検索結果, ドリルダウン結果]] </pre></div> </div> <p><tt class="docutils literal"><span class="pre">リターンコード</span></tt></p> <blockquote> <div>grn_rcに対応する数値が返されます。0(GRN_SUCCESS)以外の場合は、続いてエラー内容を示す 文字列が返されます。</div></blockquote> <p><tt class="docutils literal"><span class="pre">処理開始時間</span></tt></p> <blockquote> <div>処理を開始した時間について、1970年1月1日0時0分0秒を起点とした秒数を小数で返します。</div></blockquote> <p><tt class="docutils literal"><span class="pre">処理時間</span></tt></p> <blockquote> <div>処理にかかった秒数を返します。</div></blockquote> <p><tt class="docutils literal"><span class="pre">検索結果</span></tt></p> <blockquote> <div><p>drilldown条件が実行される前の検索結果が以下のように出力されます。:</p> <div class="highlight-none"><div class="highlight"><pre>[[検索件数], [[カラム名1,カラム型1],..], 検索結果1,..] </pre></div> </div> <p><tt class="docutils literal"><span class="pre">検索件数</span></tt></p> <blockquote> <div>検索件数が出力されます。</div></blockquote> <p><tt class="docutils literal"><span class="pre">カラム名n</span></tt></p> <blockquote> <div>output_columnsに指定された条件に従って、対象となるカラム名が出力されます。</div></blockquote> <p><tt class="docutils literal"><span class="pre">カラム型n</span></tt></p> <blockquote> <div>output_columnsに指定された条件に従って、対象となるカラム型が出力されます。</div></blockquote> <p><tt class="docutils literal"><span class="pre">検索結果n</span></tt></p> <blockquote> <div>output_columns, offset, limitによって指定された条件に従って各レコードの値が出力されます。</div></blockquote> </div></blockquote> <p><tt class="docutils literal"><span class="pre">drilldown結果</span></tt></p> <blockquote> <div><p>drilldown処理の結果が以下のように出力されます。:</p> <div class="highlight-none"><div class="highlight"><pre>[[[件数], [[カラム名1,カラム型1],..], 検索結果1,..],..] </pre></div> </div> <p><tt class="docutils literal"><span class="pre">件数</span></tt></p> <blockquote> <div>drilldownに指定されたカラムの値の異なり数が出力されます。</div></blockquote> <p><tt class="docutils literal"><span class="pre">カラム名n</span></tt></p> <blockquote> <div>drilldown_output_columnsに指定された条件に従って、対象となるカラム名が出力されます。</div></blockquote> <p><tt class="docutils literal"><span class="pre">カラム型n</span></tt></p> <blockquote> <div>drilldown_output_columnsに指定された条件に従って、対象となるカラム型が出力されます。</div></blockquote> <p><tt class="docutils literal"><span class="pre">ドリルダウン結果n</span></tt></p> <blockquote> <div>drilldown_output_columns, drilldown_offset, drilldown_limitによって指定された条件に従って各レコードの値が出力されます。</div></blockquote> </div></blockquote> </div> <div class="section" id="see-also"> <h2>8.3.22.6. 参考<a class="headerlink" href="#see-also" title="このヘッドラインへのパーマリンク">¶</a></h2> <blockquote> <div><ul class="simple"> <li><a class="reference internal" href="../grn_expr/query_syntax.html"><em>クエリー構文</em></a></li> <li><a class="reference internal" href="../grn_expr/script_syntax.html"><em>スクリプト構文</em></a></li> </ul> </div></blockquote> </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.3.22. <tt class="docutils literal"><span class="pre">select</span></tt></a><ul> <li><a class="reference internal" href="#summary">8.3.22.1. 概要</a></li> <li><a class="reference internal" href="#syntax">8.3.22.2. 構文</a></li> <li><a class="reference internal" href="#usage">8.3.22.3. 使い方</a><ul> <li><a class="reference internal" href="#simple-usage">8.3.22.3.1. 簡単な使い方</a></li> <li><a class="reference internal" href="#search-conditions">8.3.22.3.2. 検索条件</a><ul> <li><a class="reference internal" href="#search-condition-query">8.3.22.3.2.1. 検索条件: <tt class="docutils literal"><span class="pre">query</span></tt></a></li> <li><a class="reference internal" href="#search-condition-filter">8.3.22.3.2.2. 検索条件: <tt class="docutils literal"><span class="pre">filter</span></tt></a></li> </ul> </li> <li><a class="reference internal" href="#paging">8.3.22.3.3. ページング</a></li> <li><a class="reference internal" href="#the-total-number-of-records">8.3.22.3.4. 全レコード数</a></li> </ul> </li> <li><a class="reference internal" href="#parameters">8.3.22.4. 引数</a><ul> <li><a class="reference internal" href="#required-parameter">8.3.22.4.1. 必須引数</a><ul> <li><a class="reference internal" href="#table">8.3.22.4.1.1. <tt class="docutils literal"><span class="pre">table</span></tt></a></li> </ul> </li> <li><a class="reference internal" href="#search-related-parameters">8.3.22.4.2. 検索関係の引数</a><ul> <li><a class="reference internal" href="#match-columns">8.3.22.4.2.1. <tt class="docutils literal"><span class="pre">match_columns</span></tt></a></li> <li><a class="reference internal" href="#query">8.3.22.4.2.2. <tt class="docutils literal"><span class="pre">query</span></tt></a></li> <li><a class="reference internal" href="#filter">8.3.22.4.2.3. <tt class="docutils literal"><span class="pre">filter</span></tt></a></li> </ul> </li> <li><a class="reference internal" href="#advanced-search-parameters">8.3.22.4.3. 高度な検索のための引数</a><ul> <li><a class="reference internal" href="#match-escalation-threshold">8.3.22.4.3.1. <tt class="docutils literal"><span class="pre">match_escalation_threshold</span></tt></a></li> <li><a class="reference internal" href="#query-expansion">8.3.22.4.3.2. <tt class="docutils literal"><span class="pre">query_expansion</span></tt></a></li> <li><a class="reference internal" href="#query-flags">8.3.22.4.3.3. <tt class="docutils literal"><span class="pre">query_flags</span></tt></a></li> <li><a class="reference internal" href="#query-expander">8.3.22.4.3.4. <tt class="docutils literal"><span class="pre">query_expander</span></tt></a></li> </ul> </li> <li><a class="reference internal" href="#output-related-parameters">8.3.22.4.4. 出力関連の引数</a><ul> <li><a class="reference internal" href="#output-columns">8.3.22.4.4.1. <tt class="docutils literal"><span class="pre">output_columns</span></tt></a></li> <li><a class="reference internal" href="#sortby">8.3.22.4.4.2. <tt class="docutils literal"><span class="pre">sortby</span></tt></a></li> <li><a class="reference internal" href="#offset">8.3.22.4.4.3. <tt class="docutils literal"><span class="pre">offset</span></tt></a></li> <li><a class="reference internal" href="#limit">8.3.22.4.4.4. <tt class="docutils literal"><span class="pre">limit</span></tt></a></li> <li><a class="reference internal" href="#scorer">8.3.22.4.4.5. <tt class="docutils literal"><span class="pre">scorer</span></tt></a></li> </ul> </li> <li><a class="reference internal" href="#facet-related-parameters">8.3.22.4.5. ファセット関連の引数</a><ul> <li><a class="reference internal" href="#drilldown">8.3.22.4.5.1. <tt class="docutils literal"><span class="pre">drilldown</span></tt></a></li> <li><a class="reference internal" href="#drilldown-sortby">8.3.22.4.5.2. <tt class="docutils literal"><span class="pre">drilldown_sortby</span></tt></a></li> <li><a class="reference internal" href="#drilldown-output-columns">8.3.22.4.5.3. <tt class="docutils literal"><span class="pre">drilldown_output_columns</span></tt></a></li> <li><a class="reference internal" href="#drilldown-offset">8.3.22.4.5.4. <tt class="docutils literal"><span class="pre">drilldown_offset</span></tt></a></li> <li><a class="reference internal" href="#drilldown-limit">8.3.22.4.5.5. <tt class="docutils literal"><span class="pre">drilldown_limit</span></tt></a></li> </ul> </li> <li><a class="reference internal" href="#cache-related-parameter">8.3.22.4.6. キャッシュ関連の引数</a><ul> <li><a class="reference internal" href="#cache">8.3.22.4.6.1. <tt class="docutils literal"><span class="pre">cache</span></tt></a></li> </ul> </li> </ul> </li> <li><a class="reference internal" href="#id5">8.3.22.5. 返値</a></li> <li><a class="reference internal" href="#see-also">8.3.22.6. 参考</a></li> </ul> </li> </ul> <h4>前のトピックへ</h4> <p class="topless"><a href="register.html" title="前の章へ">8.3.21. register</a></p> <h4>次のトピックへ</h4> <p class="topless"><a href="shutdown.html" title="次の章へ">8.3.23. shutdown</a></p> <h3>このページ</h3> <ul class="this-page-menu"> <li><a href="../../_sources/reference/commands/select.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="shutdown.html" title="8.3.23. shutdown" >次へ</a> |</li> <li class="right" > <a href="register.html" title="8.3.21. register" >前へ</a> |</li> <li><a href="../../index.html">groonga v3.0.5ドキュメント</a> »</li> <li><a href="../../reference.html" >8. リファレンスマニュアル</a> »</li> <li><a href="../command.html" >8.3. コマンド</a> »</li> </ul> </div> <div class="footer"> © Copyright 2009-2013, Brazil, Inc. </div> </body> </html>