7.8.16. TokenTable#

7.8.16.1. 概要#

TokenTable は既知のキーワードのみをトークンとして扱うトークナイザーです。既知のキーワードは TokenTable 用のテーブルにキーとして登録されていないといけません。

例えば、クエリーが既知のキーワードと既知でないキーワードを含む場合、検索クエリーには既知のキーワードのみが使われます。(既知でないキーワードは無視されます) コンテンツを既知のキーワードからしか検索できないとも言えます。この特徴のため、新語を使えるようにするにはキーワードを登録するテーブルを継続的にメンテナンスする必要があります。

7.8.16.2. 構文#

TokenTable には必須の引数があります。

テーブルを指定します。:

TokenTable("table", TABLE)

TABLE--default_tokenizer 'TokenTable("table", TABLE) を指定して作成されていないといけません。

7.8.16.3. 使い方#

TokenTable の使用例です。例えば Raspberry PiePies テーブルから検索してみましょう。キーワードのために使われるのは Keywords テーブルです。

スキーマ定義とサンプルデータは以下の通りです。

実行例:

table_create Pies TABLE_NO_KEY
# [[0,1337566253.89858,0.000355720520019531],true]
column_create Pies name COLUMN_SCALAR Text
# [[0,1337566253.89858,0.000355720520019531],true]
table_create Keywords TABLE_PAT_KEY ShortText --default_tokenizer 'TokenTable("table", "Keywords")'
# [[0,1337566253.89858,0.000355720520019531],true]
column_create Keywords index COLUMN_INDEX Pies name
# [[0,1337566253.89858,0.000355720520019531],true]
load --table Keywords
[
{"_key": "Apple"}
{"_key": "Orange"}
{"_key": "Raspberry"}
]
# [[0,1337566253.89858,0.000355720520019531],3]
load --table Pies
[
{"name": "Apple Pie"},
{"name": "Orange Pie"}
{"name": "Raspberry Pie"}
{"name": "Stargazy Pie"}
]
# [[0,1337566253.89858,0.000355720520019531],4]

--query RaspberryRaspberry Pie を検索します。

実行例:

select Pies --match_columns name --query 'Raspberry'
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         1
#       ],
#       [
#         [
#           "_id",
#           "UInt32"
#         ],
#         [
#           "name",
#           "Text"
#         ]
#       ],
#       [
#         3,
#         "Raspberry Pie"
#       ]
#     ]
#   ]
# ]

期待通りに、上記のクエリーは Raspberry Pie というレコードにマッチします。

次に、Stargazy Pie--query Stargazy で検索してみましょう。

実行例:

select Pies --match_columns name --query 'Stargazy'
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         0
#       ],
#       [
#         [
#           "_id",
#           "UInt32"
#         ],
#         [
#           "name",
#           "Text"
#         ]
#       ]
#     ]
#   ]
# ]

上記の例では、Stargazy というキーワードは Keywords テーブルに登録されていません。そのためマッチしません。

7.8.16.4. 参考#