Navigation Menu

Skip to content

Commit

Permalink
Translate LIKE operator
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Oct 6, 2015
1 parent 3a5e959 commit 39076ec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 26 deletions.
2 changes: 2 additions & 0 deletions reference/create-index-using-pgroonga.md
Expand Up @@ -37,6 +37,8 @@ CREATE INDEX ${INDEX_NAME}

You need to specify `pgroonga.varchar_fulltext_search_ops` operator class for the case.

{: #customization}

### Customization

You can custom the followings by `WITH` option of `CREATE INDEX`:
Expand Down
39 changes: 13 additions & 26 deletions reference/operators/like.md
Expand Up @@ -5,24 +5,15 @@ layout: en

# `LIKE` operator

TODO
PGroonga converts `column LIKE '%KEYWORD%'` condition to `column @@ 'KEYWORD'` internally. [`@@` operator](match.html) does full text search with index. It's fast rather than `LIKE` operator without index.

なお、`'キーワード%'``'%キーワード'`のように最初と最後に`%`がついて
いない場合は必ず検索結果が空になります。このようなパターンはインデック
スを使って検索できないからです。気をつけてください。
Both beginning `%` and ending `%` are important. `'KEYWORD%'`, `'%KEYWORD'` and so on aren't converted to `column @@ 'KEYWORD'`. PGroonga returns no records for these patterns. Because PGroonga can't search these patterns with index.

本来の`LIKE`演算子は元の文字列そのものに対して検索しますが、`@@`演算子
は正規化後の文字列に対して全文検索検索を実行します。そのため、インデッ
クスを使わない場合の`LIKE`演算子の結果(本来の`LIKE`演算子の結果)とイ
ンデックスを使った場合の`LIKE`演算子の結果は異なります。
The original `LIKE` operator searches against text as is. But `@@` operator does full text search against normalized text. It means that search result of `LIKE` operator with index and search result of the original `LIKE` operator may be different.

たとえば、本来の`LIKE`演算子ではアルファベットの大文字小文字を区別した
りいわゆる全角・半角を区別しますが、インデックスを使った場合は区別なく
検索します。
For example, the original `LIKE` operator searches with case sensitive. But `LIKE` operator with index searches with case insensitive.



本来の`LIKE`演算子の結果:
A search result of the original `LIKE` operator:

```sql
SET enable_seqscan = on;
Expand All @@ -35,7 +26,7 @@ SELECT * FROM memos WHERE content LIKE '%groonga%';
-- (1 行)
```

インデックスを使った`LIKE`演算子の結果:
A search result of `LIKE` operator with index:

```sql
SET enable_seqscan = off;
Expand All @@ -50,14 +41,12 @@ SELECT * FROM memos WHERE content LIKE '%groonga%';
-- (3 行)
```

インデックスを使った場合でも本来の`LIKE`演算子と同様の結果にしたい場合
は次のようにトークナイザー(後述)とノーマライザー(後述)を設定してイ
ンデックスを作成してください。
If you want to get the same result by both `LIKE` operator with index and the original `LIKE` operator, use the following tokenizer and normalizer:

* トークナイザー: `TokenBigramSplitSymbolAlphaDigit`
* ノーマライザー: なし
* Tokenizer: `TokenBigramSplitSymbolAlphaDigit`
* Normalizer: None

具体的には次のようにインデックスを作成します。
Here is a concrete example:

```sql
CREATE INDEX pgroonga_content_index
Expand All @@ -67,8 +56,7 @@ CREATE INDEX pgroonga_content_index
normalizer='');
```

このようなインデックスを作っているときはインデックスを使った`LIKE`演算
子でも本来の`LIKE`演算子と同様の挙動になります。
You can get the same result as the original `LIKE` operator with `LIKE` operator with index:

```sql
SET enable_seqscan = off;
Expand All @@ -81,7 +69,6 @@ SELECT * FROM memos WHERE content LIKE '%groonga%';
-- (1 行)
```

多くの場合、デフォルトの設定の全文検索結果の方が本来の`LIKE`演算子の方
の検索結果よりもユーザーが求めている結果に近くなります。本当に本来の
`LIKE`演算子の挙動の方が適切か検討した上で使ってください。
Normally, the default configuration returns better result for full text search rather than the original `LIKE` operator. Think about which result is better for users before you change the default configuration.

See [Customization in `CREATE INDEX USING pgroonga`](../create-index-using-pgroonga.html#customization) for tokenizer and normalizer.

0 comments on commit 39076ec

Please sign in to comment.