Sophie

Sophie

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

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>8.10.1. クエリー構文 &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="8.10. grn_expr" href="../grn_expr.html" />
    <link rel="next" title="8.10.2. スクリプト構文" href="script_syntax.html" />
    <link rel="prev" title="8.10. grn_expr" href="../grn_expr.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/grn_expr/query_syntax.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="script_syntax.html" title="8.10.2. スクリプト構文"
             accesskey="N">次へ</a> |</li>
        <li class="right" >
          <a href="../grn_expr.html" title="8.10. grn_expr"
             accesskey="P">前へ</a> |</li>
        <li><a href="../../index.html">groonga v3.0.5ドキュメント</a> &raquo;</li>
          <li><a href="../../reference.html" >8. リファレンスマニュアル</a> &raquo;</li>
          <li><a href="../grn_expr.html" accesskey="U">8.10. grn_expr</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="query-syntax">
<h1>8.10.1. クエリー構文<a class="headerlink" href="#query-syntax" title="このヘッドラインへのパーマリンク">¶</a></h1>
<p>クエリー構文は一般的なWebの検索フォームで検索条件を指定するための構文です。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>クエリー構文は <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> から成ります。通常、 <tt class="docutils literal"><span class="pre">代入式</span></tt> は考えなくてよいです。なぜなら、 <tt class="docutils literal"><span class="pre">代入式</span></tt> は <a class="reference internal" href="../commands/select.html"><em>select</em></a> の <tt class="docutils literal"><span class="pre">--query</span></tt> オプションでは無効になっているからです。groongaをライブラリとして使ったときは、クエリー構文のパーサーのオプションをカスタマイズすることで <tt class="docutils literal"><span class="pre">代入式</span></tt> を有効にすることができます。</p>
<p><tt class="docutils literal"><span class="pre">条件式</span></tt> は条件を指定します。 <tt class="docutils literal"><span class="pre">結合式</span></tt> は1つ以上の <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> から成ります。 <tt class="docutils literal"><span class="pre">代入式</span></tt> はカラムに値を代入します。</p>
<div class="section" id="sample-data">
<h2>8.10.1.1. サンプルデータ<a class="headerlink" href="#sample-data" title="このヘッドラインへのパーマリンク">¶</a></h2>
<p>使い方を示すために使うスキーマ定義とサンプルデータは以下の通りです。</p>
<p>実行例:</p>
<div class="highlight-none"><div class="highlight"><pre>table_create Entries TABLE_PAT_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
[
{&quot;_key&quot;:    &quot;The first post!&quot;,
 &quot;content&quot;: &quot;Welcome! This is my first post!&quot;,
 &quot;n_likes&quot;: 5},
{&quot;_key&quot;:    &quot;Groonga&quot;,
 &quot;content&quot;: &quot;I started to use groonga. It&#39;s very fast!&quot;,
 &quot;n_likes&quot;: 10},
{&quot;_key&quot;:    &quot;Mroonga&quot;,
 &quot;content&quot;: &quot;I also started to use mroonga. It&#39;s also very fast! Really fast!&quot;,
 &quot;n_likes&quot;: 15},
{&quot;_key&quot;:    &quot;Good-bye Senna&quot;,
 &quot;content&quot;: &quot;I migrated all Senna system!&quot;,
 &quot;n_likes&quot;: 3},
{&quot;_key&quot;:    &quot;Good-bye Tritonn&quot;,
 &quot;content&quot;: &quot;I also migrated all Tritonn system!&quot;,
 &quot;n_likes&quot;: 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>
<div class="section" id="escape">
<h2>8.10.1.2. エスケープ<a class="headerlink" href="#escape" title="このヘッドラインへのパーマリンク">¶</a></h2>
<p>クエリー構文には特別な文字があります。特別な文字それ自体を使うためには文字の前に <tt class="docutils literal"><span class="pre">\</span></tt> をつけてエスケープしなければいけません。例えば、 <tt class="docutils literal"><span class="pre">&quot;</span></tt> は特別な文字です。これは <tt class="docutils literal"><span class="pre">\&quot;</span></tt> というようにエスケープします。</p>
<p>以下が特別な文字のリストです:</p>
<blockquote>
<div><ul class="simple">
<li><p class="first"><tt class="docutils literal"><span class="pre">[space]</span></tt> ( <tt class="docutils literal"><span class="pre">[backquote][space]</span></tt> とエスケープする。)( <tt class="docutils literal"><span class="pre">[space]</span></tt> をASCIIで言えば0x20の空白文字に置き換えて、 <tt class="docutils literal"><span class="pre">[backquote]</span></tt> を <tt class="docutils literal"><span class="pre">\\</span></tt> に置き換えてください。)</p>
</li>
<li><p class="first"><tt class="docutils literal"><span class="pre">&quot;</span></tt> ( <tt class="docutils literal"><span class="pre">\&quot;</span></tt> とエスケープする。)</p>
</li>
<li><p class="first"><tt class="docutils literal"><span class="pre">'</span></tt> ( <tt class="docutils literal"><span class="pre">\'</span></tt> とエスケープする。)</p>
</li>
<li><p class="first"><tt class="docutils literal"><span class="pre">(</span></tt> ( <tt class="docutils literal"><span class="pre">\(</span></tt> とエスケープする。)</p>
</li>
<li><p class="first"><tt class="docutils literal"><span class="pre">)</span></tt> ( <tt class="docutils literal"><span class="pre">\)</span></tt> とエスケープする。)</p>
</li>
<li><p class="first"><tt class="docutils literal"><span class="pre">\</span></tt> ( <tt class="docutils literal"><span class="pre">\\</span></tt> とエスケープする。)</p>
</li>
</ul>
</div></blockquote>
<p>エスケープする代わりにクォートすることもできます。クォート構文は <tt class="docutils literal"><span class="pre">&quot;...&quot;</span></tt> または <tt class="docutils literal"><span class="pre">'...'</span></tt> です。 <tt class="docutils literal"><span class="pre">&quot;...&quot;</span></tt> クォート構文中では <tt class="docutils literal"><span class="pre">&quot;</span></tt> を <tt class="docutils literal"><span class="pre">\&quot;</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> にエスケープする必要があります。例えば、 <tt class="docutils literal"><span class="pre">Alice's</span> <span class="pre">brother</span> <span class="pre">(Bob)</span></tt> は <tt class="docutils literal"><span class="pre">&quot;Alice's</span> <span class="pre">brother</span> <span class="pre">(Bob)&quot;</span></tt> あるいは <tt class="docutils literal"><span class="pre">'Alice\'s</span> <span class="pre">brother</span> <span class="pre">(Bob)'</span></tt> とクォートします。</p>
</div>
<div class="section" id="conditional-expression">
<span id="id1"></span><h2>8.10.1.3. 条件式<a class="headerlink" href="#conditional-expression" title="このヘッドラインへのパーマリンク">¶</a></h2>
<p>以下は利用可能な条件式の一覧です。</p>
<div class="section" id="full-text-search-condition">
<span id="id2"></span><h3>8.10.1.3.1. 全文検索条件<a class="headerlink" href="#full-text-search-condition" title="このヘッドラインへのパーマリンク">¶</a></h3>
<p>構文は <tt class="docutils literal"><span class="pre">keyword</span></tt> です。</p>
<p><tt class="docutils literal"><span class="pre">全文検索条件</span></tt> はデフォルトのマッチカラムに対して全文検索するという条件を指定します。マッチカラムとは全文検索対象のカラムのことです。</p>
<p>全文検索に使うデフォルトのマッチカラムを指定する必要があります。マッチカラムは <a class="reference internal" href="../commands/select.html"><em>select</em></a> の <tt class="docutils literal"><span class="pre">--match_columns</span></tt> オプションで指定します。デフォルトのマッチカラムを指定していない場合、この条件式は失敗します。</p>
<p>この条件式は <tt class="docutils literal"><span class="pre">keyword</span></tt> で全文検索をします。 <tt class="docutils literal"><span class="pre">keyword</span></tt> には空白を含めることはできません。 <tt class="docutils literal"><span class="pre">search</span> <span class="pre">keyword</span></tt> というように空白を含んでいる場合は、 <tt class="docutils literal"><span class="pre">search</span></tt> と <tt class="docutils literal"><span class="pre">keyword</span></tt> という2つの全文検索条件を指定したことになります。もし、キーワードに空白を含めたい場合は以下で説明する <tt class="docutils literal"><span class="pre">フレーズ検索条件</span></tt> を使ってください。</p>
<p>以下は簡単な使用例です。</p>
<p>実行例:</p>
<div class="highlight-none"><div class="highlight"><pre>select Entries --match_columns content --query fast
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         2
#       ],
#       [
#         [
#           &quot;_id&quot;,
#           &quot;UInt32&quot;
#         ],
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;content&quot;,
#           &quot;Text&quot;
#         ],
#         [
#           &quot;n_likes&quot;,
#           &quot;UInt32&quot;
#         ]
#       ],
#       [
#         2,
#         &quot;Groonga&quot;,
#         &quot;I started to use groonga. It&#39;s very fast!&quot;,
#         10
#       ],
#       [
#         3,
#         &quot;Mroonga&quot;,
#         &quot;I also started to use mroonga. It&#39;s also very fast! Really fast!&quot;,
#         15
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>この式は <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">content</span></tt> カラムはデフォルトのマッチカラムです。</p>
</div>
<div class="section" id="phrase-search-condition">
<span id="id3"></span><h3>8.10.1.3.2. フレーズ検索条件<a class="headerlink" href="#phrase-search-condition" title="このヘッドラインへのパーマリンク">¶</a></h3>
<p>構文は <tt class="docutils literal"><span class="pre">&quot;search</span> <span class="pre">keyword&quot;</span></tt> です。</p>
<p><tt class="docutils literal"><span class="pre">フレーズ検索条件</span></tt> はデフォルトのマッチカラムに対してフレーズ検索するという条件を指定します。</p>
<p>全文検索に使うデフォルトのマッチカラムを指定する必要があります。マッチカラムは <a class="reference internal" href="../commands/select.html"><em>select</em></a> の <tt class="docutils literal"><span class="pre">--match_columns</span></tt> オプションで指定します。デフォルトのマッチカラムを指定していない場合、この条件式は失敗します。</p>
<p>この条件式は <tt class="docutils literal"><span class="pre">search</span> <span class="pre">keyword</span></tt> でフレーズ検索をします。フレーズ検索は <tt class="docutils literal"><span class="pre">search</span></tt> と <tt class="docutils literal"><span class="pre">keyword</span></tt> がこの順番で隣接して含まれているレコードにマッチします。つまり、 <tt class="docutils literal"><span class="pre">Put</span> <span class="pre">a</span> <span class="pre">search</span> <span class="pre">keyword</span> <span class="pre">in</span> <span class="pre">the</span> <span class="pre">form</span></tt> にはマッチしますが、 <tt class="docutils literal"><span class="pre">Search</span> <span class="pre">by</span> <span class="pre">the</span> <span class="pre">keyword</span></tt> や <tt class="docutils literal"><span class="pre">There</span> <span class="pre">is</span> <span class="pre">a</span> <span class="pre">keyword.</span> <span class="pre">Search</span> <span class="pre">by</span> <span class="pre">it!</span></tt> にはマッチしません。</p>
<p>以下は簡単な使用例です。</p>
<p>実行例:</p>
<div class="highlight-none"><div class="highlight"><pre>select Entries --match_columns content --query &#39;&quot;I started&quot;&#39;
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         1
#       ],
#       [
#         [
#           &quot;_id&quot;,
#           &quot;UInt32&quot;
#         ],
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;content&quot;,
#           &quot;Text&quot;
#         ],
#         [
#           &quot;n_likes&quot;,
#           &quot;UInt32&quot;
#         ]
#       ],
#       [
#         2,
#         &quot;Groonga&quot;,
#         &quot;I started to use groonga. It&#39;s very fast!&quot;,
#         10
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>この式は <tt class="docutils literal"><span class="pre">content</span></tt> カラムの値に <tt class="docutils literal"><span class="pre">I</span> <span class="pre">started</span></tt> というフレーズを含んでいるレコードにマッチします。 <tt class="docutils literal"><span class="pre">I</span> <span class="pre">also</span> <span class="pre">started</span></tt> にはマッチしません。これは <tt class="docutils literal"><span class="pre">I</span></tt> と <tt class="docutils literal"><span class="pre">started</span></tt> が隣接していないからです。</p>
<p><tt class="docutils literal"><span class="pre">content</span></tt> カラムはデフォルトのマッチカラムです。</p>
</div>
<div class="section" id="full-text-search-condition-with-explicit-match-column">
<h3>8.10.1.3.3. 全文検索条件(マッチカラム指定あり)<a class="headerlink" href="#full-text-search-condition-with-explicit-match-column" title="このヘッドラインへのパーマリンク">¶</a></h3>
<p>構文は <tt class="docutils literal"><span class="pre">column:&#64;keyword</span></tt> です。</p>
<p>これは <tt class="docutils literal"><span class="pre">全文検索条件</span></tt> と似ていますが、デフォルトのマッチカラムは必要ありません。全文検索用のマッチカラムは <a class="reference internal" href="../commands/select.html"><em>select</em></a> の <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">--match_columns</span></tt> オプションで指定するデフォルトのマッチカラムは複数回指定することができません。2つめのマッチカラムを指定するためにはこの条件式を使う必要があります。</p>
<p><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> は高度なマッチカラムをサポートしていますが、 <tt class="docutils literal"><span class="pre">全文検索条件(マッチカラム指定あり)</span></tt> はサポートしていません。高度なマッチカラムには以下の機能があります:</p>
<blockquote>
<div><ul class="simple">
<li><p class="first">重みをサポートしている。</p>
</li>
<li><p class="first">複数のカラムを指定できる。</p>
</li>
<li><p class="first">マッチカラムとしてインデックスカラムを使える。</p>
</li>
</ul>
</div></blockquote>
<p>これらについては <a class="reference internal" href="../commands/select.html"><em>select</em></a> の <tt class="docutils literal"><span class="pre">--match_columns</span></tt> オプションを参照してください。</p>
<p>以下は簡単な使用例です。</p>
<p>実行例:</p>
<div class="highlight-none"><div class="highlight"><pre>select Entries --query content:@fast
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         2
#       ],
#       [
#         [
#           &quot;_id&quot;,
#           &quot;UInt32&quot;
#         ],
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;content&quot;,
#           &quot;Text&quot;
#         ],
#         [
#           &quot;n_likes&quot;,
#           &quot;UInt32&quot;
#         ]
#       ],
#       [
#         2,
#         &quot;Groonga&quot;,
#         &quot;I started to use groonga. It&#39;s very fast!&quot;,
#         10
#       ],
#       [
#         3,
#         &quot;Mroonga&quot;,
#         &quot;I also started to use mroonga. It&#39;s also very fast! Really fast!&quot;,
#         15
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>この式は <tt class="docutils literal"><span class="pre">content</span></tt> カラムの値に <tt class="docutils literal"><span class="pre">fast</span></tt> という単語を含んでいるレコードにマッチします。</p>
</div>
<div class="section" id="phrase-search-condition-with-explicit-match-column">
<h3>8.10.1.3.4. フレーズ検索条件(マッチカラム指定あり)<a class="headerlink" href="#phrase-search-condition-with-explicit-match-column" title="このヘッドラインへのパーマリンク">¶</a></h3>
<p>構文は <tt class="docutils literal"><span class="pre">column:&#64;&quot;search</span> <span class="pre">keyword&quot;</span></tt> です。</p>
<p>これは <tt class="docutils literal"><span class="pre">フレーズ検索条件</span></tt> に似ていますが、デフォルトのマッチカラムは必要ありません。フレーズ検索用のマッチカラムは <a class="reference internal" href="../commands/select.html"><em>select</em></a> の <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">フレーズ検索条件</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> の関係と似ています。 <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> を参照してください。</p>
<p>以下は簡単な使用例です。</p>
<p>実行例:</p>
<div class="highlight-none"><div class="highlight"><pre>select Entries --query &#39;content:@&quot;I started&quot;&#39;
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         1
#       ],
#       [
#         [
#           &quot;_id&quot;,
#           &quot;UInt32&quot;
#         ],
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;content&quot;,
#           &quot;Text&quot;
#         ],
#         [
#           &quot;n_likes&quot;,
#           &quot;UInt32&quot;
#         ]
#       ],
#       [
#         2,
#         &quot;Groonga&quot;,
#         &quot;I started to use groonga. It&#39;s very fast!&quot;,
#         10
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>この式は <tt class="docutils literal"><span class="pre">content</span></tt> カラムの値に <tt class="docutils literal"><span class="pre">I</span> <span class="pre">started</span></tt> というフレーズを含んでいるレコードにマッチします。 <tt class="docutils literal"><span class="pre">I</span> <span class="pre">also</span> <span class="pre">started</span></tt> にはマッチしません。これは <tt class="docutils literal"><span class="pre">I</span></tt> と <tt class="docutils literal"><span class="pre">started</span></tt> が隣接していないからです。</p>
</div>
<div class="section" id="prefix-search-condition">
<span id="id4"></span><h3>8.10.1.3.5. 前方一致検索条件<a class="headerlink" href="#prefix-search-condition" title="このヘッドラインへのパーマリンク">¶</a></h3>
<p>構文は <tt class="docutils literal"><span class="pre">column:^value</span></tt> または <tt class="docutils literal"><span class="pre">value*</span></tt> です。</p>
<p>この条件式は <tt class="docutils literal"><span class="pre">value</span></tt> で前方一致検索をします。前方一致検索は <tt class="docutils literal"><span class="pre">value</span></tt> で始まる単語を含むレコードを検索します。</p>
<p>カラムの値を高速に前方一致検索できます。ただし、そのカラムにはインデックスを作成し、そのインデックス用のテーブルをパトリシアトライ( <tt class="docutils literal"><span class="pre">TABLE_PAT_KEY</span></tt> )またはダブル配列トライ( <tt class="docutils literal"><span class="pre">TABLE_DAT_KEY</span></tt> )にしなければいけません。あるいは、パトリシアトライテーブルまたはダブル配列テーブルの <tt class="docutils literal"><span class="pre">_key</span></tt> も高速に前方一致検索できます。 <tt class="docutils literal"><span class="pre">_key</span></tt> にインデックスを作成する必要はありません。</p>
<p>他の種類のテーブルでも前方一致検索を使えますがレコード全件を処理します。レコード数が少ない場合には問題ありませんが、レコード数が多いと時間がかかります。</p>
<p><tt class="docutils literal"><span class="pre">全文検索条件</span></tt> や <tt class="docutils literal"><span class="pre">フレーズ検索条件</span></tt> と異なり、デフォルトのマッチカラムは必要ありません。</p>
<p>以下は簡単な使用例です。</p>
<p>実行例:</p>
<div class="highlight-none"><div class="highlight"><pre>select Entries --query &#39;_key:^Goo&#39;
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         2
#       ],
#       [
#         [
#           &quot;_id&quot;,
#           &quot;UInt32&quot;
#         ],
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;content&quot;,
#           &quot;Text&quot;
#         ],
#         [
#           &quot;n_likes&quot;,
#           &quot;UInt32&quot;
#         ]
#       ],
#       [
#         5,
#         &quot;Good-bye Tritonn&quot;,
#         &quot;I also migrated all Tritonn system!&quot;,
#         3
#       ],
#       [
#         4,
#         &quot;Good-bye Senna&quot;,
#         &quot;I migrated all Senna system!&quot;,
#         3
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>この式は <tt class="docutils literal"><span class="pre">_key</span></tt> カラムの値が <tt class="docutils literal"><span class="pre">Goo</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> がマッチします。</p>
</div>
<div class="section" id="suffix-search-condition">
<span id="id5"></span><h3>8.10.1.3.6. 後方一致検索条件<a class="headerlink" href="#suffix-search-condition" title="このヘッドラインへのパーマリンク">¶</a></h3>
<p>構文は <tt class="docutils literal"><span class="pre">column:$value</span></tt> です。</p>
<p>この条件式は <tt class="docutils literal"><span class="pre">value</span></tt> で後方一致検索します。後方一致検索は <tt class="docutils literal"><span class="pre">value</span></tt> で終わる単語を含むレコードを検索します。</p>
<p>カラムの値を高速に後方一致検索できます。ただし、そのカラムにはインデックスを作成し、そのインデックス用のテーブルを <tt class="docutils literal"><span class="pre">KEY_WITH_SIS</span></tt> フラグ付きのパトリシアトライテーブル( <tt class="docutils literal"><span class="pre">TABLE_PAT_KEY</span></tt> )にしなければいけません。 <tt class="docutils literal"><span class="pre">KEY_WITH_SIS</span></tt> フラグ付きのパトリシアトライテーブル( <tt class="docutils literal"><span class="pre">TABLE_PAT_KEY</span></tt> )の <tt class="docutils literal"><span class="pre">_key</span></tt> 擬似カラムの値も高速に後方一致検索できます。 <tt class="docutils literal"><span class="pre">_key</span></tt> にはインデックスを作成する必要はありません。 <tt class="docutils literal"><span class="pre">_key</span></tt> ベースの高速な後方一致検索よりもカラムベースの高速な後方一致検索を使うことをおすすめします。 <tt class="docutils literal"><span class="pre">_key</span></tt> ベースの高速な後方一致検索は自動的に登録された部分文字列も返ってきます。(TODO: 後方一致検索に関するドキュメントを書いてここからリンクを張る。)</p>
<div class="admonition note">
<p class="first admonition-title">ノート</p>
<p class="last">高速な後方一致検索は日本語のひらがななど非ASCII文字にしか使えません。ASCII文字には高速な後方一致検索を使えません。</p>
</div>
<p>後方一致検索は他の種類のテーブルもしくはパトリシアトライを <tt class="docutils literal"><span class="pre">KEY_WITH_SIS</span></tt> フラグなしで使用しているテーブルに対しても使えますが、レコード全件を処理します。レコード数が少ない場合には問題ありませんが、レコード数が多いと時間がかかります。</p>
<p><tt class="docutils literal"><span class="pre">全文検索条件</span></tt> や <tt class="docutils literal"><span class="pre">フレーズ検索条件</span></tt> と異なり、デフォルトのマッチカラムは必要ありません。</p>
<p>簡単な例です。ASCII文字ではない文字である日本語のひらがなに対して高速な後方一致検索をしています。</p>
<p>実行例:</p>
<div class="highlight-none"><div class="highlight"><pre>table_create Titles TABLE_NO_KEY
# [[0, 1337566253.89858, 0.000355720520019531], true]
column_create Titles content COLUMN_SCALAR ShortText
# [[0, 1337566253.89858, 0.000355720520019531], true]
table_create SuffixSearchTerms TABLE_PAT_KEY|KEY_WITH_SIS ShortText
# [[0, 1337566253.89858, 0.000355720520019531], true]
column_create SuffixSearchTerms index COLUMN_INDEX Titles content
# [[0, 1337566253.89858, 0.000355720520019531], true]
load --table Titles
[
{&quot;content&quot;: &quot;ぐるんが&quot;},
{&quot;content&quot;: &quot;むるんが&quot;},
{&quot;content&quot;: &quot;せな&quot;},
{&quot;content&quot;: &quot;とりとん&quot;}
]
# [[0, 1337566253.89858, 0.000355720520019531], 4]
select Titles --query &#39;content:$んが&#39;
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         2
#       ],
#       [
#         [
#           &quot;_id&quot;,
#           &quot;UInt32&quot;
#         ],
#         [
#           &quot;content&quot;,
#           &quot;ShortText&quot;
#         ]
#       ],
#       [
#         2,
#         &quot;むるんが&quot;
#       ],
#       [
#         1,
#         &quot;ぐるんが&quot;
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>この式は <tt class="docutils literal"><span class="pre">content</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> にマッチします。</p>
</div>
<div class="section" id="equal-condition">
<h3>8.10.1.3.7. 等価条件<a class="headerlink" href="#equal-condition" title="このヘッドラインへのパーマリンク">¶</a></h3>
<p>構文は <tt class="docutils literal"><span class="pre">column:value</span></tt> です。</p>
<p><tt class="docutils literal"><span class="pre">column</span></tt> の値が <tt class="docutils literal"><span class="pre">value</span></tt> と等しいレコードにマッチします。</p>
<p><tt class="docutils literal"><span class="pre">全文検索条件</span></tt> や <tt class="docutils literal"><span class="pre">フレーズ検索条件</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
#       ],
#       [
#         [
#           &quot;_id&quot;,
#           &quot;UInt32&quot;
#         ],
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;content&quot;,
#           &quot;Text&quot;
#         ],
#         [
#           &quot;n_likes&quot;,
#           &quot;UInt32&quot;
#         ]
#       ],
#       [
#         2,
#         &quot;Groonga&quot;,
#         &quot;I started to use groonga. It&#39;s very fast!&quot;,
#         10
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>この式は <tt class="docutils literal"><span class="pre">_key</span></tt> カラムの値が <tt class="docutils literal"><span class="pre">Groonga</span></tt> のレコードにマッチします。</p>
</div>
<div class="section" id="not-equal-condition">
<h3>8.10.1.3.8. 不等価条件<a class="headerlink" href="#not-equal-condition" title="このヘッドラインへのパーマリンク">¶</a></h3>
<p>構文は <tt class="docutils literal"><span class="pre">column:!value</span></tt> です。</p>
<p><tt class="docutils literal"><span class="pre">column</span></tt> の値が <tt class="docutils literal"><span class="pre">value</span></tt> と等しくないレコードにマッチします。</p>
<p><tt class="docutils literal"><span class="pre">全文検索条件</span></tt> や <tt class="docutils literal"><span class="pre">フレーズ検索条件</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
#   ],
#   [
#     [
#       [
#         4
#       ],
#       [
#         [
#           &quot;_id&quot;,
#           &quot;UInt32&quot;
#         ],
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;content&quot;,
#           &quot;Text&quot;
#         ],
#         [
#           &quot;n_likes&quot;,
#           &quot;UInt32&quot;
#         ]
#       ],
#       [
#         4,
#         &quot;Good-bye Senna&quot;,
#         &quot;I migrated all Senna system!&quot;,
#         3
#       ],
#       [
#         5,
#         &quot;Good-bye Tritonn&quot;,
#         &quot;I also migrated all Tritonn system!&quot;,
#         3
#       ],
#       [
#         3,
#         &quot;Mroonga&quot;,
#         &quot;I also started to use mroonga. It&#39;s also very fast! Really fast!&quot;,
#         15
#       ],
#       [
#         1,
#         &quot;The first post!&quot;,
#         &quot;Welcome! This is my first post!&quot;,
#         5
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>この式は <tt class="docutils literal"><span class="pre">_key</span></tt> カラムの値が <tt class="docutils literal"><span class="pre">Groonga</span></tt> ではないレコードにマッチします。</p>
</div>
<div class="section" id="less-than-condition">
<h3>8.10.1.3.9. 小なり条件<a class="headerlink" href="#less-than-condition" title="このヘッドラインへのパーマリンク">¶</a></h3>
<p>構文は <tt class="docutils literal"><span class="pre">column:&lt;value</span></tt> です。</p>
<p><tt class="docutils literal"><span class="pre">column</span></tt> の値が <tt class="docutils literal"><span class="pre">value</span></tt> 未満のレコードにマッチします。</p>
<p><tt class="docutils literal"><span class="pre">column</span></tt> の型が <tt class="docutils literal"><span class="pre">Int32</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></tt> の型が <tt class="docutils literal"><span class="pre">ShortText</span></tt> のような文字列型の場合は <tt class="docutils literal"><span class="pre">column</span></tt> の値と <tt class="docutils literal"><span class="pre">value</span></tt> はビット列として比較します。</p>
<p><tt class="docutils literal"><span class="pre">全文検索条件</span></tt> や <tt class="docutils literal"><span class="pre">フレーズ検索条件</span></tt> と異なり、デフォルトのマッチカラムは必要ありません。</p>
<p>以下は簡単な使用例です。</p>
<p>実行例:</p>
<div class="highlight-none"><div class="highlight"><pre>select Entries --query n_likes:&lt;10
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         3
#       ],
#       [
#         [
#           &quot;_id&quot;,
#           &quot;UInt32&quot;
#         ],
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;content&quot;,
#           &quot;Text&quot;
#         ],
#         [
#           &quot;n_likes&quot;,
#           &quot;UInt32&quot;
#         ]
#       ],
#       [
#         4,
#         &quot;Good-bye Senna&quot;,
#         &quot;I migrated all Senna system!&quot;,
#         3
#       ],
#       [
#         5,
#         &quot;Good-bye Tritonn&quot;,
#         &quot;I also migrated all Tritonn system!&quot;,
#         3
#       ],
#       [
#         1,
#         &quot;The first post!&quot;,
#         &quot;Welcome! This is my first post!&quot;,
#         5
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>この式は <tt class="docutils literal"><span class="pre">n_likes</span></tt> カラムの値が <tt class="docutils literal"><span class="pre">10</span></tt> より小さいレコードにマッチします。</p>
</div>
<div class="section" id="greater-than-condition">
<h3>8.10.1.3.10. 大なり条件<a class="headerlink" href="#greater-than-condition" title="このヘッドラインへのパーマリンク">¶</a></h3>
<p>構文は <tt class="docutils literal"><span class="pre">column:&gt;value</span></tt> です。</p>
<p><tt class="docutils literal"><span class="pre">column</span></tt> の値が <tt class="docutils literal"><span class="pre">value</span></tt> より大きいレコードにマッチします。</p>
<p><tt class="docutils literal"><span class="pre">column</span></tt> の型が <tt class="docutils literal"><span class="pre">Int32</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></tt> の型が <tt class="docutils literal"><span class="pre">ShortText</span></tt> のような文字列型の場合は <tt class="docutils literal"><span class="pre">column</span></tt> の値と <tt class="docutils literal"><span class="pre">value</span></tt> はビット列として比較します。</p>
<p><tt class="docutils literal"><span class="pre">全文検索条件</span></tt> や <tt class="docutils literal"><span class="pre">フレーズ検索条件</span></tt> と異なり、デフォルトのマッチカラムは必要ありません。</p>
<p>以下は簡単な使用例です。</p>
<p>実行例:</p>
<div class="highlight-none"><div class="highlight"><pre>select Entries --query n_likes:&gt;10
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         1
#       ],
#       [
#         [
#           &quot;_id&quot;,
#           &quot;UInt32&quot;
#         ],
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;content&quot;,
#           &quot;Text&quot;
#         ],
#         [
#           &quot;n_likes&quot;,
#           &quot;UInt32&quot;
#         ]
#       ],
#       [
#         3,
#         &quot;Mroonga&quot;,
#         &quot;I also started to use mroonga. It&#39;s also very fast! Really fast!&quot;,
#         15
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>この式は <tt class="docutils literal"><span class="pre">n_likes</span></tt> カラムの値が <tt class="docutils literal"><span class="pre">10</span></tt> より大きいレコードにマッチします。</p>
</div>
<div class="section" id="less-than-or-equal-to-condition">
<h3>8.10.1.3.11. 以下条件<a class="headerlink" href="#less-than-or-equal-to-condition" title="このヘッドラインへのパーマリンク">¶</a></h3>
<p>構文は <tt class="docutils literal"><span class="pre">column:&lt;=value</span></tt> です。</p>
<p><tt class="docutils literal"><span class="pre">column</span></tt> の値が <tt class="docutils literal"><span class="pre">value</span></tt> 以下のレコードにマッチします。</p>
<p><tt class="docutils literal"><span class="pre">column</span></tt> の型が <tt class="docutils literal"><span class="pre">Int32</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></tt> の型が <tt class="docutils literal"><span class="pre">ShortText</span></tt> のような文字列型の場合は <tt class="docutils literal"><span class="pre">column</span></tt> の値と <tt class="docutils literal"><span class="pre">value</span></tt> はビット列として比較します。</p>
<p><tt class="docutils literal"><span class="pre">全文検索条件</span></tt> や <tt class="docutils literal"><span class="pre">フレーズ検索条件</span></tt> と異なり、デフォルトのマッチカラムは必要ありません。</p>
<p>以下は簡単な使用例です。</p>
<p>実行例:</p>
<div class="highlight-none"><div class="highlight"><pre>select Entries --query n_likes:&lt;=10
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         4
#       ],
#       [
#         [
#           &quot;_id&quot;,
#           &quot;UInt32&quot;
#         ],
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;content&quot;,
#           &quot;Text&quot;
#         ],
#         [
#           &quot;n_likes&quot;,
#           &quot;UInt32&quot;
#         ]
#       ],
#       [
#         4,
#         &quot;Good-bye Senna&quot;,
#         &quot;I migrated all Senna system!&quot;,
#         3
#       ],
#       [
#         5,
#         &quot;Good-bye Tritonn&quot;,
#         &quot;I also migrated all Tritonn system!&quot;,
#         3
#       ],
#       [
#         2,
#         &quot;Groonga&quot;,
#         &quot;I started to use groonga. It&#39;s very fast!&quot;,
#         10
#       ],
#       [
#         1,
#         &quot;The first post!&quot;,
#         &quot;Welcome! This is my first post!&quot;,
#         5
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>この式は <tt class="docutils literal"><span class="pre">n_likes</span></tt> カラムの値が <tt class="docutils literal"><span class="pre">10</span></tt> 以下のレコードにマッチします。</p>
</div>
<div class="section" id="greater-than-or-equal-to-condition">
<h3>8.10.1.3.12. 以上条件<a class="headerlink" href="#greater-than-or-equal-to-condition" title="このヘッドラインへのパーマリンク">¶</a></h3>
<p>構文は <tt class="docutils literal"><span class="pre">column:&gt;=value</span></tt> です。</p>
<p><tt class="docutils literal"><span class="pre">column</span></tt> の値が <tt class="docutils literal"><span class="pre">value</span></tt> 以上のレコードにマッチします。</p>
<p><tt class="docutils literal"><span class="pre">column</span></tt> の型が <tt class="docutils literal"><span class="pre">Int32</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></tt> の型が <tt class="docutils literal"><span class="pre">ShortText</span></tt> のような文字列型の場合は <tt class="docutils literal"><span class="pre">column</span></tt> の値と <tt class="docutils literal"><span class="pre">value</span></tt> はビット列として比較します。</p>
<p><tt class="docutils literal"><span class="pre">全文検索条件</span></tt> や <tt class="docutils literal"><span class="pre">フレーズ検索条件</span></tt> と異なり、デフォルトのマッチカラムは必要ありません。</p>
<p>以下は簡単な使用例です。</p>
<p>実行例:</p>
<div class="highlight-none"><div class="highlight"><pre>select Entries --query n_likes:&gt;=10
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         2
#       ],
#       [
#         [
#           &quot;_id&quot;,
#           &quot;UInt32&quot;
#         ],
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;content&quot;,
#           &quot;Text&quot;
#         ],
#         [
#           &quot;n_likes&quot;,
#           &quot;UInt32&quot;
#         ]
#       ],
#       [
#         2,
#         &quot;Groonga&quot;,
#         &quot;I started to use groonga. It&#39;s very fast!&quot;,
#         10
#       ],
#       [
#         3,
#         &quot;Mroonga&quot;,
#         &quot;I also started to use mroonga. It&#39;s also very fast! Really fast!&quot;,
#         15
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>この式は <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="combined-expression">
<span id="id6"></span><h2>8.10.1.4. 結合式<a class="headerlink" href="#combined-expression" title="このヘッドラインへのパーマリンク">¶</a></h2>
<p>以下は利用可能な結合式のリストです。</p>
<div class="section" id="logical-or">
<h3>8.10.1.4.1. 論理和<a class="headerlink" href="#logical-or" title="このヘッドラインへのパーマリンク">¶</a></h3>
<p>構文は <tt class="docutils literal"><span class="pre">a</span> <span class="pre">OR</span> <span class="pre">b</span></tt> です。</p>
<p><tt class="docutils literal"><span class="pre">a</span></tt> と <tt class="docutils literal"><span class="pre">b</span></tt> は条件式または結合式または代入式です。</p>
<p><tt class="docutils literal"><span class="pre">a</span></tt> と <tt class="docutils literal"><span class="pre">b</span></tt> のうち少なくともひとつの式がマッチすれば <tt class="docutils literal"><span class="pre">a</span> <span class="pre">OR</span> <span class="pre">b</span></tt> はマッチします。</p>
<p>以下は簡単な使用例です。</p>
<p>実行例:</p>
<div class="highlight-none"><div class="highlight"><pre>select Entries --query &#39;n_likes:&gt;10 OR content:@senna&#39;
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         2
#       ],
#       [
#         [
#           &quot;_id&quot;,
#           &quot;UInt32&quot;
#         ],
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;content&quot;,
#           &quot;Text&quot;
#         ],
#         [
#           &quot;n_likes&quot;,
#           &quot;UInt32&quot;
#         ]
#       ],
#       [
#         3,
#         &quot;Mroonga&quot;,
#         &quot;I also started to use mroonga. It&#39;s also very fast! Really fast!&quot;,
#         15
#       ],
#       [
#         4,
#         &quot;Good-bye Senna&quot;,
#         &quot;I migrated all Senna system!&quot;,
#         3
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>この式は <tt class="docutils literal"><span class="pre">n_likes</span></tt> カラムの値が <tt class="docutils literal"><span class="pre">10</span></tt> より大きいか <tt class="docutils literal"><span class="pre">content</span></tt> カラムの値に <tt class="docutils literal"><span class="pre">senna</span></tt> という単語を含んでいるレコードにマッチします。</p>
</div>
<div class="section" id="logical-and">
<h3>8.10.1.4.2. 論理積<a class="headerlink" href="#logical-and" title="このヘッドラインへのパーマリンク">¶</a></h3>
<p>構文は <tt class="docutils literal"><span class="pre">a</span> <span class="pre">+</span> <span class="pre">b</span></tt> です。あるいは単に <tt class="docutils literal"><span class="pre">a</span> <span class="pre">b</span></tt> と書くこともできます。</p>
<p><tt class="docutils literal"><span class="pre">a</span></tt> と <tt class="docutils literal"><span class="pre">b</span></tt> は条件式または結合式または代入式です。</p>
<p><tt class="docutils literal"><span class="pre">a</span></tt> と <tt class="docutils literal"><span class="pre">b</span></tt> の両方にマッチすれば <tt class="docutils literal"><span class="pre">a</span> <span class="pre">+</span> <span class="pre">b</span></tt> はマッチします。</p>
<p><tt class="docutils literal"><span class="pre">+a</span></tt> というように最初の式に <tt class="docutils literal"><span class="pre">+</span></tt> を指定することもできます。この場合は <tt class="docutils literal"><span class="pre">+</span></tt> は単に無視されます。</p>
<p>以下は簡単な使用例です。</p>
<p>実行例:</p>
<div class="highlight-none"><div class="highlight"><pre>select Entries --query &#39;n_likes:&gt;=10 + content:@groonga&#39;
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         1
#       ],
#       [
#         [
#           &quot;_id&quot;,
#           &quot;UInt32&quot;
#         ],
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;content&quot;,
#           &quot;Text&quot;
#         ],
#         [
#           &quot;n_likes&quot;,
#           &quot;UInt32&quot;
#         ]
#       ],
#       [
#         2,
#         &quot;Groonga&quot;,
#         &quot;I started to use groonga. It&#39;s very fast!&quot;,
#         10
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>この式は <tt class="docutils literal"><span class="pre">n_likes</span></tt> カラムの値が <tt class="docutils literal"><span class="pre">10</span></tt> 以上で <tt class="docutils literal"><span class="pre">content</span></tt> カラムの値に <tt class="docutils literal"><span class="pre">groonga</span></tt> という単語を含むレコードにマッチします。</p>
</div>
<div class="section" id="logical-not">
<h3>8.10.1.4.3. 論理否定<a class="headerlink" href="#logical-not" title="このヘッドラインへのパーマリンク">¶</a></h3>
<p>構文は <tt class="docutils literal"><span class="pre">a</span> <span class="pre">-</span> <span class="pre">b</span></tt> です。</p>
<p><tt class="docutils literal"><span class="pre">a</span></tt> と <tt class="docutils literal"><span class="pre">b</span></tt> は条件式または結合式または代入式です。</p>
<p><tt class="docutils literal"><span class="pre">a</span></tt> にマッチして <tt class="docutils literal"><span class="pre">b</span></tt> にマッチしなければ、 <tt class="docutils literal"><span class="pre">a</span> <span class="pre">-</span> <span class="pre">b</span></tt> はマッチします。</p>
<p><tt class="docutils literal"><span class="pre">-a</span></tt> というように最初の式に <tt class="docutils literal"><span class="pre">-</span></tt> を指定することはできません。この場合は構文エラーになります。</p>
<p>以下は簡単な使用例です。</p>
<p>実行例:</p>
<div class="highlight-none"><div class="highlight"><pre>select Entries --query &#39;n_likes:&gt;=10 - content:@groonga&#39;
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         1
#       ],
#       [
#         [
#           &quot;_id&quot;,
#           &quot;UInt32&quot;
#         ],
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;content&quot;,
#           &quot;Text&quot;
#         ],
#         [
#           &quot;n_likes&quot;,
#           &quot;UInt32&quot;
#         ]
#       ],
#       [
#         3,
#         &quot;Mroonga&quot;,
#         &quot;I also started to use mroonga. It&#39;s also very fast! Really fast!&quot;,
#         15
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>この式は <tt class="docutils literal"><span class="pre">n_likes</span></tt> カラムの値が <tt class="docutils literal"><span class="pre">10</span></tt> 以上で <tt class="docutils literal"><span class="pre">content</span></tt> カラムの値に <tt class="docutils literal"><span class="pre">groonga</span></tt> という単語を含まないレコードにマッチします。</p>
</div>
<div class="section" id="grouping">
<h3>8.10.1.4.4. グループ化<a class="headerlink" href="#grouping" title="このヘッドラインへのパーマリンク">¶</a></h3>
<p>構文は <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">(...)</span></tt> は1つ以上の式をグループ化します。グループ化された式は1つの式として処理されます。 <tt class="docutils literal"><span class="pre">a</span> <span class="pre">b</span> <span class="pre">OR</span> <span class="pre">c</span></tt> は <tt class="docutils literal"><span class="pre">a</span></tt> と <tt class="docutils literal"><span class="pre">b</span></tt> の両方がマッチするか、 <tt class="docutils literal"><span class="pre">c</span></tt> がマッチすれば式全体がマッチする、という意味になります。 <tt class="docutils literal"><span class="pre">a</span> <span class="pre">(b</span> <span class="pre">OR</span> <span class="pre">c)</span></tt> は <tt class="docutils literal"><span class="pre">a</span></tt> がマッチして <tt class="docutils literal"><span class="pre">b</span></tt> と <tt class="docutils literal"><span class="pre">c</span></tt> はどちらか一方がマッチすれば式全体がマッチする、という意味になります。</p>
<p>以下は簡単な使用例です。</p>
<p>実行例:</p>
<div class="highlight-none"><div class="highlight"><pre>select Entries --query &#39;n_likes:&lt;5 content:@senna OR content:@fast&#39;
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         3
#       ],
#       [
#         [
#           &quot;_id&quot;,
#           &quot;UInt32&quot;
#         ],
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;content&quot;,
#           &quot;Text&quot;
#         ],
#         [
#           &quot;n_likes&quot;,
#           &quot;UInt32&quot;
#         ]
#       ],
#       [
#         4,
#         &quot;Good-bye Senna&quot;,
#         &quot;I migrated all Senna system!&quot;,
#         3
#       ],
#       [
#         2,
#         &quot;Groonga&quot;,
#         &quot;I started to use groonga. It&#39;s very fast!&quot;,
#         10
#       ],
#       [
#         3,
#         &quot;Mroonga&quot;,
#         &quot;I also started to use mroonga. It&#39;s also very fast! Really fast!&quot;,
#         15
#       ]
#     ]
#   ]
# ]
select Entries --query &#39;n_likes:&lt;5 (content:@senna OR content:@fast)&#39;
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         1
#       ],
#       [
#         [
#           &quot;_id&quot;,
#           &quot;UInt32&quot;
#         ],
#         [
#           &quot;_key&quot;,
#           &quot;ShortText&quot;
#         ],
#         [
#           &quot;content&quot;,
#           &quot;Text&quot;
#         ],
#         [
#           &quot;n_likes&quot;,
#           &quot;UInt32&quot;
#         ]
#       ],
#       [
#         4,
#         &quot;Good-bye Senna&quot;,
#         &quot;I migrated all Senna system!&quot;,
#         3
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>最初の式はグループ化していません。この式は <tt class="docutils literal"><span class="pre">n_likes:&lt;5</span></tt> と <tt class="docutils literal"><span class="pre">content:&#64;senna</span></tt> の両方がマッチするか <tt class="docutils literal"><span class="pre">content:&#64;fast</span></tt> がマッチするレコードにマッチします。</p>
<p>2番目の式はグループ化しています。この式は <tt class="docutils literal"><span class="pre">n_likes:&lt;5</span></tt> にマッチして、 <tt class="docutils literal"><span class="pre">content:&#64;senna</span></tt> と <tt class="docutils literal"><span class="pre">content:&#64;fast</span></tt> は少なくともどちらか一方にマッチするレコードにマッチします。</p>
</div>
</div>
<div class="section" id="assignment-expression">
<h2>8.10.1.5. 代入式<a class="headerlink" href="#assignment-expression" title="このヘッドラインへのパーマリンク">¶</a></h2>
<p>このセクションは高度なユーザー向けです。それは、代入式は <a class="reference internal" href="../commands/select.html"><em>select</em></a> の <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> を指定してください。</p>
<p>クエリー構文における代入式にはいくつか制限があります。代入にはクエリー構文の代りに <a class="reference internal" href="script_syntax.html"><em>スクリプト構文</em></a> を使ってください。</p>
<p>代入式の構文は1つだけです。 <tt class="docutils literal"><span class="pre">column:=value</span></tt> となります。</p>
<p><tt class="docutils literal"><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">value</span></tt> は <tt class="docutils literal"><span class="pre">column</span></tt> の型へと自動的にキャストされます。 キャストにはいくつか制限があります。例えば <tt class="docutils literal"><span class="pre">true</span></tt> や <tt class="docutils literal"><span class="pre">false</span></tt> といった真偽値のリテラルを <tt class="docutils literal"><span class="pre">Bool</span></tt> 型のカラムに使用することができません。 <tt class="docutils literal"><span class="pre">false</span></tt> については空文字列を使う必要がありますが、クエリー構文は <tt class="docutils literal"><span class="pre">column:=</span></tt> 構文をサポートしていません。</p>
<p>キャストについては <a class="reference internal" href="../cast.html"><em>Cast</em></a> を参照してください。</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="#">8.10.1. クエリー構文</a><ul>
<li><a class="reference internal" href="#sample-data">8.10.1.1. サンプルデータ</a></li>
<li><a class="reference internal" href="#escape">8.10.1.2. エスケープ</a></li>
<li><a class="reference internal" href="#conditional-expression">8.10.1.3. 条件式</a><ul>
<li><a class="reference internal" href="#full-text-search-condition">8.10.1.3.1. 全文検索条件</a></li>
<li><a class="reference internal" href="#phrase-search-condition">8.10.1.3.2. フレーズ検索条件</a></li>
<li><a class="reference internal" href="#full-text-search-condition-with-explicit-match-column">8.10.1.3.3. 全文検索条件(マッチカラム指定あり)</a></li>
<li><a class="reference internal" href="#phrase-search-condition-with-explicit-match-column">8.10.1.3.4. フレーズ検索条件(マッチカラム指定あり)</a></li>
<li><a class="reference internal" href="#prefix-search-condition">8.10.1.3.5. 前方一致検索条件</a></li>
<li><a class="reference internal" href="#suffix-search-condition">8.10.1.3.6. 後方一致検索条件</a></li>
<li><a class="reference internal" href="#equal-condition">8.10.1.3.7. 等価条件</a></li>
<li><a class="reference internal" href="#not-equal-condition">8.10.1.3.8. 不等価条件</a></li>
<li><a class="reference internal" href="#less-than-condition">8.10.1.3.9. 小なり条件</a></li>
<li><a class="reference internal" href="#greater-than-condition">8.10.1.3.10. 大なり条件</a></li>
<li><a class="reference internal" href="#less-than-or-equal-to-condition">8.10.1.3.11. 以下条件</a></li>
<li><a class="reference internal" href="#greater-than-or-equal-to-condition">8.10.1.3.12. 以上条件</a></li>
</ul>
</li>
<li><a class="reference internal" href="#combined-expression">8.10.1.4. 結合式</a><ul>
<li><a class="reference internal" href="#logical-or">8.10.1.4.1. 論理和</a></li>
<li><a class="reference internal" href="#logical-and">8.10.1.4.2. 論理積</a></li>
<li><a class="reference internal" href="#logical-not">8.10.1.4.3. 論理否定</a></li>
<li><a class="reference internal" href="#grouping">8.10.1.4.4. グループ化</a></li>
</ul>
</li>
<li><a class="reference internal" href="#assignment-expression">8.10.1.5. 代入式</a></li>
</ul>
</li>
</ul>

  <h4>前のトピックへ</h4>
  <p class="topless"><a href="../grn_expr.html"
                        title="前の章へ">8.10. grn_expr</a></p>
  <h4>次のトピックへ</h4>
  <p class="topless"><a href="script_syntax.html"
                        title="次の章へ">8.10.2. スクリプト構文</a></p>
  <h3>このページ</h3>
  <ul class="this-page-menu">
    <li><a href="../../_sources/reference/grn_expr/query_syntax.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="script_syntax.html" title="8.10.2. スクリプト構文"
             >次へ</a> |</li>
        <li class="right" >
          <a href="../grn_expr.html" title="8.10. grn_expr"
             >前へ</a> |</li>
        <li><a href="../../index.html">groonga v3.0.5ドキュメント</a> &raquo;</li>
          <li><a href="../../reference.html" >8. リファレンスマニュアル</a> &raquo;</li>
          <li><a href="../grn_expr.html" >8.10. grn_expr</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2009-2013, Brazil, Inc.
    </div>
  </body>
</html>