[Groonga-commit] pgroonga/pgroonga.github.io at 65eb20d [master] Translate @@ for jsonb

Back to archive index

Kouhei Sutou null+****@clear*****
Sun Oct 25 20:50:14 JST 2015


Kouhei Sutou	2015-10-25 20:50:14 +0900 (Sun, 25 Oct 2015)

  New Revision: 65eb20df7f22e2ca730ca8e355eedd3d3b0bca4f
  https://github.com/pgroonga/pgroonga.github.io/commit/65eb20df7f22e2ca730ca8e355eedd3d3b0bca4f

  Message:
    Translate @@ for jsonb

  Added files:
    _po/ja/reference/operators/jsonb-query.po
    ja/reference/operators/jsonb-query.md
  Modified files:
    reference/operators/jsonb-query.md

  Added: _po/ja/reference/operators/jsonb-query.po (+409 -0) 100644
===================================================================
--- /dev/null
+++ _po/ja/reference/operators/jsonb-query.po    2015-10-25 20:50:14 +0900 (657836e)
@@ -0,0 +1,409 @@
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"PO-Revision-Date: 2015-10-25 20:50+0900\n"
+"Language: ja\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=1; plural=0;\n"
+
+msgid ""
+"---\n"
+"title: \"@@ operator for jsonb type\"\n"
+"layout: en\n"
+"---"
+msgstr ""
+"---\n"
+"title: \"jsonb型用の@@演算子\"\n"
+"layout: ja\n"
+"---"
+
+msgid "# `@@` operator for `jsonb` type"
+msgstr "# `jsonb`型用の`@@`演算子"
+
+msgid "## Summary"
+msgstr "## 概要"
+
+msgid ""
+"`@@` operator is a PGroonga original operator. You can use complex condition t"
+"hat can't be written by [`@>` operator](jsonb-contain.html) such as range sear"
+"ch."
+msgstr ""
+"`@@`演算子はPGroonga独自の演算子です。範囲検索のような[`@>`演算子](jsonb-contain.html)では書けないような複雑な条件を書"
+"くことができます。"
+
+msgid ""
+"If you know [JsQuery](https://github.com/postgrespro/jsquery), you can underst"
+"and like \"PGroonga provides `jsonb` type related search features that are simi"
+"lar to JsQuery with different syntax\"."
+msgstr ""
+"もし[JsQuery](https://github.com/postgrespro/jsquery)を知っているなら、「PGroongaはJsQueryが"
+"提供しているような`jsonb`型用の検索機能を違う構文で提供している」と理解してください。"
+
+msgid "## Syntax"
+msgstr "## 構文"
+
+msgid "Here is the syntax of this operator:"
+msgstr "この演算子の構文は次の通りです。"
+
+msgid ""
+"```sql\n"
+"jsonb_column @@ condition\n"
+"```"
+msgstr ""
+
+msgid "`jsonb_column` is a column that its type is `jsonb`."
+msgstr "`jsonb_column`は`jsonb`型のカラムです。"
+
+msgid ""
+"`condition` is a `text` value used as query. It uses [Groonga's script syntax]"
+"(http://groonga.org/docs/reference/grn_expr/script_syntax.html)."
+msgstr ""
+"`condition`はクエリーとして使う`text`型の値です。[Groongaのスクリプト構文](http://groonga.org/ja/docs/"
+"reference/grn_expr/script_syntax.html)を使います。"
+
+msgid ""
+"The operator returns `true` when `condition` matches `jsonb_column` value, `fa"
+"lse` otherwise."
+msgstr "この演算子は`condition`が`jsonb_column`の値にマッチしたら`true`を返し、マッチしなかったら`false`を返します。"
+
+msgid "## Usage"
+msgstr "## 使い方"
+
+msgid "Here are sample schema and data for examples:"
+msgstr "例に使うサンプルスキーマとデータは次の通りです。"
+
+msgid ""
+"```sql\n"
+"CREATE TABLE logs (\n"
+"  record jsonb\n"
+");"
+msgstr ""
+
+msgid "CREATE INDEX pgroonga_logs_index ON logs USING pgroonga (record);"
+msgstr ""
+
+msgid ""
+"INSERT INTO logs\n"
+"     VALUES ('{\n"
+"                \"message\": \"Server is started.\",\n"
+"                \"host\":    \"www.example.com\",\n"
+"                \"tags\": [\n"
+"                  \"web\",\n"
+"                  \"example.com\"\n"
+"                ]\n"
+"              }');\n"
+"INSERT INTO logs\n"
+"     VALUES ('{\n"
+"                \"message\": \"GET /\",\n"
+"                \"host\":    \"www.example.com\",\n"
+"                \"code\":    200,\n"
+"                \"tags\": [\n"
+"                  \"web\",\n"
+"                  \"example.com\"\n"
+"                ]\n"
+"              }');\n"
+"INSERT INTO logs\n"
+"     VALUES ('{\n"
+"                \"message\": \"Send to <info �� example.com>.\",\n"
+"                \"host\":    \"mail.example.net\",\n"
+"                \"tags\": [\n"
+"                  \"mail\",\n"
+"                  \"example.net\"\n"
+"                ]\n"
+"              }');\n"
+"```"
+msgstr ""
+
+msgid "Disable sequential scan:"
+msgstr "シーケンシャルスキャンを無効にします。"
+
+msgid ""
+"```sql\n"
+"SET enable_seqscan = off;\n"
+"```"
+msgstr ""
+
+msgid ""
+"You need to understand how PGroonga creates index against `jsonb` type value t"
+"o create search condition."
+msgstr "検索条件を作るためにはPGroongaが`jsonb`型のデータ用のインデックスをどのように作るかを理解する必要があります。"
+
+msgid ""
+"PGroonga splits a `jsonb` type value into values and then creates indexes agai"
+"nst these values. In SQL, think about the following schema:"
+msgstr ""
+"PGroongaは`jsonb`型の値を複数の値に分割し、それらの分割した値に対してインデックスを作成します。SQLで言うと次のスキーマを作っていると考えて"
+"ください。"
+
+msgid ""
+"```sql\n"
+"CREATE TABLE values (\n"
+"  key text PRIMARY KEY,\n"
+"  path text,\n"
+"  paths text[],\n"
+"  type text,\n"
+"  boolean boolean,\n"
+"  number double precision,\n"
+"  string text,\n"
+"  size numeric\n"
+");\n"
+"```"
+msgstr ""
+
+msgid "Here are descriptions of column:"
+msgstr "各カラムの説明は次の通りです。"
+
+msgid ""
+"  * `key`: The ID of the value. If value has the same path and content, `key` "
+"is the same value. Key format is `'${PATH}|${TYPE}|${VALUE}'`. It's not used i"
+"n search condition."
+msgstr ""
+"  * `key`:値のIDです。値が違うパスで違う内容なら`key`は違う値になります。キーのフォーマットは`'${パス}|${種類}|${値}'`です。"
+"このカラムは検索条件には使いません。"
+
+msgid ""
+"  * `path`: The path of the value from root. It uses [jq](https://stedolan.git"
+"hub.io/jq/) compatible format. Object is `[\"${ELEMENT_NAME}\"]`, array is `[]`."
+" For example, the path of `\"web\"` in `{\"tags\": [\"web\"]}` is `.[\"tags\"][]`. If "
+"you know absolute path of the value, you can use this value in search conditio"
+"n."
+msgstr ""
+"  * `path`:値がある位置へのルートからのパスです。[jq](https://stedolan.github.io/jq/)互換のフォーマットです。"
+"オブジェクトは`[\"${要素名}\"]`で配列は`[]`です。たとえば、`{\"tags\": [\"web\"]}`の中の`\"web\"`のパスは`.[\"tags\"]"
+"[]`です。もし、値の絶対パスを知っているなら検索条件でこの値を使えます。"
+
+msgid ""
+"  * `paths`: The paths of the value. It includes absolute path, sub paths, `.$"
+"{ELEMENT_NAME1}.${ELEMENT_NAME2}` format paths and paths without array. This c"
+"olumn is convenient for search condition because you can use one of them for s"
+"earch condition. Here are paths for `\"x\"` in `{\"a\": {\"b\": \"c\": [\"x\"]}}`:"
+msgstr ""
+"  * `paths`: 値を示すパスです。値を示すパスは複数あります。絶対パス、サブパス、`.${要素名1}.${要素名2}`というフォーマットのパス、配"
+"列部分を省略したパスがあります。このカラムは検索条件の指定を便利にするために用意されています。検索時にはこの中のパスのどれでも使うことができます。以下はどれ"
+"も`{\"a\": {\"b\": \"c\": [\"x\"]}}`の中の`\"x\"`を指定するパスです。"
+
+msgid ""
+"     * `.a.b.c`\n"
+"     * `.[\"a\"][\"b\"][\"c\"]`\n"
+"     * `.[\"a\"][\"b\"][\"c\"][]`\n"
+"     * `a.b.c`\n"
+"     * `[\"a\"][\"b\"][\"c\"]`\n"
+"     * `[\"a\"][\"b\"][\"c\"][]`\n"
+"     * `b.c`\n"
+"     * `[\"b\"][\"c\"]`\n"
+"     * `[\"b\"][\"c\"][]`\n"
+"     * `c`\n"
+"     * `[\"c\"]`\n"
+"     * `[\"c\"][]`\n"
+"     * `[]`"
+msgstr ""
+
+msgid "  * `type`: The type of the value. This column value is one of them:"
+msgstr "  * `type`:値の種類です。このカラムの値は次のどれかになります。"
+
+msgid "    * `\"object\"`: Object. No value."
+msgstr "    * `\"object\"`:オブジェクト。値はありません。"
+
+msgid "    * `\"array\"`: Array. The number of elements is stored in `size` column."
+msgstr "    * `\"array\"`:配列。`size`カラムに要素数が入っています。"
+
+msgid "    * `\"boolean\"`: Boolean. The value is stored in `boolean` column."
+msgstr "    * `\"boolean\"`:真偽値。`boolean`カラムに値が入っています。"
+
+msgid "    * `\"number\"`: Number. The value is stored in `number` column."
+msgstr "    * `\"number\"`:数値。`number`カラムに値が入っています。"
+
+msgid "    * `\"string\"`: String. The value is stored in `string` column."
+msgstr "    * `\"string\"`:文字列。`string`カラムに値が入っています。"
+
+msgid ""
+"  * `boolean`: The value if `type` column value is `\"boolean\"`, `false` otherw"
+"ise."
+msgstr "  * `boolean`:`type`カラムの値が`\"boolean\"`なら値が入っています。それ以外のときは`false`が入っています。"
+
+msgid "  * `number`: The value if `type` column value is `\"number\"`, `0` otherwise."
+msgstr "  * `number`:`type`カラムの値が`\"number\"`なら値が入っています。それ以外のときは`0`が入っています。"
+
+msgid "  * `string`: The value if `type` column value is `\"string\"`, `\"\"` otherwise."
+msgstr "  * `string`:`type`カラムの値が`\"string\"`なら値が入っています。それ以外のときは`\"\"`が入っています。"
+
+msgid ""
+"  * `size`: The number of elements if `type` column value is `\"array\"`, `0` ot"
+"herwise."
+msgstr "  * `size`:`type`カラムの値が`\"array\"`なら要素数が入っています。それ以外のときは`0`が入っています。"
+
+msgid "Here is a sample JSON:"
+msgstr "以下はサンプルJSONです。"
+
+msgid ""
+"```json\n"
+"{\n"
+"  \"message\": \"GET /\",\n"
+"  \"host\":    \"www.example.com\",\n"
+"  \"code\":    200,\n"
+"  \"tags\": [\n"
+"    \"web\",\n"
+"    \"example.com\"\n"
+"  ]\n"
+"}\n"
+"```"
+msgstr ""
+
+msgid ""
+"The JSON is split to the following values. (They are part of all split values."
+")"
+msgstr "このJSONを次の値に分割します。(これは分割した値の一部です。)"
+
+msgid ""
+"| key | path | paths | type | boolean | number | string | size |\n"
+"| --- | ---- | ----- | ---- | ------- | ------ | ------ | ---- |\n"
+"| `.|object` | `.` | `[.]` | `object` | | | | |\n"
+"| `.[\"message\"]|string|GET /` | `.[\"message\"]` | `[.message, .[\"message\"], mes"
+"sage, [\"message\"]]` | `string` | | | `GET /` | |\n"
+"| `.[\"tags\"][]|string|web` | `.[\"tags\"]` | `[.tags, .[\"tags\"], .[\"tags\"][], ta"
+"gs, [\"tags\"], [\"tags\"][], []]` | `string` | | | `web` | |"
+msgstr ""
+
+msgid ""
+"You specify condition that matches split value to `@@` operator. If there is o"
+"ne or more split values that match specified condition in `jsonb` type value, "
+"the `jsonb` type value is matched."
+msgstr ""
+"`@@`演算子を使って分割した値にマッチする条件を指定します。もし、`jsonb`型の値の中に条件にマッチする分割した値が1つ以上ある場合はその`jsonb"
+"`型の値はマッチしたことになります。"
+
+msgid ""
+"Here is a condition that searches `jsonb` type value that has `www.example.com"
+"` string:"
+msgstr "次は`www.example.com`という文字列値を含む`jsonb`型の値を検索する条件です。"
+
+msgid ""
+"(It uses [`jsonb_pretty()` function](http://www.postgresql.org/docs/devel/stat"
+"ic/functions-json.html#FUNCTIONS-JSON-PROCESSING-TABLE) provided since Postgre"
+"SQL 9.5 for readability.)"
+msgstr ""
+"(読みやすくするためにPostgreSQL 9.5以降で使える[`jsonb_pretty()`関数](http://www.postgresql.jp/d"
+"ocument/current/html/functions-json.html#FUNCTIONS-JSON-PROCESSING-TABLE)を使ってい"
+"ます。)"
+
+msgid ""
+"```sql\n"
+"SELECT jsonb_pretty(record) FROM logs WHERE record @@ 'string == \"www.example."
+"com\"';\n"
+"--             jsonb_pretty             \n"
+"-- -------------------------------------\n"
+"--  {                                  +\n"
+"--      \"host\": \"www.example.com\",     +\n"
+"--      \"tags\": [                      +\n"
+"--          \"web\",                     +\n"
+"--          \"example.com\"              +\n"
+"--      ],                             +\n"
+"--      \"message\": \"Server is started.\"+\n"
+"--  }\n"
+"--  {                                  +\n"
+"--      \"code\": 200,                   +\n"
+"--      \"host\": \"www.example.com\",     +\n"
+"--      \"tags\": [                      +\n"
+"--          \"web\",                     +\n"
+"--          \"example.com\"              +\n"
+"--      ],                             +\n"
+"--      \"message\": \"GET /\"             +\n"
+"--  }\n"
+"-- (2 rows)\n"
+"```"
+msgstr ""
+
+msgid ""
+"Here is a condition that searches `jsonb` type value that has number between `"
+"200` to `299` as `code` column value. The condition uses `paths @ \"...\"` synta"
+"x to use simple path format (`.code`) to specify path."
+msgstr ""
+"以下は`code`カラムの値として`200`から`299`の間の数値を持っている`jsonb`型の値を検索する条件です。この条件はパスの指定に簡易パスフォー"
+"マット(`.code`)を使うため、`paths @ \"...\"`という構文を使っています。"
+
+msgid ""
+"```sql\n"
+"SELECT jsonb_pretty(record) FROM logs WHERE record @@ 'paths @ \".code\" && numb"
+"er >= 200 && number < 300';\n"
+"--           jsonb_pretty          \n"
+"-- --------------------------------\n"
+"--  {                             +\n"
+"--      \"code\": 200,              +\n"
+"--      \"host\": \"www.example.com\",+\n"
+"--      \"tags\": [                 +\n"
+"--          \"web\",                +\n"
+"--          \"example.com\"         +\n"
+"--      ],                        +\n"
+"--      \"message\": \"GET /\"        +\n"
+"--  }\n"
+"-- (1 row)\n"
+"```"
+msgstr ""
+
+msgid ""
+"Here is a condition for full text search from all text values in `jsonb` value"
+" type:"
+msgstr "`jsonb`型の値の中のすべてのテキスト値に対して全文検索をする条件は次の通りです。"
+
+msgid ""
+"```sql\n"
+"SELECT jsonb_pretty(record) FROM logs WHERE record @@ 'string @ \"started\"';\n"
+"--             jsonb_pretty             \n"
+"-- -------------------------------------\n"
+"--  {                                  +\n"
+"--      \"host\": \"www.example.com\",     +\n"
+"--      \"tags\": [                      +\n"
+"--          \"web\",                     +\n"
+"--          \"example.com\"              +\n"
+"--      ],                             +\n"
+"--      \"message\": \"Server is started.\"+\n"
+"--  }\n"
+"-- (1 row)\n"
+"```"
+msgstr ""
+
+msgid ""
+"You can use [Groonga's query syntax](http://groonga.org/docs/reference/grn_exp"
+"r/query_syntax.html) (`a OR b` can be used) for full text search by `query(\"st"
+"ring\", \"...\")` syntax:"
+msgstr ""
+"全文検索用に[Groongaのクエリー構文](http://groonga.org/ja/docs/reference/grn_expr/query_syn"
+"tax.html)(`a OR b`という構文を使えます)を使うには`query(\"string\", \"...\")`という構文を使います。"
+
+msgid ""
+"```sql\n"
+"SELECT jsonb_pretty(record) FROM logs WHERE record @@ 'query(\"string\", \"send O"
+"R server\")';\n"
+"--                  jsonb_pretty                 \n"
+"-- ----------------------------------------------\n"
+"--  {                                           +\n"
+"--      \"host\": \"www.example.com\",              +\n"
+"--      \"tags\": [                               +\n"
+"--          \"web\",                              +\n"
+"--          \"example.com\"                       +\n"
+"--      ],                                      +\n"
+"--      \"message\": \"Server is started.\"         +\n"
+"--  }\n"
+"--  {                                           +\n"
+"--      \"host\": \"mail.example.net\",             +\n"
+"--      \"tags\": [                               +\n"
+"--          \"mail\",                             +\n"
+"--          \"example.net\"                       +\n"
+"--      ],                                      +\n"
+"--      \"message\": \"Send to <info �� example.com>.\"+\n"
+"--  }\n"
+"-- (2 rows)\n"
+"```"
+msgstr ""
+
+msgid "## See also"
+msgstr "## 参考"
+
+msgid ""
+"  * [`jsonb` support](../jsonb.html)\n"
+"  * [`@>` operator](jsonb-contain.html)"
+msgstr ""
+"  * [`jsonb`サポート](../jsonb.html)\n"
+"  * [`@>`演算子](jsonb-contain.html)"

  Added: ja/reference/operators/jsonb-query.md (+249 -0) 100644
