| 1 |
.. -*- rst -*- |
| 2 |
|
| 3 |
.. groonga-command |
| 4 |
.. database: completion |
| 5 |
.. $ groonga-suggest-create-dataset ${DB_PATH} query |
| 6 |
|
| 7 |
Completion |
| 8 |
========== |
| 9 |
|
| 10 |
This section describes about the following completion |
| 11 |
features: |
| 12 |
|
| 13 |
* How it works |
| 14 |
* How to use |
| 15 |
* How to learn |
| 16 |
|
| 17 |
How it works |
| 18 |
------------ |
| 19 |
|
| 20 |
The completion feature uses three searches to compute |
| 21 |
completed words: |
| 22 |
|
| 23 |
1. Prefix RK search against registered words. |
| 24 |
2. Cooccurrence search against learned data. |
| 25 |
3. Prefix search against registered words. (optional) |
| 26 |
|
| 27 |
Prefix RK search |
| 28 |
^^^^^^^^^^^^^^^^ |
| 29 |
|
| 30 |
See :doc:`/reference/operations/prefix_rk_search` for prefix RK |
| 31 |
search. |
| 32 |
|
| 33 |
If you create dataset which is named as ``query`` by |
| 34 |
:doc:`/reference/executables/groonga-suggest-create-dataset` |
| 35 |
executable file, you can update pairs of registered word and its |
| 36 |
reading by loading data to ``_key`` and ``kana`` column of |
| 37 |
``item_query`` table explicitly for prefix RK search. |
| 38 |
|
| 39 |
Cooccurrence search |
| 40 |
^^^^^^^^^^^^^^^^^^^ |
| 41 |
|
| 42 |
Cooccurrence search can find registered words from user's |
| 43 |
partial input. It uses user input sequences that will be |
| 44 |
learned from query logs, access logs and so on. |
| 45 |
|
| 46 |
For example, there is the following user input sequence: |
| 47 |
|
| 48 |
+----------+----------+ |
| 49 |
| input | submit | |
| 50 |
+==========+==========+ |
| 51 |
|s |no | |
| 52 |
+----------+----------+ |
| 53 |
|se |no | |
| 54 |
+----------+----------+ |
| 55 |
|sea |no | |
| 56 |
+----------+----------+ |
| 57 |
|sear |no | |
| 58 |
+----------+----------+ |
| 59 |
|searc |no | |
| 60 |
+----------+----------+ |
| 61 |
|search |yes | |
| 62 |
+----------+----------+ |
| 63 |
|e |no | |
| 64 |
+----------+----------+ |
| 65 |
|en |no | |
| 66 |
+----------+----------+ |
| 67 |
|eng |no | |
| 68 |
+----------+----------+ |
| 69 |
|engi |no | |
| 70 |
+----------+----------+ |
| 71 |
|engin |no | |
| 72 |
+----------+----------+ |
| 73 |
|engine |no | |
| 74 |
+----------+----------+ |
| 75 |
|enginen |no (typo!)| |
| 76 |
+----------+----------+ |
| 77 |
|engine |yes | |
| 78 |
+----------+----------+ |
| 79 |
|
| 80 |
Groonga creates the following completion pairs: |
| 81 |
|
| 82 |
+----------+--------------------+ |
| 83 |
| input | completed word | |
| 84 |
+==========+====================+ |
| 85 |
|s |search | |
| 86 |
+----------+--------------------+ |
| 87 |
|se |search | |
| 88 |
+----------+--------------------+ |
| 89 |
|sea |search | |
| 90 |
+----------+--------------------+ |
| 91 |
|sear |search | |
| 92 |
+----------+--------------------+ |
| 93 |
|searc |search | |
| 94 |
+----------+--------------------+ |
| 95 |
|e |engine | |
| 96 |
+----------+--------------------+ |
| 97 |
|en |engine | |
| 98 |
+----------+--------------------+ |
| 99 |
|eng |engine | |
| 100 |
+----------+--------------------+ |
| 101 |
|engi |engine | |
| 102 |
+----------+--------------------+ |
| 103 |
|engin |engine | |
| 104 |
+----------+--------------------+ |
| 105 |
|engine |engine | |
| 106 |
+----------+--------------------+ |
| 107 |
|enginen |engine | |
| 108 |
+----------+--------------------+ |
| 109 |
|
| 110 |
All user not-submitted inputs (e.g. "s", "se" and so on) |
| 111 |
before each an user submission maps to the submitted input |
| 112 |
(e.g. "search"). |
| 113 |
|
| 114 |
To be precise, this description isn't correct because it |
| 115 |
omits about time stamp. Groonga doesn't case about "all user |
| 116 |
not-submitted inputs before each an user |
| 117 |
submission". Groonga just case about "all user not-submitted |
| 118 |
inputs within a minute from an user submission before each |
| 119 |
an user submission". Groonga doesn't treat user inputs |
| 120 |
before a minute ago. |
| 121 |
|
| 122 |
If an user inputs "sea" and cooccurrence search returns |
| 123 |
"search" because "sea" is in input column and corresponding |
| 124 |
completed word column value is "search". |
| 125 |
|
| 126 |
Prefix search |
| 127 |
^^^^^^^^^^^^^ |
| 128 |
|
| 129 |
Prefix search can find registered word that start with |
| 130 |
user's input. This search doesn't care about romaji, |
| 131 |
katakana and hiragana not like prefix RK search. |
| 132 |
|
| 133 |
This search isn't always ran. It's just ran when it's |
| 134 |
requested explicitly or both prefix RK search and |
| 135 |
cooccurrence search return nothing. |
| 136 |
|
| 137 |
For example, there is a registered word "search". An user |
| 138 |
can find "search" by "s", "se", "sea", "sear", "searc" and |
| 139 |
"search". |
| 140 |
|
| 141 |
How to use |
| 142 |
---------- |
| 143 |
|
| 144 |
.. groonga-command |
| 145 |
.. load --table event_query --each 'suggest_preparer(_id, type, item, sequence, time, pair_query)' |
| 146 |
.. [ |
| 147 |
.. {"sequence": "1", "time": 1312950803.86057, "item": "e"}, |
| 148 |
.. {"sequence": "1", "time": 1312950803.96857, "item": "en"}, |
| 149 |
.. {"sequence": "1", "time": 1312950804.26057, "item": "eng"}, |
| 150 |
.. {"sequence": "1", "time": 1312950804.56057, "item": "engi"}, |
| 151 |
.. {"sequence": "1", "time": 1312950804.76057, "item": "engin"}, |
| 152 |
.. {"sequence": "1", "time": 1312950805.86057, "item": "engine", "type": "submit"} |
| 153 |
.. ] |
| 154 |
|
| 155 |
Groonga provides :doc:`/reference/commands/suggest` command to use |
| 156 |
completion. ``--type complete`` option requests completion. |
| 157 |
|
| 158 |
For example, here is an command to get completion results by |
| 159 |
"en": |
| 160 |
|
| 161 |
.. groonga-command |
| 162 |
.. include:: ../../example/reference/suggest/complete/select.log |
| 163 |
.. suggest --table item_query --column kana --types complete --frequency_threshold 1 --query en |
| 164 |
|
| 165 |
How it learns |
| 166 |
------------- |
| 167 |
|
| 168 |
Cooccurrence search uses learned data. They are based on |
| 169 |
query logs, access logs and so on. To create learned data, |
| 170 |
Groonga needs user input sequence with time stamp and user |
| 171 |
submit input with time stamp. |
| 172 |
|
| 173 |
For example, an user wants to search by "engine". The user |
| 174 |
inputs the query with the following sequence: |
| 175 |
|
| 176 |
1. 2011-08-10T13:33:23+09:00: e |
| 177 |
2. 2011-08-10T13:33:23+09:00: en |
| 178 |
3. 2011-08-10T13:33:24+09:00: eng |
| 179 |
4. 2011-08-10T13:33:24+09:00: engi |
| 180 |
5. 2011-08-10T13:33:24+09:00: engin |
| 181 |
6. 2011-08-10T13:33:25+09:00: engine (submit!) |
| 182 |
|
| 183 |
Groonga can be learned from the input sequence by the |
| 184 |
following command:: |
| 185 |
|
| 186 |
load --table event_query --each 'suggest_preparer(_id, type, item, sequence, time, pair_query)' |
| 187 |
[ |
| 188 |
{"sequence": "1", "time": 1312950803.86057, "item": "e"}, |
| 189 |
{"sequence": "1", "time": 1312950803.96857, "item": "en"}, |
| 190 |
{"sequence": "1", "time": 1312950804.26057, "item": "eng"}, |
| 191 |
{"sequence": "1", "time": 1312950804.56057, "item": "engi"}, |
| 192 |
{"sequence": "1", "time": 1312950804.76057, "item": "engin"}, |
| 193 |
{"sequence": "1", "time": 1312950805.86057, "item": "engine", "type": "submit"} |
| 194 |
] |
| 195 |
|
| 196 |
How to update reading data |
| 197 |
-------------------------- |
| 198 |
|
| 199 |
Groonga requires registered word and its reading for prefix RK |
| 200 |
search. This section describes how to register a word and its reading. |
| 201 |
|
| 202 |
Here is an example to register "日本" which means Japan in English: |
| 203 |
|
| 204 |
.. groonga-command |
| 205 |
.. include:: ../../example/reference/suggest/complete/registered-word-japan.log |
| 206 |
.. load --table event_query --each 'suggest_preparer(_id, type, item, sequence, time, pair_query)' |
| 207 |
.. [ |
| 208 |
.. {"sequence": "1", "time": 1312950805.86058, "item": "日本", "type": "submit"} |
| 209 |
.. ] |
| 210 |
|
| 211 |
|
| 212 |
Here is an example to update reading data to complete "日本": |
| 213 |
|
| 214 |
.. groonga-command |
| 215 |
.. include:: ../../example/reference/suggest/complete/update-rk-data.log |
| 216 |
.. load --table item_query |
| 217 |
.. [ |
| 218 |
.. {"_key":"日本", "kana":["ニホン", "ニッポン"]} |
| 219 |
.. ] |
| 220 |
|
| 221 |
Then you can complete registered word "日本" by Romaji input - |
| 222 |
"nihon". |
| 223 |
|
| 224 |
.. groonga-command |
| 225 |
.. include:: ../../example/reference/suggest/complete/rk-search-nihon.log |
| 226 |
.. suggest --table item_query --column kana --types complete --frequency_threshold 1 --query nihon |
| 227 |
|
| 228 |
Without loading above reading data, you can't complete registered word |
| 229 |
"日本" by query - "nihon". |
| 230 |
|
| 231 |
You can register multiple readings for a registered word because |
| 232 |
``kana`` column in ``item_query`` table is defined as a |
| 233 |
:doc:`/reference/columns/vector`. |
| 234 |
|
| 235 |
This is the reason that you can also complete the registered word "日本" |
| 236 |
by query - "nippon". |
| 237 |
|
| 238 |
.. groonga-command |
| 239 |
.. include:: ../../example/reference/suggest/complete/rk-search-nippon.log |
| 240 |
.. suggest --table item_query --column kana --types complete --frequency_threshold 1 --query nippon |
| 241 |
|
| 242 |
This feature is very convenient because you can search registered word |
| 243 |
even though Japanese input method is disabled. |
| 244 |
|
| 245 |
If there are multiple candidates as completed result, you can |
| 246 |
customize priority to set the value of ``boost`` column in |
| 247 |
``item_query`` table. |
| 248 |
|
| 249 |
Here is an example to customize priority for prefix RK search: |
| 250 |
|
| 251 |
.. groonga-command |
| 252 |
.. include:: ../../example/reference/suggest/complete/registered-word-japanese.log |
| 253 |
.. load --table event_query --each 'suggest_preparer(_id, type, item, sequence, time, pair_query)' |
| 254 |
.. [ |
| 255 |
.. {"sequence": "1", "time": 1312950805.86059, "item": "日本語", "type": "submit"} |
| 256 |
.. {"sequence": "1", "time": 1312950805.86060, "item": "日本人", "type": "submit"} |
| 257 |
.. ] |
| 258 |
.. load --table item_query |
| 259 |
.. [ |
| 260 |
.. {"_key":"日本語", "kana":"ニホンゴ"} |
| 261 |
.. {"_key":"日本人", "kana":"ニホンジン"} |
| 262 |
.. ] |
| 263 |
.. suggest --table item_query --column kana --types complete --frequency_threshold 1 --query nihon |
| 264 |
.. load --table item_query |
| 265 |
.. [ |
| 266 |
.. {"_key":"日本人", "boost": 100}, |
| 267 |
.. ] |
| 268 |
.. suggest --table item_query --column kana --types complete --frequency_threshold 1 --query nihon |
| 269 |
|