Skip to content

Commit

Permalink
query-v2: Add when to use pgroonga_condition() (#389)
Browse files Browse the repository at this point in the history
GitHub: GH-335
  • Loading branch information
abetomo authored Oct 7, 2024
1 parent 1e461c9 commit 8f5791f
Show file tree
Hide file tree
Showing 3 changed files with 309 additions and 19 deletions.
192 changes: 178 additions & 14 deletions _po/ja/reference/operators/query-v2.po
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ msgid ""
"pgroonga_full_text_search_condition\n"
"column &@~ (query, weights, scorers, index_name)::"
"pgroonga_full_text_search_condition_with_scorers\n"
"column &@~ pgroonga_condition(query,\n"
" weights,\n"
" scorers,\n"
" schema_name,\n"
" index_name,\n"
" column_name,\n"
" fuzzy_max_distance_ratio)\n"
"```"
msgstr ""

Expand Down Expand Up @@ -89,6 +96,19 @@ msgstr ""
msgid "The third signature is available since 2.0.6."
msgstr "3つ目の使い方は2.0.6から使えます。"

msgid ""
"The fourth signature is using [`pgroonga_condition` function][condition].\n"
"You can implement the second and third signatures uses with "
"[`pgroonga_condition` function][condition].\n"
"You should use this signature in 3.1.6 and above.\n"
"See [`pgroonga_condition` function][condition] for details."
msgstr ""
"4つ目の使い方は[`pgroonga_condition`関数][condition]を使います。\n"
"[`pgroonga_condition`関数][condition]を使うと2つ目と3つ目の使い方が実現できま"
"す。\n"
"3.1.6以降はこの構文を使ってください。詳しくは[`pgroonga_condition`関数]"
"[condition]をご覧ください。"

msgid "Here is the description of the first signature."
msgstr "以下は1つ目の使い方の説明です。"

Expand Down Expand Up @@ -383,8 +403,7 @@ msgid ""
"index. | 2\n"
"-- CLI | There is groonga "
"command. | 1\n"
"-- (4 rows)\n"
"```"
"-- (4 rows)"
msgstr ""
"```sql\n"
"SELECT *, pgroonga_score(tableoid, ctid) AS score\n"
Expand All @@ -407,6 +426,54 @@ msgstr ""
"PostgreSQLの拡張機能です。 | 2\n"
"-- コマンドライン | groongaコマンドがありま"
"す。 | 1\n"
"-- (4 rows)"

msgid ""
"-- Query with pgroonga_condition().\n"
"SELECT *, pgroonga_score(tableoid, ctid) AS score\n"
" FROM memos\n"
" WHERE ARRAY[title, content] &@~\n"
" pgroonga_condition('Groonga OR PostgreSQL',\n"
" weights => ARRAY[5, 1],\n"
" index_name => 'pgroonga_memos_index')\n"
" ORDER BY score DESC;\n"
"-- title | "
"content | score\n"
"-- ------------"
"+------------------------------------------------------------------------"
"+-------\n"
"-- Groonga | Groonga is a fast full text search engine that supports all "
"languages. | 6\n"
"-- PostgreSQL | PostgreSQL is a relational database management "
"system. | 6\n"
"-- PGroonga | PGroonga is a PostgreSQL extension that uses Groonga as "
"index. | 2\n"
"-- CLI | There is groonga "
"command. | 1\n"
"-- (4 rows)\n"
"```"
msgstr ""
"-- pgroonga_condition()を使う\n"
"SELECT *, pgroonga_score(tableoid, ctid) AS score\n"
" FROM memos\n"
" WHERE ARRAY[title, content] &@~\n"
" pgroonga_condition('Groonga OR PostgreSQL',\n"
" weights => ARRAY[5, 1],\n"
" index_name => 'pgroonga_memos_index')\n"
" ORDER BY score DESC;\n"
"-- title | "
"content | score \n"
"-- ----------------"
"+---------------------------------------------------------------------------"
"+-------\n"
"-- Groonga | Groongaは日本語対応の高速な全文検索エンジンで"
"す。 | 6\n"
"-- PostgreSQL | PostgreSQLはリレーショナル・データベース管理システムで"
"す。 | 6\n"
"-- PGroonga | PGroongaはインデックスとしてGroongaを使うための"
"PostgreSQLの拡張機能です。 | 2\n"
"-- コマンドライン | groongaコマンドがありま"
"す。 | 1\n"
"-- (4 rows)\n"
"```"

Expand Down Expand Up @@ -442,8 +509,7 @@ msgid ""
"languages. | 5\n"
"-- PostgreSQL | PostgreSQL is a relational database management "
"system. | 5\n"
"-- (2 rows)\n"
"```"
"-- (2 rows)"
msgstr ""
"```sql\n"
"SELECT *, pgroonga_score(tableoid, ctid) AS score\n"
Expand All @@ -461,6 +527,45 @@ msgstr ""
"| 5\n"
"-- PostgreSQL | PostgreSQLはリレーショナル・データベース管理システムです。 "
"| 5\n"
"-- (2 rows)"

msgid ""
"-- Query with pgroonga_condition().\n"
"SELECT *, pgroonga_score(tableoid, ctid) AS score\n"
" FROM memos\n"
" WHERE ARRAY[title, content] &@~\n"
" pgroonga_condition('Groonga OR PostgreSQL',\n"
" weights => ARRAY[5, 0],\n"
" index_name => 'pgroonga_memos_index')\n"
" ORDER BY score DESC;\n"
"-- title | "
"content | score \n"
"-- ------------"
"+------------------------------------------------------------------------"
"+-------\n"
"-- Groonga | Groonga is a fast full text search engine that supports all "
"languages. | 5\n"
"-- PostgreSQL | PostgreSQL is a relational database management "
"system. | 5\n"
"-- (2 rows)\n"
"```"
msgstr ""
"-- pgroonga_condition()を使う\n"
"SELECT *, pgroonga_score(tableoid, ctid) AS score\n"
" FROM memos\n"
" WHERE ARRAY[title, content] &@~\n"
" pgroonga_condition('Groonga OR PostgreSQL',\n"
" weights => ARRAY[5, 0],\n"
" index_name => 'pgroonga_memos_index')\n"
" ORDER BY score DESC;\n"
"-- title | content "
"| score \n"
"-- ------------+------------------------------------------------------------"
"+-------\n"
"-- Groonga | Groongaは日本語対応の高速な全文検索エンジンです。 "
"| 5\n"
"-- PostgreSQL | PostgreSQLはリレーショナル・データベース管理システムです。 "
"| 5\n"
"-- (2 rows)\n"
"```"

Expand Down Expand Up @@ -495,16 +600,69 @@ msgid ""
"index. | 1\n"
"-- CLI | There is groonga "
"command. | 0.5\n"
"-- (4 rows)\n"
"```"
"-- (4 rows)"
msgstr ""
"```sql\n"
"SELECT *, pgroonga_score(tableoid, ctid) AS score\n"
" FROM memos\n"
" WHERE ARRAY[title, content] &@~\n"
" ('Groonga OR PostgreSQL',\n"
" ARRAY[5, 1],\n"
" 'pgroonga_memos_index')::pgroonga_full_text_search_condition\n"
" ARRAY[NULL, 'scorer_tf_at_most($index, 0.5)'],\n"
" 'pgroonga_memos_index')::"
"pgroonga_full_text_search_condition_with_scorers\n"
" ORDER BY score DESC;\n"
"-- title | "
"content | score \n"
"-- ----------------"
"+---------------------------------------------------------------------------"
"+-------\n"
"-- Groonga | Groongaは日本語対応の高速な全文検索エンジンで"
"す。 | 5.5\n"
"-- PostgreSQL | PostgreSQLはリレーショナル・データベース管理システムで"
"す。 | 5.5\n"
"-- PGroonga | PGroongaはインデックスとしてGroongaを使うための"
"PostgreSQLの拡張機能です。 | 1\n"
"-- コマンドライン | groongaコマンドがありま"
"す。 | 0.5\n"
"-- (4 rows)"

msgid ""
"-- Query with pgroonga_condition().\n"
"SELECT *, pgroonga_score(tableoid, ctid) AS score\n"
" FROM memos\n"
" WHERE ARRAY[title, content] &@~\n"
" pgroonga_condition('Groonga OR PostgreSQL',\n"
" weights => ARRAY[5, 1],\n"
" scorers => ARRAY[NULL, 'scorer_tf_at_most($index, "
"0.5)'],\n"
" index_name => 'pgroonga_memos_index')\n"
" ORDER BY score DESC;\n"
"-- title | "
"content | score \n"
"-- ------------"
"+------------------------------------------------------------------------"
"+-------\n"
"-- Groonga | Groonga is a fast full text search engine that supports all "
"languages. | 5.5\n"
"-- PostgreSQL | PostgreSQL is a relational database management "
"system. | 5.5\n"
"-- PGroonga | PGroonga is a PostgreSQL extension that uses Groonga as "
"index. | 1\n"
"-- CLI | There is groonga "
"command. | 0.5\n"
"-- (4 rows)\n"
"```"
msgstr ""
"-- pgroonga_condition()を使う\n"
"SELECT *, pgroonga_score(tableoid, ctid) AS score\n"
" FROM memos\n"
" WHERE ARRAY[title, content] &@~\n"
" pgroonga_condition('Groonga OR PostgreSQL',\n"
" weights => ARRAY[5, 1],\n"
" scorers => ARRAY[NULL, 'scorer_tf_at_most($index, "
"0.5)'],\n"
" index_name => 'pgroonga_memos_index')\n"
" ORDER BY score DESC;\n"
"-- title | "
"content | score \n"
Expand Down Expand Up @@ -547,6 +705,9 @@ msgstr "## 参考"
msgid " * [`&@` operator][match-v2]: Full text search by a keyword"
msgstr " * [`&@`演算子][match-v2]:キーワード1つでの全文検索"

msgid " * [`pgroonga_condition` function][condition]"
msgstr ""

msgid " * [Groonga's query syntax][groonga-query-syntax]"
msgstr " * [Groongaのクエリーの構文][groonga-query-syntax]"

Expand All @@ -556,18 +717,21 @@ msgstr ""
"[wikipedia-keyword-stuffing]:https://ja.wikipedia.org/wiki/"
"%E3%82%AD%E3%83%BC%E3%83%AF%E3%83%BC%E3%83%89%E3%82%B9%E3%82%BF%E3%83%83%E3%83%95%E3%82%A3%E3%83%B3%E3%82%B0"

msgid ""
"[groonga-query-syntax]:http://groonga.org/docs/reference/grn_expr/"
"query_syntax.html"
msgstr ""
"[groonga-query-syntax]:http://groonga.org/ja/docs/reference/grn_expr/"
"query_syntax.html"

msgid "[groonga-scorer]:http://groonga.org/docs/reference/scorer.html"
msgstr "[groonga-scorer]:http://groonga.org/ja/docs/reference/scorer.html"

msgid "[score]:../functions/pgroonga-score.html"
msgid "[condition]:../functions/pgroonga-condition.html"
msgstr ""

msgid "[match-v2]:match-v2.html"
msgid "[score]:../functions/pgroonga-score.html"
msgstr ""

msgid ""
"[groonga-query-syntax]:http://groonga.org/docs/reference/grn_expr/"
"query_syntax.html"
msgid "[match-v2]:match-v2.html"
msgstr ""
"[groonga-query-syntax]:http://groonga.org/ja/docs/reference/grn_expr/"
"query_syntax.html"
69 changes: 66 additions & 3 deletions ja/reference/operators/query-v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ upper_level: ../
column &@~ query
column &@~ (query, weights, index_name)::pgroonga_full_text_search_condition
column &@~ (query, weights, scorers, index_name)::pgroonga_full_text_search_condition_with_scorers
column &@~ pgroonga_condition(query,
weights,
scorers,
schema_name,
index_name,
column_name,
fuzzy_max_distance_ratio)
```

1つ目の使い方は他の使い方よりもシンプルです。多くの場合は1つ目の使い方で十分です。
Expand All @@ -35,6 +42,10 @@ column &@~ (query, weights, scorers, index_name)::pgroonga_full_text_search_cond

3つ目の使い方は2.0.6から使えます。

4つ目の使い方は[`pgroonga_condition`関数][condition]を使います。
[`pgroonga_condition`関数][condition]を使うと2つ目と3つ目の使い方が実現できます。
3.1.6以降はこの構文を使ってください。詳しくは[`pgroonga_condition`関数][condition]をご覧ください。

以下は1つ目の使い方の説明です。

```sql
Expand Down Expand Up @@ -204,6 +215,22 @@ SELECT *, pgroonga_score(tableoid, ctid) AS score
-- PGroonga | PGroongaはインデックスとしてGroongaを使うためのPostgreSQLの拡張機能です。 | 2
-- コマンドライン | groongaコマンドがあります。 | 1
-- (4 rows)

-- pgroonga_condition()を使う
SELECT *, pgroonga_score(tableoid, ctid) AS score
FROM memos
WHERE ARRAY[title, content] &@~
pgroonga_condition('Groonga OR PostgreSQL',
weights => ARRAY[5, 1],
index_name => 'pgroonga_memos_index')
ORDER BY score DESC;
-- title | content | score
-- ----------------+---------------------------------------------------------------------------+-------
-- Groonga | Groongaは日本語対応の高速な全文検索エンジンです。 | 6
-- PostgreSQL | PostgreSQLはリレーショナル・データベース管理システムです。 | 6
-- PGroonga | PGroongaはインデックスとしてGroongaを使うためのPostgreSQLの拡張機能です。 | 2
-- コマンドライン | groongaコマンドがあります。 | 1
-- (4 rows)
```

`title`カラムに「`Groonga`」または「`PostgreSQL`」があるレコードの方が`content`カラムに「`Groonga`」または「`PostgreSQL`」がある方がスコアーが高いことを確認できます。
Expand All @@ -223,6 +250,20 @@ SELECT *, pgroonga_score(tableoid, ctid) AS score
-- Groonga | Groongaは日本語対応の高速な全文検索エンジンです。 | 5
-- PostgreSQL | PostgreSQLはリレーショナル・データベース管理システムです。 | 5
-- (2 rows)

-- pgroonga_condition()を使う
SELECT *, pgroonga_score(tableoid, ctid) AS score
FROM memos
WHERE ARRAY[title, content] &@~
pgroonga_condition('Groonga OR PostgreSQL',
weights => ARRAY[5, 0],
index_name => 'pgroonga_memos_index')
ORDER BY score DESC;
-- title | content | score
-- ------------+------------------------------------------------------------+-------
-- Groonga | Groongaは日本語対応の高速な全文検索エンジンです。 | 5
-- PostgreSQL | PostgreSQLはリレーショナル・データベース管理システムです。 | 5
-- (2 rows)
```

スコアーの計算方法をカスタマイズできます。たとえば、`content`カラムのスコアーを最大で`0.5`に制限できます。
Expand All @@ -233,7 +274,25 @@ SELECT *, pgroonga_score(tableoid, ctid) AS score
WHERE ARRAY[title, content] &@~
('Groonga OR PostgreSQL',
ARRAY[5, 1],
'pgroonga_memos_index')::pgroonga_full_text_search_condition
ARRAY[NULL, 'scorer_tf_at_most($index, 0.5)'],
'pgroonga_memos_index')::pgroonga_full_text_search_condition_with_scorers
ORDER BY score DESC;
-- title | content | score
-- ----------------+---------------------------------------------------------------------------+-------
-- Groonga | Groongaは日本語対応の高速な全文検索エンジンです。 | 5.5
-- PostgreSQL | PostgreSQLはリレーショナル・データベース管理システムです。 | 5.5
-- PGroonga | PGroongaはインデックスとしてGroongaを使うためのPostgreSQLの拡張機能です。 | 1
-- コマンドライン | groongaコマンドがあります。 | 0.5
-- (4 rows)