===================================================================
--- /dev/null
+++ ja/reference/operators/jsonb-query.md    2015-10-25 20:50:14 +0900 (d475ce2)
@@ -0,0 +1,249 @@
+---
+title: "jsonb型用の@@演算子"
+layout: ja
+---
+
+# `jsonb`型用の`@@`演算子
+
+## 概要
+
+`@@`演算子はPGroonga独自の演算子です。範囲検索のような[`@>`演算子](jsonb-contain.html)では書けないような複雑な条件を書くことができます。
+
+もし[JsQuery](https://github.com/postgrespro/jsquery)を知っているなら、「PGroongaはJsQueryが提供しているような`jsonb`型用の検索機能を違う構文で提供している」と理解してください。
+
+## 構文
+
+この演算子の構文は次の通りです。
+
+```sql
+jsonb_column @@ condition
+```
+
+`jsonb_column`は`jsonb`型のカラムです。
+
+`condition`はクエリーとして使う`text`型の値です。[Groongaのスクリプト構文](http://groonga.org/ja/docs/reference/grn_expr/script_syntax.html)を使います。
+
+この演算子は`condition`が`jsonb_column`の値にマッチしたら`true`を返し、マッチしなかったら`false`を返します。
+
+## 使い方
+
+例に使うサンプルスキーマとデータは次の通りです。
+
+```sql
+CREATE TABLE logs (
+  record jsonb
+);
+
+CREATE INDEX pgroonga_logs_index ON logs USING pgroonga (record);
+
+INSERT INTO logs
+     VALUES ('{
+                "message": "Server is started.",
+                "host":    "www.example.com",
+                "tags": [
+                  "web",
+                  "example.com"
+                ]
+              }');
+INSERT INTO logs
+     VALUES ('{
+                "message": "GET /",
+                "host":    "www.example.com",
+                "code":    200,
+                "tags": [
+                  "web",
+                  "example.com"
+                ]
+              }');
+INSERT INTO logs
+     VALUES ('{
+                "message": "Send to <info �� example.com>.",
+                "host":    "mail.example.net",
+                "tags": [
+                  "mail",
+                  "example.net"
+                ]
+              }');
+```
+
+シーケンシャルスキャンを無効にします。
+
+```sql
+SET enable_seqscan = off;
+```
+
+検索条件を作るためにはPGroongaが`jsonb`型のデータ用のインデックスをどのように作るかを理解する必要があります。
+
+PGroongaは`jsonb`型の値を複数の値に分割し、それらの分割した値に対してインデックスを作成します。SQLで言うと次のスキーマを作っていると考えてください。
+
+```sql
+CREATE TABLE values (
+  key text PRIMARY KEY,
+  path text,
+  paths text[],
+  type text,
+  boolean boolean,
+  number double precision,
+  string text,
+  size numeric
+);
+```
+
+各カラムの説明は次の通りです。
+
+  * `key`:値のIDです。値が違うパスで違う内容なら`key`は違う値になります。キーのフォーマットは`'${パス}|${種類}|${値}'`です。このカラムは検索条件には使いません。
+
+  * `path`:値がある位置へのルートからのパスです。[jq](https://stedolan.github.io/jq/)互換のフォーマットです。オブジェクトは`["${要素名}"]`で配列は`[]`です。たとえば、`{"tags": ["web"]}`の中の`"web"`のパスは`.["tags"][]`です。もし、値の絶対パスを知っているなら検索条件でこの値を使えます。
+
+  * `paths`: 値を示すパスです。値を示すパスは複数あります。絶対パス、サブパス、`.${要素名1}.${要素名2}`というフォーマットのパス、配列部分を省略したパスがあります。このカラムは検索条件の指定を便利にするために用意されています。検索時にはこの中のパスのどれでも使うことができます。以下はどれも`{"a": {"b": "c": ["x"]}}`の中の`"x"`を指定するパスです。
+
+     * `.a.b.c`
+     * `.["a"]["b"]["c"]`
+     * `.["a"]["b"]["c"][]`
+     * `a.b.c`
+     * `["a"]["b"]["c"]`
+     * `["a"]["b"]["c"][]`
+     * `b.c`
+     * `["b"]["c"]`
+     * `["b"]["c"][]`
+     * `c`
+     * `["c"]`
+     * `["c"][]`
+     * `[]`
+
+  * `type`:値の種類です。このカラムの値は次のどれかになります。
+
+    * `"object"`:オブジェクト。値はありません。
+
+    * `"array"`:配列。`size`カラムに要素数が入っています。
+
+    * `"boolean"`:真偽値。`boolean`カラムに値が入っています。
+
+    * `"number"`:数値。`number`カラムに値が入っています。
+
+    * `"string"`:文字列。`string`カラムに値が入っています。
+
+  * `boolean`:`type`カラムの値が`"boolean"`なら値が入っています。それ以外のときは`false`が入っています。
+
+  * `number`:`type`カラムの値が`"number"`なら値が入っています。それ以外のときは`0`が入っています。
+
+  * `string`:`type`カラムの値が`"string"`なら値が入っています。それ以外のときは`""`が入っています。
+
+  * `size`:`type`カラムの値が`"array"`なら要素数が入っています。それ以外のときは`0`が入っています。
+
+以下はサンプルJSONです。
+
+```json
+{
+  "message": "GET /",
+  "host":    "www.example.com",
+  "code":    200,
+  "tags": [
+    "web",
+    "example.com"
+  ]
+}
+```
+
+このJSONを次の値に分割します。(これは分割した値の一部です。)
+
+| key | path | paths | type | boolean | number | string | size |
+| --- | ---- | ----- | ---- | ------- | ------ | ------ | ---- |
+| `.|object` | `.` | `[.]` | `object` | | | | |
+| `.["message"]|string|GET /` | `.["message"]` | `[.message, .["message"], message, ["message"]]` | `string` | | | `GET /` | |
+| `.["tags"][]|string|web` | `.["tags"]` | `[.tags, .["tags"], .["tags"][], tags, ["tags"], ["tags"][], []]` | `string` | | | `web` | |
+
+`@@`演算子を使って分割した値にマッチする条件を指定します。もし、`jsonb`型の値の中に条件にマッチする分割した値が1つ以上ある場合はその`jsonb`型の値はマッチしたことになります。
+
+次は`www.example.com`という文字列値を含む`jsonb`型の値を検索する条件です。
+
+(読みやすくするためにPostgreSQL 9.5以降で使える[`jsonb_pretty()`関数](http://www.postgresql.jp/document/current/html/functions-json.html#FUNCTIONS-JSON-PROCESSING-TABLE)を使っています。)
+
+```sql
+SELECT jsonb_pretty(record) FROM logs WHERE record @@ 'string == "www.example.com"';
+--             jsonb_pretty             
+-- -------------------------------------
+--  {                                  +
+--      "host": "www.example.com",     +
+--      "tags": [                      +
+--          "web",                     +
+--          "example.com"              +
+--      ],                             +
+--      "message": "Server is started."+
+--  }
+--  {                                  +
+--      "code": 200,                   +
+--      "host": "www.example.com",     +
+--      "tags": [                      +
+--          "web",                     +
+--          "example.com"              +
+--      ],                             +
+--      "message": "GET /"             +
+--  }
+-- (2 rows)
+```
+
+以下は`code`カラムの値として`200`から`299`の間の数値を持っている`jsonb`型の値を検索する条件です。この条件はパスの指定に簡易パスフォーマット(`.code`)を使うため、`paths @ "..."`という構文を使っています。
+
+```sql
+SELECT jsonb_pretty(record) FROM logs WHERE record @@ 'paths @ ".code" && number >= 200 && number < 300';
+--           jsonb_pretty          
+-- --------------------------------
+--  {                             +
+--      "code": 200,              +
+--      "host": "www.example.com",+
+--      "tags": [                 +
+--          "web",                +
+--          "example.com"         +
+--      ],                        +
+--      "message": "GET /"        +
+--  }
+-- (1 row)
+```
+
+`jsonb`型の値の中のすべてのテキスト値に対して全文検索をする条件は次の通りです。
+
+```sql
+SELECT jsonb_pretty(record) FROM logs WHERE record @@ 'string @ "started"';
+--             jsonb_pretty             
+-- -------------------------------------
+--  {                                  +
+--      "host": "www.example.com",     +
+--      "tags": [                      +
+--          "web",                     +
+--          "example.com"              +
+--      ],                             +
+--      "message": "Server is started."+
+--  }
+-- (1 row)
+```
+
+全文検索用に[Groongaのクエリー構文](http://groonga.org/ja/docs/reference/grn_expr/query_syntax.html)(`a OR b`という構文を使えます)を使うには`query("string", "...")`という構文を使います。
+
+```sql
+SELECT jsonb_pretty(record) FROM logs WHERE record @@ 'query("string", "send OR server")';
+--                  jsonb_pretty                 
+-- ----------------------------------------------
+--  {                                           +
+--      "host": "www.example.com",              +
+--      "tags": [                               +
+--          "web",                              +
+--          "example.com"                       +
+--      ],                                      +
+--      "message": "Server is started."         +
+--  }
+--  {                                           +
+--      "host": "mail.example.net",             +
+--      "tags": [                               +
+--          "mail",                             +
+--          "example.net"                       +
+--      ],                                      +
+--      "message": "Send to <info �� example.com>."+
+--  }
+-- (2 rows)
+```
+
+## 参考
+
+  * [`jsonb`サポート](../jsonb.html)
+  * [`@>`演算子](jsonb-contain.html)

  Modified: reference/operators/jsonb-query.md (+23 -10)
===================================================================
--- reference/operators/jsonb-query.md    2015-10-25 15:28:23 +0900 (f5be842)
+++ reference/operators/jsonb-query.md    2015-10-25 20:50:14 +0900 (1ab35a1)
@@ -9,7 +9,7 @@ layout: en
 
 `@@` operator is a PGroonga original operator. You can use complex condition that can't be written by [`@>` operator](jsonb-contain.html) such as range search.
 
-If you know [JsQuery](https://github.com/postgrespro/jsquery), you can understand like "PGroonga provides `jsonb` related search features that are similar to JsQuery with different syntax".
+If you know [JsQuery](https://github.com/postgrespro/jsquery), you can understand like "PGroonga provides `jsonb` type related search features that are similar to JsQuery with different syntax".
 
 ## Syntax
 
@@ -23,7 +23,7 @@ jsonb_column @@ condition
 
 `condition` is a `text` value used as query. It uses [Groonga's script syntax](http://groonga.org/docs/reference/grn_expr/script_syntax.html).
 
-The operator returns `true` when `condition` matches  `jsonb_column` value, `false` otherwise.
+The operator returns `true` when `condition` matches `jsonb_column` value, `false` otherwise.
 
 ## Usage
 
@@ -72,9 +72,9 @@ Disable sequential scan:
 SET enable_seqscan = off;
 ```
 
-You need to understand how PGroonga creates index against `jsonb` data to create search condition.
+You need to understand how PGroonga creates index against `jsonb` type value to create search condition.
 
-PGroonga splits a `jsonb` value into values and then creates indexes against these values. In SQL, think about the following schema:
+PGroonga splits a `jsonb` type value into values and then creates indexes against these values. In SQL, think about the following schema:
 
 ```sql
 CREATE TABLE values (
@@ -91,9 +91,12 @@ CREATE TABLE values (
 
 Here are descriptions of column:
 
-  * `key`: The ID of the value. If value has the same path and content, `key` is the same value. Key format is "`${PATH}|${TYPE}|${VALUE}`". It's not used in search condition.
+  * `key`: The ID of the value. If value has the same path and content, `key` is the same value. Key format is `'${PATH}|${TYPE}|${VALUE}'`. It's not used in search condition.
+
   * `path`: The path of the value from root. It uses [jq](https://stedolan.github.io/jq/) compatible format. Object is `["${ELEMENT_NAME}"]`, array is `[]`. For example, the path of `"web"` in `{"tags": ["web"]}` is `.["tags"][]`. If you know absolute path of the value, you can use this value in search condition.
-  * `paths`: The paths of the value. It includes absolute path, sub paths, `.${ELEMENT_NAME1}.${ELEMENT_NAME2}` format paths, paths without array. This column is convenient for search condition because you can use one of them for search condition. Here are paths for `"x"` in `{"a": {"b": "c": ["x"]}}`:
+
+  * `paths`: The paths of the value. It includes absolute path, sub paths, `.${ELEMENT_NAME1}.${ELEMENT_NAME2}` format paths and paths without array. This column is convenient for search condition because you can use one of them for search condition. Here are paths for `"x"` in `{"a": {"b": "c": ["x"]}}`:
+
      * `.a.b.c`
      * `.["a"]["b"]["c"]`
      * `.["a"]["b"]["c"][]`
@@ -107,15 +110,25 @@ Here are descriptions of column:
      * `["c"]`
      * `["c"][]`
      * `[]`
+
   * `type`: The type of the value. This column value is one of them:
+
     * `"object"`: Object. No value.
+
     * `"array"`: Array. The number of elements is stored in `size` column.
+
     * `"boolean"`: Boolean. The value is stored in `boolean` column.
+
     * `"number"`: Number. The value is stored in `number` column.
+
     * `"string"`: String. The value is stored in `string` column.
+
   * `boolean`: The value if `type` column value is `"boolean"`, `false` otherwise.
+
   * `number`: The value if `type` column value is `"number"`, `0` otherwise.
+
   * `string`: The value if `type` column value is `"string"`, `""` otherwise.
+
   * `size`: The number of elements if `type` column value is `"array"`, `0` otherwise.
 
 Here is a sample JSON:
@@ -140,9 +153,9 @@ The JSON is split to the following values. (They are part of all split values.)
 | `.["message"]|string|GET /` | `.["message"]` | `[.message, .["message"], message, ["message"]]` | `string` | | | `GET /` | |
 | `.["tags"][]|string|web` | `.["tags"]` | `[.tags, .["tags"], .["tags"][], tags, ["tags"], ["tags"][], []]` | `string` | | | `web` | |
 
-You specify condition that matches split value to `@@` operator. If there is one or more values that match specified condition in `jsonb`, the `jsonb` is matched.
+You specify condition that matches split value to `@@` operator. If there is one or more split values that match specified condition in `jsonb` type value, the `jsonb` type value is matched.
 
-Here is a condition that searches `jsonb` that has `www.example.com` string:
+Here is a condition that searches `jsonb` type value that has `www.example.com` string:
 
 (It uses [`jsonb_pretty()` function](http://www.postgresql.org/docs/devel/static/functions-json.html#FUNCTIONS-JSON-PROCESSING-TABLE) provided since PostgreSQL 9.5 for readability.)
 
@@ -170,7 +183,7 @@ SELECT jsonb_pretty(record) FROM logs WHERE record @@ 'string == "www.example.co
 -- (2 rows)
 ```
 
-Here is a condition that searches `jsonb` that has number between `200` to `299` as `code` column value. The condition uses `paths @ "..."` syntax to use simple path format (`.code`) to specify path.
+Here is a condition that searches `jsonb` type value that has number between `200` to `299` as `code` column value. The condition uses `paths @ "..."` syntax to use simple path format (`.code`) to specify path.
 
 ```sql
 SELECT jsonb_pretty(record) FROM logs WHERE record @@ 'paths @ ".code" && number >= 200 && number < 300';
@@ -188,7 +201,7 @@ SELECT jsonb_pretty(record) FROM logs WHERE record @@ 'paths @ ".code" && number
 -- (1 row)
 ```
 
-Here is a condition for full text search from all text values in `jsonb`:
+Here is a condition for full text search from all text values in `jsonb` value type:
 
 ```sql
 SELECT jsonb_pretty(record) FROM logs WHERE record @@ 'string @ "started"';
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index