例として次のデータを考える。
| ISBN | title |
|---|---|
| ISBN1 | Haskell入門 |
| ISBN2 | Groonga入門 |
| ISBN3 | できるErlang |
| ISBN4 | Go言語入門 |
| ISBN5 | 三日でできるScala |
| ISBN6 | Learning Groonga |
| ISBN7 | Haskell programming tutorial |
| _id | _key | title |
|---|---|---|
| b1 | ISBN1 | Haskell入門 |
| b2 | ISBN2 | Groonga入門 |
| b3 | ISBN3 | できるErlang |
| b4 | ISBN4 | Go言語入門 |
| b5 | ISBN5 | 三日でできるScala |
| b5 | ISBN6 | Learning Groonga |
| b5 | ISBN7 | Haskell programming tutorial |
次のようにしてデータを登録する
table_create --name Book --flags TABLE_HASH_KEY --key_type ShortText
column_create --table Book --name title --type ShortText
load --table Book
[
{"_key":"ISBN1","title":"Haskell入門"},
{"_key":"ISBN2","title":"Groonga入門"},
{"_key":"ISBN3","title":"できるErlang"},
{"_key":"ISBN4","title":"Go言語入門"},
{"_key":"ISBN5","title":"三日でできるScala"},
{"_key":"ISBN6","title":"Learning Groonga"}
{"_key":"ISBN7","title":"Haskell programming tutorial"}
]
次のようにして、インデックスのカラムを作る
table_create --name Terms --flags TABLE_PAT_KEY --key_type ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto
column_create --table Terms --name title_idx --flags COLUMN_INDEX|WITH_POSITION --type Book --source title
TokenBigramは、2文字ずつ分割をするという意味である。(BiはBinaryのBi) 例えば「東京都民」という言葉があった場合、2文字ずつ「東京 / 京都 / 都民 」という三つの単語に分解を行う。
Groongaの場合、TokenBigramを指定しても2文字ずつに分解を行うのは非ASCII文字の場合のみである。
- 文字がASCIIの場合: 単語単位に分割??(ここ怪しい)
- 文字が非ASCII文字の場合: 2文字ずつに分割をする
また、大文字を小文字に変換して検索できるようにする正規化(Normalize)処理も合わせて行う。 例:「Go -> go」
上記の動作を確認するために次のselect文を実行する。
select --table Terms --limit 999
=> [[0, 1435889569.58, 0.000641822814941406],
[[[18],
[["_id", "UInt32"], ["_key", "ShortText"], ["title_idx", "UInt32"]],
[1, "erlang", 1],
[2, "go", 1],
[3, "groonga", 4],
[4, "haskell", 4],
[5, "learning", 1],
[6, "programming", 1],
[7, "scala", 1],
[8, "tutorial", 1],
[9, "きる", 4],
[10, "でき", 4],
[11, "でで", 1],
[12, "る", 4],
[13, "三日", 1],
[14, "入門", 5],
[15, "日で", 1],
[16, "言語", 1],
[17, "語入", 1],
[18, "門", 5]]]]
日本語の文字が2文字ずつに、なって、ASCII文字は単語毎になっていることが確認できる。 また、Goという単語はgoと小文字に変換されていることがわかる。