-- pgroonga_condition()を使う
SELECT *, pgroonga_score(tableoid, ctid) AS score
FROM memos
WHERE ARRAY[title, content] &@~
pgroonga_condition('Groonga OR PostgreSQL',
weights => ARRAY[5, 1],
scorers => ARRAY[NULL, 'scorer_tf_at_most($index, 0.5)'],
index_name => 'pgroonga_memos_index')
ORDER BY score DESC;
-- title | content | score
-- ----------------+---------------------------------------------------------------------------+-------
Expand All @@ -254,14 +313,18 @@ SELECT *, pgroonga_score(tableoid, ctid) AS score

* [`&@`演算子][match-v2]:キーワード1つでの全文検索

* [`pgroonga_condition`関数][condition]

* [Groongaのクエリーの構文][groonga-query-syntax]

[wikipedia-keyword-stuffing]:https://ja.wikipedia.org/wiki/%E3%82%AD%E3%83%BC%E3%83%AF%E3%83%BC%E3%83%89%E3%82%B9%E3%82%BF%E3%83%83%E3%83%95%E3%82%A3%E3%83%B3%E3%82%B0

[groonga-query-syntax]:http://groonga.org/ja/docs/reference/grn_expr/query_syntax.html

[groonga-scorer]:http://groonga.org/ja/docs/reference/scorer.html

[condition]:../functions/pgroonga-condition.html

[score]:../functions/pgroonga-score.html

[match-v2]:match-v2.html

[groonga-query-syntax]:http://groonga.org/ja/docs/reference/grn_expr/query_syntax.html
Loading

0 comments on commit 8f5791f

Please sign in to comment.