| 1 |
.. -*- rst -*- |
| 2 |
|
| 3 |
.. groonga-command |
| 4 |
.. database: commands_select |
| 5 |
|
| 6 |
``select`` |
| 7 |
========== |
| 8 |
|
| 9 |
Summary |
| 10 |
------- |
| 11 |
|
| 12 |
``select`` searches records that are matched to specified conditions |
| 13 |
from a table and then outputs them. |
| 14 |
|
| 15 |
``select`` is the most important command in groonga. You need to |
| 16 |
understand ``select`` to use the full power of Groonga. |
| 17 |
|
| 18 |
Syntax |
| 19 |
------ |
| 20 |
|
| 21 |
This command takes many parameters. |
| 22 |
|
| 23 |
The required parameter is only ``table``. Other parameters are |
| 24 |
optional:: |
| 25 |
|
| 26 |
select table |
| 27 |
[match_columns=null] |
| 28 |
[query=null] |
| 29 |
[filter=null] |
| 30 |
[scorer=null] |
| 31 |
[sortby=null] |
| 32 |
[output_columns="_id, _key, *"] |
| 33 |
[offset=0] |
| 34 |
[limit=10] |
| 35 |
[drilldown=null] |
| 36 |
[drilldown_sortby=null] |
| 37 |
[drilldown_output_columns="_key, _nsubrecs"] |
| 38 |
[drilldown_offset=0] |
| 39 |
[drilldown_limit=10] |
| 40 |
[cache=yes] |
| 41 |
[match_escalation_threshold=0] |
| 42 |
[query_expansion=null] |
| 43 |
[query_flags=ALLOW_PRAGMA|ALLOW_COLUMN] |
| 44 |
[query_expander=null] |
| 45 |
[adjuster=null] |
| 46 |
[drilldown_calc_types=NONE] |
| 47 |
[drilldown_calc_target=null] |
| 48 |
[drilldown_filter=null] |
| 49 |
[sort_keys=null] |
| 50 |
[drilldown_sort_keys=null] |
| 51 |
[match_escalation=auto] |
| 52 |
[load_table=null] |
| 53 |
[load_columns=null] |
| 54 |
[load_values=null] |
| 55 |
[drilldown_max_n_target_records=-1] |
| 56 |
[n_workers=0] |
| 57 |
[fuzzy_max_distance_ratio=0] |
| 58 |
[fuzzy_max_distance=0] |
| 59 |
[fuzzy_max_expansions=10] |
| 60 |
[fuzzy_prefix_length=0] |
| 61 |
[fuzzy_with_transposition=yes] |
| 62 |
[fuzzy_tokenize=no] |
| 63 |
|
| 64 |
This command has the following named parameters for dynamic columns: |
| 65 |
|
| 66 |
* ``columns[${NAME}].stage=null`` |
| 67 |
* ``columns[${NAME}].flags=COLUMN_SCALAR`` |
| 68 |
* ``columns[${NAME}].type=null`` |
| 69 |
* ``columns[${NAME}].value=null`` |
| 70 |
* ``columns[${NAME}].window.sort_keys=null`` |
| 71 |
* ``columns[${NAME}].window.group_keys=null`` |
| 72 |
|
| 73 |
You can use one or more alphabets, digits, ``_`` for ``${NAME}``. For |
| 74 |
example, ``column1`` is a valid ``${NAME}``. This is the same rule as |
| 75 |
normal column. See also :ref:`column-create-name`. |
| 76 |
|
| 77 |
Parameters that have the same ``${NAME}`` are grouped. |
| 78 |
|
| 79 |
For example, the following parameters specify one dynamic column: |
| 80 |
|
| 81 |
* ``--columns[name].stage initial`` |
| 82 |
* ``--columns[name].type UInt32`` |
| 83 |
* ``--columns[name].value 29`` |
| 84 |
|
| 85 |
The following parameters specify two dynamic columns: |
| 86 |
|
| 87 |
* ``--columns[name1].stage initial`` |
| 88 |
* ``--columns[name1].type UInt32`` |
| 89 |
* ``--columns[name1].value 29`` |
| 90 |
* ``--columns[name2].stage filtered`` |
| 91 |
* ``--columns[name2].type Float`` |
| 92 |
* ``--columns[name2].value '_score * 0.1'`` |
| 93 |
|
| 94 |
This command has the following named parameters for advanced drilldown: |
| 95 |
|
| 96 |
* ``drilldowns[${LABEL}].keys=null`` |
| 97 |
* ``drilldowns[${LABEL}].sort_keys=null`` |
| 98 |
* ``drilldowns[${LABEL}].output_columns="_key, _nsubrecs"`` |
| 99 |
* ``drilldowns[${LABEL}].offset=0`` |
| 100 |
* ``drilldowns[${LABEL}].limit=10`` |
| 101 |
* ``drilldowns[${LABEL}].calc_types=NONE`` |
| 102 |
* ``drilldowns[${LABEL}].calc_target=null`` |
| 103 |
* ``drilldowns[${LABEL}].filter=null`` |
| 104 |
* ``drilldowns[${LABEL}].max_n_target_records=-1`` |
| 105 |
* ``drilldowns[${LABEL}].columns[${NAME}].stage=null`` |
| 106 |
* ``drilldowns[${LABEL}].columns[${NAME}].flags=COLUMN_SCALAR`` |
| 107 |
* ``drilldowns[${LABEL}].columns[${NAME}].type=null`` |
| 108 |
* ``drilldowns[${LABEL}].columns[${NAME}].value=null`` |
| 109 |
* ``drilldowns[${LABEL}].columns[${NAME}].window.sort_keys=null`` |
| 110 |
* ``drilldowns[${LABEL}].columns[${NAME}].window.group_keys=null`` |
| 111 |
|
| 112 |
.. deprecated:: 6.0.3 |
| 113 |
|
| 114 |
``drilldown[...]`` syntax is deprecated, Use ``drilldowns[...]`` |
| 115 |
instead. |
| 116 |
|
| 117 |
You can use one or more alphabets, digits, ``_`` and ``.`` for |
| 118 |
``${LABEL}``. For example, ``parent.sub1`` is a valid ``${LABEL}``. |
| 119 |
|
| 120 |
Parameters that have the same ``${LABEL}`` are grouped. |
| 121 |
|
| 122 |
For example, the following parameters specify one drilldown: |
| 123 |
|
| 124 |
* ``--drilldowns[label].keys column`` |
| 125 |
* ``--drilldowns[label].sort_keys -_nsubrecs`` |
| 126 |
|
| 127 |
The following parameters specify two drilldowns: |
| 128 |
|
| 129 |
* ``--drilldowns[label1].keys column1`` |
| 130 |
* ``--drilldowns[label1].sort_keys -_nsubrecs`` |
| 131 |
* ``--drilldowns[label2].keys column2`` |
| 132 |
* ``--drilldowns[label2].sort_keys _key`` |
| 133 |
|
| 134 |
Usage |
| 135 |
----- |
| 136 |
|
| 137 |
Let's learn about ``select`` usage with examples. This section shows |
| 138 |
many popular usages. |
| 139 |
|
| 140 |
Here are a schema definition and sample data to show usage. |
| 141 |
|
| 142 |
.. groonga-command |
| 143 |
.. include:: ../../example/reference/commands/select/usage_setup.log |
| 144 |
.. table_create Entries TABLE_HASH_KEY ShortText |
| 145 |
.. column_create Entries content COLUMN_SCALAR Text |
| 146 |
.. column_create Entries n_likes COLUMN_SCALAR UInt32 |
| 147 |
.. column_create Entries tag COLUMN_SCALAR ShortText |
| 148 |
.. table_create Terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto |
| 149 |
.. column_create Terms entries_key_index COLUMN_INDEX|WITH_POSITION Entries _key |
| 150 |
.. column_create Terms entries_content_index COLUMN_INDEX|WITH_POSITION Entries content |
| 151 |
.. load --table Entries |
| 152 |
.. [ |
| 153 |
.. {"_key": "The first post!", |
| 154 |
.. "content": "Welcome! This is my first post!", |
| 155 |
.. "n_likes": 5, |
| 156 |
.. "tag": "Hello"}, |
| 157 |
.. {"_key": "Groonga", |
| 158 |
.. "content": "I started to use Groonga. It's very fast!", |
| 159 |
.. "n_likes": 10, |
| 160 |
.. "tag": "Groonga"}, |
| 161 |
.. {"_key": "Mroonga", |
| 162 |
.. "content": "I also started to use Mroonga. It's also very fast! Really fast!", |
| 163 |
.. "n_likes": 15, |
| 164 |
.. "tag": "Groonga"}, |
| 165 |
.. {"_key": "Good-bye Senna", |
| 166 |
.. "content": "I migrated all Senna system!", |
| 167 |
.. "n_likes": 3, |
| 168 |
.. "tag": "Senna"}, |
| 169 |
.. {"_key": "Good-bye Tritonn", |
| 170 |
.. "content": "I also migrated all Tritonn system!", |
| 171 |
.. "n_likes": 3, |
| 172 |
.. "tag": "Senna"} |
| 173 |
.. ] |
| 174 |
|
| 175 |
There is a table, ``Entries``, for blog entries. An entry has title, |
| 176 |
content, the number of likes for the entry and tag. Title is key of |
| 177 |
``Entries``. Content is value of ``Entries.content`` column. The |
| 178 |
number of likes is value of ``Entries.n_likes`` column. Tag is value |
| 179 |
of ``Entries.tag`` column. |
| 180 |
|
| 181 |
``Entries._key`` column and ``Entries.content`` column are indexed |
| 182 |
using ``TokenBigram`` tokenizer. So both ``Entries._key`` and |
| 183 |
``Entries.content`` are fulltext search ready. |
| 184 |
|
| 185 |
OK. The schema and data for examples are ready. |
| 186 |
|
| 187 |
.. _select-simple-usage: |
| 188 |
|
| 189 |
Simple usage |
| 190 |
^^^^^^^^^^^^ |
| 191 |
|
| 192 |
Here is the most simple usage with the above schema and data. It outputs |
| 193 |
all records in ``Entries`` table. |
| 194 |
|
| 195 |
.. groonga-command |
| 196 |
.. include:: ../../example/reference/commands/select/simple_usage.log |
| 197 |
.. select Entries |
| 198 |
|
| 199 |
Why does the command output all records? There are two reasons. The |
| 200 |
first reason is that the command doesn't specify any search |
| 201 |
conditions. No search condition means all records are matched. The |
| 202 |
second reason is that the number of all records is 5. ``select`` |
| 203 |
command outputs 10 records at a maximum by default. There are only 5 |
| 204 |
records. It is less than 10. So the command outputs all records. |
| 205 |
|
| 206 |
Search conditions |
| 207 |
^^^^^^^^^^^^^^^^^ |
| 208 |
|
| 209 |
Search conditions are specified by ``query`` or ``filter``. You can |
| 210 |
also specify both ``query`` and ``filter``. It means that selected |
| 211 |
records must be matched against both ``query`` and ``filter``. |
| 212 |
|
| 213 |
Search condition: ``query`` |
| 214 |
""""""""""""""""""""""""""" |
| 215 |
|
| 216 |
``query`` is designed for search box in Web page. Imagine a search box |
| 217 |
in google.com. You specify search conditions for ``query`` as space |
| 218 |
separated keywords. For example, ``search engine`` means a matched |
| 219 |
record should contain two words, ``search`` and ``engine``. |
| 220 |
|
| 221 |
Normally, ``query`` parameter is used for specifying fulltext search |
| 222 |
conditions. It can be used for non fulltext search conditions but |
| 223 |
``filter`` is used for the propose. |
| 224 |
|
| 225 |
``query`` parameter is used with ``match_columns`` parameter when |
| 226 |
``query`` parameter is used for specifying fulltext search |
| 227 |
conditions. ``match_columns`` specifies which columns and indexes are |
| 228 |
matched against ``query``. |
| 229 |
|
| 230 |
Here is a simple ``query`` usage example. |
| 231 |
|
| 232 |
.. groonga-command |
| 233 |
.. include:: ../../example/reference/commands/select/simple_query.log |
| 234 |
.. select Entries --match_columns content --query fast |
| 235 |
|
| 236 |
The ``select`` command searches records that contain a word ``fast`` |
| 237 |
in ``content`` column value from ``Entries`` table. |
| 238 |
|
| 239 |
``query`` has query syntax but its details aren't described here. See |
| 240 |
:doc:`/reference/grn_expr/query_syntax` for details. |
| 241 |
|
| 242 |
Search condition: ``filter`` |
| 243 |
"""""""""""""""""""""""""""" |
| 244 |
|
| 245 |
``filter`` is designed for complex search conditions. You specify |
| 246 |
search conditions for ``filter`` as ECMAScript like syntax. |
| 247 |
|
| 248 |
Here is a simple ``filter`` usage example. |
| 249 |
|
| 250 |
.. groonga-command |
| 251 |
.. include:: ../../example/reference/commands/select/simple_filter.log |
| 252 |
.. select Entries --filter 'content @ "fast" && _key == "Groonga"' |
| 253 |
|
| 254 |
The ``select`` command searches records that contain a word ``fast`` |
| 255 |
in ``content`` column value and has ``Groonga`` as ``_key`` from |
| 256 |
``Entries`` table. There are three operators in the command, ``@``, |
| 257 |
``&&`` and ``==``. ``@`` is fulltext search operator. ``&&`` and |
| 258 |
``==`` are the same as ECMAScript. ``&&`` is logical AND operator and |
| 259 |
``==`` is equality operator. |
| 260 |
|
| 261 |
``filter`` has more operators and syntax like grouping by ``(...)`` |
| 262 |
its details aren't described here. See |
| 263 |
:doc:`/reference/grn_expr/script_syntax` for details. |
| 264 |
|
| 265 |
Paging |
| 266 |
^^^^^^ |
| 267 |
|
| 268 |
You can specify range of outputted records by ``offset`` and ``limit``. |
| 269 |
Here is an example to output only the 2nd record. |
| 270 |
|
| 271 |
.. groonga-command |
| 272 |
.. include:: ../../example/reference/commands/select/paging.log |
| 273 |
.. select Entries --offset 1 --limit 1 |
| 274 |
|
| 275 |
``offset`` is zero-based. ``--offset 1`` means output range is |
| 276 |
started from the 2nd record. |
| 277 |
|
| 278 |
``limit`` specifies the max number of output records. ``--limit 1`` |
| 279 |
means the number of output records is 1 at a maximum. If no records |
| 280 |
are matched, ``select`` command outputs no records. |
| 281 |
|
| 282 |
The total number of records |
| 283 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 284 |
|
| 285 |
You can use ``--limit 0`` to retrieve the total number of records |
| 286 |
without any contents of records. |
| 287 |
|
| 288 |
.. groonga-command |
| 289 |
.. include:: ../../example/reference/commands/select/no_limit.log |
| 290 |
.. select Entries --limit 0 |
| 291 |
|
| 292 |
``--limit 0`` is also useful for retrieving only the number of matched |
| 293 |
records. |
| 294 |
|
| 295 |
Drilldown |
| 296 |
^^^^^^^^^ |
| 297 |
|
| 298 |
You can get additional grouped results against the search result in |
| 299 |
one ``select``. You need to use two or more ``SELECT`` s in SQL but |
| 300 |
``select`` in Groonga can do it in one ``select``. |
| 301 |
|
| 302 |
This feature is called as `drilldown |
| 303 |
<http://en.wikipedia.org/wiki/Drill_down>`_ in Groonga. It's also |
| 304 |
called as `faceted search |
| 305 |
<http://en.wikipedia.org/wiki/Faceted_search>`_ in other search |
| 306 |
engine. |
| 307 |
|
| 308 |
For example, think about the following situation. |
| 309 |
|
| 310 |
You search entries that has ``fast`` word: |
| 311 |
|
| 312 |
.. groonga-command |
| 313 |
.. include:: ../../example/reference/commands/select/usage_drilldown_only_query.log |
| 314 |
.. select Entries --filter 'content @ "fast"' |
| 315 |
|
| 316 |
You want to use ``tag`` for additional search condition like |
| 317 |
``--filter 'content @ "fast" && tag == "???"``. But you don't know |
| 318 |
suitable tag until you see the result of ``content @ "fast"``. |
| 319 |
|
| 320 |
If you know the number of matched records of each available tag, you |
| 321 |
can choose suitable tag. You can use drilldown for the case: |
| 322 |
|
| 323 |
.. groonga-command |
| 324 |
.. include:: ../../example/reference/commands/select/usage_drilldown.log |
| 325 |
.. select Entries --filter 'content @ "fast"' --drilldown tag |
| 326 |
|
| 327 |
``--drilldown tag`` returns a list of pair of available tag and the |
| 328 |
number of matched records. You can avoid "no hit search" case by |
| 329 |
choosing a tag from the list. You can also avoid "too many search |
| 330 |
results" case by choosing a tag that the number of matched records is |
| 331 |
few from the list. |
| 332 |
|
| 333 |
You can create the following UI with the drilldown results: |
| 334 |
|
| 335 |
* Links to narrow search results. (Users don't need to input a |
| 336 |
search query by their keyboard. They just click a link.) |
| 337 |
|
| 338 |
Most EC sites use the UI. See side menu at Amazon. |
| 339 |
|
| 340 |
Groonga supports not only counting grouped records but also finding |
| 341 |
the maximum and/or minimum value from grouped records, summing values |
| 342 |
in grouped records and so on. See |
| 343 |
:ref:`select-drilldown-related-parameters` for details. |
| 344 |
|
| 345 |
Dynamic column |
| 346 |
^^^^^^^^^^^^^^ |
| 347 |
|
| 348 |
You can create zero or more columns dynamically while a ``select`` |
| 349 |
execution. You can use them for drilldown by computed value, window |
| 350 |
function and so on. |
| 351 |
|
| 352 |
Here is an example that uses dynamic column for drilldown by computed |
| 353 |
value. This example creates a new column named |
| 354 |
``n_likes_class``. ``n_likes_class`` column has classified value of |
| 355 |
``Entry.n_likes`` value. This example classifies ``Entry.n_likes`` |
| 356 |
column value ``10`` step and the lowest number in the class is the |
| 357 |
classified value. If a ``Entry.n_likes`` value is between ``0`` and |
| 358 |
``9`` such as ``3`` and ``5``, ``n_likes_class`` value (classified |
| 359 |
value) is ``0``. If ``Entry.n_likes`` value is between ``10`` and |
| 360 |
``19`` such as ``10`` and ``15``, ``n_likes_class`` value (classified |
| 361 |
value) is ``10``. |
| 362 |
|
| 363 |
You can use :doc:`/reference/functions/number_classify` function for |
| 364 |
the classification. You need to register ``functions/number`` plugin |
| 365 |
by :doc:`plugin_register` command to use |
| 366 |
:doc:`/reference/functions/number_classify` function. |
| 367 |
|
| 368 |
This example does drilldown by ``n_likes_class`` value. The drilldown |
| 369 |
result will help you to know data trend. |
| 370 |
|
| 371 |
.. groonga-command |
| 372 |
.. include:: ../../example/reference/commands/select/usage_dynamic_column.log |
| 373 |
.. plugin_register functions/number |
| 374 |
.. select \ |
| 375 |
.. --table Entries \ |
| 376 |
.. --columns[n_likes_class].stage initial \ |
| 377 |
.. --columns[n_likes_class].type UInt32 \ |
| 378 |
.. --columns[n_likes_class].value 'number_classify(n_likes, 10)' \ |
| 379 |
.. --drilldown n_likes_class \ |
| 380 |
.. --drilldown_sort_keys _nsubrecs \ |
| 381 |
.. --output_columns n_likes,n_likes_class |
| 382 |
|
| 383 |
See :ref:`select-dynamic-column-related-parameters` for details. |
| 384 |
|
| 385 |
Window function |
| 386 |
^^^^^^^^^^^^^^^ |
| 387 |
|
| 388 |
You can compute each record value from values of grouped records. For |
| 389 |
example, you can compute sums of each group and puts sums to each |
| 390 |
record. The difference against drilldown is drilldown can compute sums |
| 391 |
of each group but it puts sums to each group not record. |
| 392 |
|
| 393 |
Here is the result with window function. Each record has sum: |
| 394 |
|
| 395 |
.. list-table:: |
| 396 |
:header-rows: 1 |
| 397 |
|
| 398 |
* - Group No. |
| 399 |
- Target value |
| 400 |
- Sum result |
| 401 |
* - 1 |
| 402 |
- 5 |
| 403 |
- 5 |
| 404 |
* - 2 |
| 405 |
- 10 |
| 406 |
- 25 |
| 407 |
* - 2 |
| 408 |
- 15 |
| 409 |
- 25 |
| 410 |
* - 3 |
| 411 |
- 3 |
| 412 |
- 8 |
| 413 |
* - 3 |
| 414 |
- 5 |
| 415 |
- 8 |
| 416 |
|
| 417 |
Here is the result with drilldown. Each group has sum: |
| 418 |
|
| 419 |
.. list-table:: |
| 420 |
:header-rows: 1 |
| 421 |
|
| 422 |
* - Group No. |
| 423 |
- Target values |
| 424 |
- Sum result |
| 425 |
* - 1 |
| 426 |
- 5 |
| 427 |
- 5 |
| 428 |
* - 2 |
| 429 |
- 10, 15 |
| 430 |
- 25 |
| 431 |
* - 3 |
| 432 |
- 3, 5 |
| 433 |
- 8 |
| 434 |
|
| 435 |
Window function is useful for data analysis. |
| 436 |
|
| 437 |
Here is an example that sums ``Entries.n_likes`` per |
| 438 |
``Entries.tag``: |
| 439 |
|
| 440 |
.. groonga-command |
| 441 |
.. include:: ../../example/reference/commands/select/usage_window_function.log |
| 442 |
.. plugin_register functions/number |
| 443 |
.. select \ |
| 444 |
.. --table Entries \ |
| 445 |
.. --columns[n_likes_sum_per_tag].stage initial \ |
| 446 |
.. --columns[n_likes_sum_per_tag].type UInt32 \ |
| 447 |
.. --columns[n_likes_sum_per_tag].value 'window_sum(n_likes)' \ |
| 448 |
.. --columns[n_likes_sum_per_tag].window.group_keys tag \ |
| 449 |
.. --output_columns tag,n_likes,n_likes_sum_per_tag |
| 450 |
|
| 451 |
See :ref:`select-window-function-related-parameters` for details. |
| 452 |
|
| 453 |
.. _select-usage-typo-tolerance: |
| 454 |
|
| 455 |
Typo tolerance |
| 456 |
^^^^^^^^^^^^^^ |
| 457 |
|
| 458 |
You can implement typo tolerance search by specifying how many |
| 459 |
characters to be accepted as typo. If no records are matched by the |
| 460 |
given query, Groonga searches with typo fixed query again |
| 461 |
automatically. |
| 462 |
|
| 463 |
The number of accepted typo characters is 0 by default. So typo |
| 464 |
tolerance search isn't enabled by default. |
| 465 |
|
| 466 |
You can enable typo tolerance search by specifying |
| 467 |
:ref:`select-fuzzy-max-distance-ratio` or |
| 468 |
:ref:`select-fuzzy-max-distance`. In general, |
| 469 |
``--fuzzy_max_distance_ratio 0.34`` will be a good parameter. |
| 470 |
|
| 471 |
:ref:`select-fuzzy-max-distance-ratio` specifies how many typo |
| 472 |
characters is accepted based on the number of characters of each input |
| 473 |
term. |
| 474 |
|
| 475 |
Here is a table that shows how many characters are accepted as typo |
| 476 |
with ``--fuzzy_max_distance_ratio 0.34``: |
| 477 |
|
| 478 |
.. list-table:: |
| 479 |
:header-rows: 1 |
| 480 |
|
| 481 |
* - The number of characters of a term |
| 482 |
- The number of accepted typo characters |
| 483 |
* - 1 |
| 484 |
- 0 (``floor(1 * 0.34) = floor(0.34) = 0``) |
| 485 |
* - 2 |
| 486 |
- 0 (``floor(2 * 0.34) = floor(0.68) = 0``) |
| 487 |
* - 3 |
| 488 |
- 1 (``floor(3 * 0.34) = floor(1.02) = 1``) |
| 489 |
* - 4 |
| 490 |
- 1 (``floor(4 * 0.34) = floor(1.36) = 1``) |
| 491 |
* - 5 |
| 492 |
- 1 (``floor(5 * 0.34) = floor(1.7) = 1``) |
| 493 |
* - 6 |
| 494 |
- 2 (``floor(6 * 0.34) = floor(2.04) = 2``) |
| 495 |
|
| 496 |
In other words, Groonga doesn't accept any typo for a short term |
| 497 |
(0-2 characters term), accepts 1 typo for a middle term (3-5 |
| 498 |
characters term) and accepts 2 or more typos for a long term (6- |
| 499 |
characters term). |
| 500 |
|
| 501 |
Here is an example that shows that we can search ``Groonga`` with |
| 502 |
``Moronga`` (2 typos): |
| 503 |
|
| 504 |
.. groonga-command |
| 505 |
.. include:: ../../example/reference/commands/select/usage_fuzzy_max_distance_ratio.log |
| 506 |
.. select \ |
| 507 |
.. --table Entries \ |
| 508 |
.. --fuzzy_max_distance_ratio 0.34 \ |
| 509 |
.. --match_columns content \ |
| 510 |
.. --query Moronga \ |
| 511 |
.. --output_columns content,_score |
| 512 |
|
| 513 |
You can specify the fixed number of typo accept characters by |
| 514 |
:ref:`select-fuzzy-max-distance`. For example, Groonga accepts 2 |
| 515 |
characters for all terms with ``--fuzzy_max_distance 2``. But |
| 516 |
``--fuzzy_max_distance_ratio`` will be better for many use cases. |
| 517 |
|
| 518 |
You need correct terms for typo tolerance search. Groonga uses terms |
| 519 |
in a lexicon as correct terms. ``Terms`` is a lexicon for this |
| 520 |
case. Terms in a lexicon are generated by a tokenizer. If your data is |
| 521 |
alphabet based language such as English, you can use |
| 522 |
:doc:`/reference/tokenizers/token_ngram`. Because |
| 523 |
:doc:`/reference/tokenizers/token_ngram` tokenizes a text to (almost) |
| 524 |
words for alphabet based languages. If your data isn't alphabet based |
| 525 |
language such as Japanese, you can't use |
| 526 |
:doc:`/reference/tokenizers/token_ngram`. Because |
| 527 |
:doc:`/reference/tokenizers/token_ngram` tokenizes a text to |
| 528 |
N-characters for non alphabet based languages. You need to use |
| 529 |
morphological analyzer based tokenizer for non alphabet based |
| 530 |
languages. For example, you can use |
| 531 |
:doc:`/reference/tokenizers/token_mecab` for Japanese. (You can use |
| 532 |
:doc:`/reference/tokenizers/token_mecab` for non Japanese languages |
| 533 |
with suitable dictionary.) |
| 534 |
|
| 535 |
Here is an example to use typo tolerance search with Japanese |
| 536 |
text. ``--default_tokenizer TokenMecab`` for ``JapaneseTerms`` is |
| 537 |
important. ``JapaneseTerms`` is a lexicon for this case. |
| 538 |
|
| 539 |
.. groonga-command |
| 540 |
.. include:: ../../example/reference/commands/select/usage_typo_tolerance_japanese.log |
| 541 |
.. table_create JapaneseEntries TABLE_NO_KEY |
| 542 |
.. column_create JapaneseEntries content COLUMN_SCALAR Text |
| 543 |
.. table_create JapaneseTerms TABLE_PAT_KEY ShortText \ |
| 544 |
.. --default_tokenizer TokenMecab \ |
| 545 |
.. --normalizer NormalizerNFKC150 |
| 546 |
.. column_create JapaneseTerms japanese_entries_content \ |
| 547 |
.. COLUMN_INDEX|WITH_POSITION JapaneseEntries content |
| 548 |
.. load --table JapaneseEntries |
| 549 |
.. [ |
| 550 |
.. {"content": "ようこそ!これが最初の投稿です!"}, |
| 551 |
.. {"content": "Groongaを使い始めました。とても速いですね!"}, |
| 552 |
.. {"content": "Mroongaも使い始めました。これもとても速いですね!本当に速い!"}, |
| 553 |
.. {"content": "Sennaのシステムをすべて移行しました!"}, |
| 554 |
.. {"content": "Tritonnのシステムもすべて移行しました!"} |
| 555 |
.. ] |
| 556 |
.. select \ |
| 557 |
.. --table JapaneseEntries \ |
| 558 |
.. --fuzzy_max_distance_ratio 0.34 \ |
| 559 |
.. --match_columns content \ |
| 560 |
.. --query ともて \ |
| 561 |
.. --output_columns content,_score |
| 562 |
|
| 563 |
See :ref:`select-fuzzy-query-related-parameters` for details. |
| 564 |
|
| 565 |
Parameters |
| 566 |
---------- |
| 567 |
|
| 568 |
This section describes all parameters. Parameters are categorized. |
| 569 |
|
| 570 |
Required parameters |
| 571 |
^^^^^^^^^^^^^^^^^^^ |
| 572 |
|
| 573 |
There is a required parameter, ``table``. |
| 574 |
|
| 575 |
.. _select-table: |
| 576 |
|
| 577 |
``table`` |
| 578 |
""""""""" |
| 579 |
|
| 580 |
Specifies a table to be searched. ``table`` must be specified. |
| 581 |
|
| 582 |
If nonexistent table is specified, an error is returned. |
| 583 |
|
| 584 |
.. groonga-command |
| 585 |
.. include:: ../../example/reference/commands/select/table_nonexistent.log |
| 586 |
.. select Nonexistent |
| 587 |
|
| 588 |
.. _select-search-related-parameters: |
| 589 |
|
| 590 |
Search related parameters |
| 591 |
^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 592 |
|
| 593 |
There are search related parameters. Typically, ``match_columns`` and |
| 594 |
``query`` parameters are used for implementing a search |
| 595 |
box. ``filter`` parameters is used for implementing complex search |
| 596 |
feature. |
| 597 |
|
| 598 |
If both ``query`` and ``filter`` are specified, selected records must |
| 599 |
be matched against both ``query`` and ``filter``. If both ``query`` |
| 600 |
and ``filter`` aren't specified, all records are selected. |
| 601 |
|
| 602 |
.. _select-match-columns: |
| 603 |
|
| 604 |
``match_columns`` |
| 605 |
""""""""""""""""" |
| 606 |
|
| 607 |
Specifies the default target column for fulltext search by ``query`` |
| 608 |
parameter value. A target column for fulltext search can be specified |
| 609 |
in ``query`` parameter. The difference between ``match_columns`` and |
| 610 |
``query`` is whether weight and score function are supported or |
| 611 |
not. ``match_columns`` supports them but ``query`` doesn't. |
| 612 |
|
| 613 |
Weight is relative importance of target column. A higher weight target |
| 614 |
column gets more hit score rather than a lower weight target column |
| 615 |
when a record is matched by fulltext search. The default weight is 1. |
| 616 |
|
| 617 |
Here is a simple ``match_columns`` usage example. |
| 618 |
|
| 619 |
.. groonga-command |
| 620 |
.. include:: ../../example/reference/commands/select/match_columns_simple.log |
| 621 |
.. select Entries --match_columns content --query fast --output_columns '_key, _score' |
| 622 |
|
| 623 |
``--match_columns content`` means the default target column for |
| 624 |
fulltext search is ``content`` column and its weight |
| 625 |
is 1. ``--output_columns '_key, _score'`` means that the ``select`` |
| 626 |
command outputs ``_key`` value and ``_score`` value for matched |
| 627 |
records. |
| 628 |
|
| 629 |
Pay attention to ``_score`` value. ``_score`` value is the number of |
| 630 |
matched counts against ``query`` parameter value. In the example, |
| 631 |
``query`` parameter value is ``fast``. The fact that ``_score`` value |
| 632 |
is 1 means that ``fast`` appears in ``content`` column only once. The |
| 633 |
fact that ``_score`` value is 2 means that ``fast`` appears in |
| 634 |
``content`` column twice. |
| 635 |
|
| 636 |
To specify weight, ``column * weight`` syntax is used. Here is a |
| 637 |
weight usage example. |
| 638 |
|
| 639 |
.. groonga-command |
| 640 |
.. include:: ../../example/reference/commands/select/match_columns_weight.log |
| 641 |
.. select Entries --match_columns 'content * 2' --query fast --output_columns '_key, _score' |
| 642 |
|
| 643 |
``--match_columns 'content * 2'`` means the default target column for |
| 644 |
fulltext search is ``content`` column and its weight is 2. |
| 645 |
|
| 646 |
Pay attention to ``_score`` value. ``_score`` value is doubled because |
| 647 |
weight is 2. |
| 648 |
|
| 649 |
You can specify one or more columns as the default target columns for |
| 650 |
fulltext search. If one or more columns are specified, fulltext search |
| 651 |
is done for all columns and scores are accumulated. If one of the |
| 652 |
columns is matched against ``query`` parameter value, the record is |
| 653 |
treated as matched. |
| 654 |
|
| 655 |
To specify one or more columns, ``column1 * weight1 || column2 * |
| 656 |
weight2 || ...`` syntax is used. ``* weight`` can be omitted. If it is |
| 657 |
omitted, 1 is used for weight. Here is a one or more columns usage |
| 658 |
example. |
| 659 |
|
| 660 |
.. groonga-command |
| 661 |
.. include:: ../../example/reference/commands/select/match_columns_some_columns.log |
| 662 |
.. select Entries --match_columns '_key * 10 || content' --query groonga --output_columns '_key, _score' |
| 663 |
|
| 664 |
``--match_columns '_key * 10 || content'`` means the default target |
| 665 |
columns for fulltext search are ``_key`` and ``content`` columns and |
| 666 |
``_key`` column's weight is 10 and ``content`` column's weight |
| 667 |
is 1. This weight allocation means ``_key`` column value is more |
| 668 |
important rather than ``content`` column value. In this example, title |
| 669 |
of blog entry is more important rather than content of blog entry. |
| 670 |
|
| 671 |
You can also specify score function. See :doc:`/reference/scorer` for |
| 672 |
details. |
| 673 |
|
| 674 |
Note that score function isn't related to :ref:`select-scorer` |
| 675 |
parameter. |
| 676 |
|
| 677 |
You can also specify index columns to ``--match_columns`` |
| 678 |
parameter. In such a case, you can control what index column should be |
| 679 |
used and what data column should be searched explicitly. |
| 680 |
|
| 681 |
If data column is specified to ``--match_columns``, Groonga searches |
| 682 |
related index column automatically, but it is not defined as a spec |
| 683 |
that which index column is actually selected. Thus, if multiple index |
| 684 |
columns are created against one data column, there is no way to know |
| 685 |
which index column will be selected in advance. (In most cases, latest |
| 686 |
created index column will be selected, but it is undocumented |
| 687 |
behavior.) |
| 688 |
|
| 689 |
Here is a use case how to specify index column. |
| 690 |
|
| 691 |
* index column for one data column |
| 692 |
* index column for multiple data column |
| 693 |
|
| 694 |
If you use index column for one data column, index column which |
| 695 |
corresponds to data column is paired. Thus, |
| 696 |
``TERMS_TABLE.INDEX_COLUMN`` should be specified. On the other hand, if |
| 697 |
you use index column for multiple data column, all data column is |
| 698 |
searched by default. If you want to use specific multiple index column |
| 699 |
to search specific data column, Specify index column with data column |
| 700 |
name such as ``TERMS_TABLE.INDEX_COLUMN.DATA_COLUMN``. See example use |
| 701 |
case :ref:`full-text-search-with-specific-index-name` for details. |
| 702 |
|
| 703 |
.. _select-query: |
| 704 |
|
| 705 |
``query`` |
| 706 |
""""""""" |
| 707 |
|
| 708 |
Specifies the query text. Normally, it is used for fulltext search |
| 709 |
with ``match_columns`` parameter. ``query`` parameter is designed for |
| 710 |
a fulltext search form in a Web page. A query text should be formatted |
| 711 |
in :doc:`/reference/grn_expr/query_syntax`. The syntax is similar to common search |
| 712 |
form like Google's search form. For example, ``word1 word2`` means |
| 713 |
that groonga searches records that contain both ``word1`` and |
| 714 |
``word2``. ``word1 OR word2`` means that groonga searches records that |
| 715 |
contain either ``word1`` or ``word2``. |
| 716 |
|
| 717 |
Here is a simple logical and search example. |
| 718 |
|
| 719 |
.. groonga-command |
| 720 |
.. include:: ../../example/reference/commands/select/query_and.log |
| 721 |
.. select Entries --match_columns content --query "fast groonga" |
| 722 |
|
| 723 |
The ``select`` command searches records that contain two words |
| 724 |
``fast`` and ``groonga`` in ``content`` column value from ``Entries`` |
| 725 |
table. |
| 726 |
|
| 727 |
Here is a simple logical or search example. |
| 728 |
|
| 729 |
.. groonga-command |
| 730 |
.. include:: ../../example/reference/commands/select/query_or.log |
| 731 |
.. select Entries --match_columns content --query "groonga OR mroonga" |
| 732 |
|
| 733 |
The ``select`` command searches records that contain one of two words |
| 734 |
``groonga`` or ``mroonga`` in ``content`` column value from |
| 735 |
``Entries`` table. |
| 736 |
|
| 737 |
See :doc:`/reference/grn_expr/query_syntax` for other syntax. |
| 738 |
|
| 739 |
It can be used for not only fulltext search but also other |
| 740 |
conditions. For example, ``column:value`` means the value of |
| 741 |
``column`` column is equal to ``value``. ``column:<value`` means the |
| 742 |
value of ``column`` column is less than ``value``. |
| 743 |
|
| 744 |
Here is a simple equality operator search example. |
| 745 |
|
| 746 |
.. groonga-command |
| 747 |
.. include:: ../../example/reference/commands/select/query_equal.log |
| 748 |
.. select Entries --query _key:Groonga |
| 749 |
|
| 750 |
The ``select`` command searches records that ``_key`` column value is |
| 751 |
``Groonga`` from ``Entries`` table. |
| 752 |
|
| 753 |
Here is a simple less than operator search example. |
| 754 |
|
| 755 |
.. groonga-command |
| 756 |
.. include:: ../../example/reference/commands/select/query_less_than.log |
| 757 |
.. select Entries --query n_likes:<11 |
| 758 |
|
| 759 |
The ``select`` command searches records that ``n_likes`` column value |
| 760 |
is less than ``11`` from ``Entries`` table. |
| 761 |
|
| 762 |
See :doc:`/reference/grn_expr/query_syntax` for other operations. |
| 763 |
|
| 764 |
.. _select-filter: |
| 765 |
|
| 766 |
``filter`` |
| 767 |
"""""""""" |
| 768 |
|
| 769 |
Specifies the filter text. Normally, it is used for complex search |
| 770 |
conditions. ``filter`` can be used with ``query`` parameter. If both |
| 771 |
``filter`` and ``query`` are specified, there are combined with |
| 772 |
logical and. It means that matched records should be matched against |
| 773 |
both ``filter`` and ``query``. |
| 774 |
|
| 775 |
``filter`` parameter is designed for complex conditions. A filter text |
| 776 |
should be formatted in :doc:`/reference/grn_expr/script_syntax`. The syntax is |
| 777 |
similar to ECMAScript. For example, ``column == "value"`` means that |
| 778 |
the value of ``column`` column is equal to ``"value"``. ``column < |
| 779 |
value`` means that the value of ``column`` column is less than |
| 780 |
``value``. |
| 781 |
|
| 782 |
Here is a simple equality operator search example. |
| 783 |
|
| 784 |
.. groonga-command |
| 785 |
.. include:: ../../example/reference/commands/select/filter_equal.log |
| 786 |
.. select Entries --filter '_key == "Groonga"' |
| 787 |
|
| 788 |
The ``select`` command searches records that ``_key`` column value is |
| 789 |
``Groonga`` from ``Entries`` table. |
| 790 |
|
| 791 |
Here is a simple less than operator search example. |
| 792 |
|
| 793 |
.. groonga-command |
| 794 |
.. include:: ../../example/reference/commands/select/filter_less_than.log |
| 795 |
.. select Entries --filter 'n_likes < 11' |
| 796 |
|
| 797 |
The ``select`` command searches records that ``n_likes`` column value |
| 798 |
is less than ``11`` from ``Entries`` table. |
| 799 |
|
| 800 |
See :doc:`/reference/grn_expr/script_syntax` for other operators. |
| 801 |
|
| 802 |
.. _select-load-table: |
| 803 |
|
| 804 |
``load_table`` |
| 805 |
"""""""""""""" |
| 806 |
|
| 807 |
.. versionadded:: 9.0.1 |
| 808 |
|
| 809 |
You can store specified a table a result of ``select`` with ``--load_table``, ``--load-columns`` and ``--load_values`` arguments. |
| 810 |
``--load_table`` specifies a table name for storing a result of ``select``. |
| 811 |
|
| 812 |
You must specify a table that already exists. |
| 813 |
|
| 814 |
This argument must use with :ref:`select-load-columns` and :ref:`select-load-values`. |
| 815 |
|
| 816 |
Here is an example that can store ``_id`` and ``timestamp`` that a result of ``select`` in a Logs table specified by ``--load_table``. |
| 817 |
|
| 818 |
.. groonga-command |
| 819 |
.. include:: ../../example/reference/commands/select/load_table.log |
| 820 |
.. table_create Logs_20150203 TABLE_HASH_KEY ShortText |
| 821 |
.. column_create Logs_20150203 timestamp COLUMN_SCALAR Time |
| 822 |
.. |
| 823 |
.. table_create Logs TABLE_HASH_KEY ShortText |
| 824 |
.. column_create Logs original_id COLUMN_SCALAR UInt32 |
| 825 |
.. column_create Logs timestamp_text COLUMN_SCALAR ShortText |
| 826 |
.. |
| 827 |
.. load --table Logs_20150203 |
| 828 |
.. [ |
| 829 |
.. { |
| 830 |
.. "_key": "2015-02-03:1", |
| 831 |
.. "timestamp": "2015-02-03 10:49:00" |
| 832 |
.. }, |
| 833 |
.. { |
| 834 |
.. "_key": "2015-02-03:2", |
| 835 |
.. "timestamp": "2015-02-03 12:49:00" |
| 836 |
.. } |
| 837 |
.. ] |
| 838 |
.. select \ |
| 839 |
.. --table Logs_20150203 \ |
| 840 |
.. --load_table Logs \ |
| 841 |
.. --load_columns "_key, original_id, timestamp_text" \ |
| 842 |
.. --load_values "_key, _id, timestamp" |
| 843 |
.. select --table Logs |
| 844 |
|
| 845 |
.. _select-load-columns: |
| 846 |
|
| 847 |
``load_columns`` |
| 848 |
"""""""""""""""" |
| 849 |
|
| 850 |
.. versionadded:: 9.0.1 |
| 851 |
|
| 852 |
Specifies columns of a table that specifying ``--load-table``. |
| 853 |
Stores value of columns that specified with :ref:`select-load-values` in columns that specified with this argument. |
| 854 |
You must specify columns that already exists. |
| 855 |
|
| 856 |
This argument must use with :ref:`select-load-table` and :ref:`select-load-values`. |
| 857 |
|
| 858 |
See example of ``--load_table`` for how to use this argument. |
| 859 |
|
| 860 |
.. _select-load-values: |
| 861 |
|
| 862 |
``load_values`` |
| 863 |
""""""""""""""" |
| 864 |
|
| 865 |
.. versionadded:: 9.0.1 |
| 866 |
|
| 867 |
Specifies columns of result of ``select``. |
| 868 |
Specifies columns for storing values into columns that specified with :ref:`select-load-columns`. |
| 869 |
You must specify columns that already exists. |
| 870 |
|
| 871 |
This argument must use with :ref:`select-load-table` and :ref:`select-load-columns`. |
| 872 |
|
| 873 |
See example of ``--load_table`` for how to use this argument. |
| 874 |
|
| 875 |
.. _select-advanced-search-parameters: |
| 876 |
|
| 877 |
Advanced search parameters |
| 878 |
^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 879 |
|
| 880 |
.. _select-match-escalation-threshold: |
| 881 |
|
| 882 |
``match_escalation_threshold`` |
| 883 |
"""""""""""""""""""""""""""""" |
| 884 |
|
| 885 |
.. versionadded:: 8.0.1 |
| 886 |
|
| 887 |
Specifies threshold to determine whether search strategy |
| 888 |
escalation is used or not. The threshold is compared against the |
| 889 |
number of matched records. If the number of matched records is equal |
| 890 |
to or less than the threshold, the search strategy escalation is |
| 891 |
used. See :doc:`/spec/search` about the search strategy escalation. |
| 892 |
|
| 893 |
The default threshold is 0. It means that search strategy escalation |
| 894 |
is used only when no records are matched. |
| 895 |
|
| 896 |
The default threshold can be customized by one of the followings. |
| 897 |
|
| 898 |
* ``--with-match-escalation-threshold`` option of configure |
| 899 |
* ``--match-escalation-threshold`` option of groonga command |
| 900 |
* ``match-escalation-threshold`` configuration item in configuration |
| 901 |
file |
| 902 |
|
| 903 |
Here is a simple ``match_escalation_threshold`` usage example. The |
| 904 |
first ``select`` doesn't have ``match_escalation_threshold`` |
| 905 |
parameter. The second ``select`` has ``match_escalation_threshold`` |
| 906 |
parameter. |
| 907 |
|
| 908 |
.. groonga-command |
| 909 |
.. include:: ../../example/reference/commands/select/match_escalation_threshold.log |
| 910 |
.. select Entries --match_columns content --query groo |
| 911 |
.. select Entries --match_columns content --query groo --match_escalation_threshold -1 |
| 912 |
|
| 913 |
The first ``select`` command searches records that contain a word |
| 914 |
``groo`` in ``content`` column value from ``Entries`` table. But no |
| 915 |
records are matched because the ``TokenBigram`` tokenizer tokenizes |
| 916 |
``groonga`` to ``groonga`` not ``gr|ro|oo|on|ng|ga``. (The |
| 917 |
``TokenBigramSplitSymbolAlpha`` tokenizer tokenizes ``groonga`` to |
| 918 |
``gr|ro|oo|on|ng|ga``. See :doc:`/reference/tokenizers` for details.) |
| 919 |
It means that ``groonga`` is indexed but ``groo`` isn't indexed. So no |
| 920 |
records are matched against ``groo`` by exact match. In the case, the |
| 921 |
search strategy escalation is used because the number of matched |
| 922 |
records (0) is equal to ``match_escalation_threshold`` (0). One record |
| 923 |
is matched against ``groo`` by unsplit search. |
| 924 |
|
| 925 |
The second ``select`` command also searches records that contain a |
| 926 |
word ``groo`` in ``content`` column value from ``Entries`` table. And |
| 927 |
it also doesn't find matched records. In this case, the search |
| 928 |
strategy escalation is not used because the number of matched |
| 929 |
records (0) is larger than ``match_escalation_threshold`` (-1). So no |
| 930 |
more searches aren't executed. And no records are matched. |
| 931 |
|
| 932 |
.. _select-match-escalation: |
| 933 |
|
| 934 |
``match_escalation`` |
| 935 |
"""""""""""""""""""" |
| 936 |
|
| 937 |
Specifies how to use match escalation. See also |
| 938 |
:ref:`select-match-escalation` and :doc:`/spec/search` about the match |
| 939 |
escalation. |
| 940 |
|
| 941 |
Here are available values: |
| 942 |
|
| 943 |
.. list-table:: |
| 944 |
:header-rows: 1 |
| 945 |
|
| 946 |
* - Value |
| 947 |
- Description |
| 948 |
* - ``auto`` |
| 949 |
- Groonga uses :ref:`select-match-escalation-threshold` to |
| 950 |
determine whether match escalation is used or not. |
| 951 |
|
| 952 |
This is the default. |
| 953 |
* - ``yes`` |
| 954 |
- Groonga always uses match escalation. |
| 955 |
* - ``no`` |
| 956 |
- Groonga never use match escalation. |
| 957 |
|
| 958 |
``--match_escalation yes`` is stronger than |
| 959 |
``--match_escalation_threshold 9999...999``. ``--filter 'true && |
| 960 |
column @ "query"`` with ``--match_escalation yes`` uses match |
| 961 |
escalation. ``--filter 'true && column @ "query"`` with |
| 962 |
``--match_escalation_threshold 9999...999`` doesn't use match |
| 963 |
escalation. |
| 964 |
|
| 965 |
Here is a simple ``match_escalation`` usage example. The first |
| 966 |
``select`` doesn't have ``match_escalation`` parameter. The |
| 967 |
second ``select`` has ``match_escalation`` parameter. |
| 968 |
|
| 969 |
.. groonga-command |
| 970 |
.. include:: ../../example/reference/commands/select/match_escalation.log |
| 971 |
.. select Entries --filter 'true && content @ "groo"' |
| 972 |
.. select Entries --filter 'true && content @ "groo"' --match_escalation yes |
| 973 |
|
| 974 |
The first ``select`` command searches records that contain a word |
| 975 |
``groo`` in ``content`` column value from ``Entries`` table. But no |
| 976 |
records are matched because the ``TokenBigram`` tokenizer tokenizes |
| 977 |
``groonga`` to ``groonga`` not ``gr|ro|oo|on|ng|ga``. |
| 978 |
|
| 979 |
The second ``select`` command also searches records that contain a |
| 980 |
word ``groo`` in ``content`` column value from ``Entries`` table. And |
| 981 |
it uses match escalation. So it can find matched records. |
| 982 |
|
| 983 |
.. _select-query-expansion: |
| 984 |
|
| 985 |
``query_expansion`` |
| 986 |
""""""""""""""""""" |
| 987 |
|
| 988 |
.. deprecated:: 3.0.2 |
| 989 |
Use :ref:`select-query-expander` instead. |
| 990 |
|
| 991 |
.. _select-query-flags: |
| 992 |
|
| 993 |
``query_flags`` |
| 994 |
""""""""""""""" |
| 995 |
|
| 996 |
It customs ``query`` parameter syntax. You cannot update column value |
| 997 |
by ``query`` parameter by default. But if you specify |
| 998 |
``ALLOW_COLUMN|ALLOW_UPDATE`` as ``query_flags``, you can update |
| 999 |
column value by ``query``. |
| 1000 |
|
| 1001 |
Here are available values: |
| 1002 |
|
| 1003 |
* ``ALLOW_PRAGMA`` |
| 1004 |
* ``ALLOW_COLUMN`` |
| 1005 |
* ``ALLOW_UPDATE`` |
| 1006 |
* ``ALLOW_LEADING_NOT`` |
| 1007 |
* ``QUERY_NO_SYNTAX_ERROR`` |
| 1008 |
* ``NONE`` |
| 1009 |
|
| 1010 |
``ALLOW_PRAGMA`` enables pragma at the head of ``query``. This is not |
| 1011 |
implemented yet. |
| 1012 |
|
| 1013 |
``ALLOW_COLUMN`` enables search against columns that are not included |
| 1014 |
in ``match_columns``. To specify column, there are ``COLUMN:...`` |
| 1015 |
syntaxes. |
| 1016 |
|
| 1017 |
``ALLOW_UPDATE`` enables column update by ``query`` with |
| 1018 |
``COLUMN:=NEW_VALUE`` syntax. ``ALLOW_COLUMN`` is also required to |
| 1019 |
update column because the column update syntax specifies column. |
| 1020 |
|
| 1021 |
``ALLOW_LEADING_NOT`` enables leading NOT condition with ``-WORD`` |
| 1022 |
syntax. The query searches records that doesn't match |
| 1023 |
``WORD``. Leading NOT condition query is heavy query in many cases |
| 1024 |
because it matches many records. So this flag is disabled by |
| 1025 |
default. Be careful about it when you use the flag. |
| 1026 |
|
| 1027 |
``QUERY_NO_SYNTAX_ERROR`` enables never causes syntax error for query. |
| 1028 |
This flag is useful when an application uses user input directly and doesn't want to show syntax error to the user and in a log. |
| 1029 |
This flag is disabled by default. |
| 1030 |
|
| 1031 |
``NONE`` is just ignores. You can use ``NONE`` for specifying no flags. |
| 1032 |
|
| 1033 |
They can be combined by separated ``|`` such as |
| 1034 |
``ALLOW_COLUMN|ALLOW_UPDATE``. |
| 1035 |
|
| 1036 |
The default value is ``ALLOW_PRAGMA|ALLOW_COLUMN``. |
| 1037 |
|
| 1038 |
Here is a usage example of ``ALLOW_COLUMN``. |
| 1039 |
|
| 1040 |
.. groonga-command |
| 1041 |
.. include:: ../../example/reference/commands/select/query_flags_allow_column.log |
| 1042 |
.. select Entries --query content:@mroonga --query_flags ALLOW_COLUMN |
| 1043 |
|
| 1044 |
The ``select`` command searches records that contain ``mroonga`` in |
| 1045 |
``content`` column value from ``Entries`` table. |
| 1046 |
|
| 1047 |
Here is a usage example of ``ALLOW_UPDATE``. |
| 1048 |
|
| 1049 |
.. groonga-command |
| 1050 |
.. include:: ../../example/reference/commands/select/query_flags_allow_update.log |
| 1051 |
.. table_create Users TABLE_HASH_KEY ShortText |
| 1052 |
.. column_create Users age COLUMN_SCALAR UInt32 |
| 1053 |
.. load --table Users |
| 1054 |
.. [ |
| 1055 |
.. {"_key": "alice", "age": 18}, |
| 1056 |
.. {"_key": "bob", "age": 20} |
| 1057 |
.. ] |
| 1058 |
.. select Users --query age:=19 --query_flags ALLOW_COLUMN|ALLOW_UPDATE |
| 1059 |
.. select Users |
| 1060 |
|
| 1061 |
The first ``select`` command sets ``age`` column value of all records |
| 1062 |
to ``19``. The second ``select`` command outputs updated ``age`` |
| 1063 |
column values. |
| 1064 |
|
| 1065 |
Here is a usage example of ``ALLOW_LEADING_NOT``. |
| 1066 |
|
| 1067 |
.. groonga-command |
| 1068 |
.. include:: ../../example/reference/commands/select/query_flags_allow_leading_not.log |
| 1069 |
.. select Entries --match_columns content --query -mroonga --query_flags ALLOW_LEADING_NOT |
| 1070 |
|
| 1071 |
The ``select`` command searches records that don't contain ``mroonga`` |
| 1072 |
in ``content`` column value from ``Entries`` table. |
| 1073 |
|
| 1074 |
Here are a schema definition and sample data to describe other flags: |
| 1075 |
|
| 1076 |
.. groonga-command |
| 1077 |
.. include:: ../../example/reference/commands/select/query_flags_setup.log |
| 1078 |
.. table_create --name Magazine --flags TABLE_HASH_KEY --key_type ShortText |
| 1079 |
.. column_create --table Magazine --name title --type ShortText |
| 1080 |
.. load --table Magazine |
| 1081 |
.. [ |
| 1082 |
.. {"_key":"http://test.jp/magazine/webplus","title":"WEB+"}, |
| 1083 |
.. {"_key":"http://test.jp/magazine/database","title":"DataBase"}, |
| 1084 |
.. ] |
| 1085 |
|
| 1086 |
Here is an example of ``QUERY_NO_SYNTAX_ERROR``: |
| 1087 |
|
| 1088 |
.. groonga-command |
| 1089 |
.. include:: ../../example/reference/commands/select/query_flags_query_no_syntax_error.log |
| 1090 |
.. select Magazine --match_columns title --query 'WEB +' --query_flags ALLOW_PRAGMA|ALLOW_COLUMN|QUERY_NO_SYNTAX_ERROR |
| 1091 |
|
| 1092 |
If you don't specify this flag, the query causes a syntax error as below. |
| 1093 |
|
| 1094 |
.. groonga-command |
| 1095 |
.. include:: ../../example/reference/commands/select/query_flags_no_query_no_syntax_error.log |
| 1096 |
.. select Magazine --match_columns title --query 'WEB +' --query_flags ALLOW_PRAGMA|ALLOW_COLUMN |
| 1097 |
|
| 1098 |
Here is a usage example of ``NONE``. |
| 1099 |
|
| 1100 |
.. groonga-command |
| 1101 |
.. include:: ../../example/reference/commands/select/query_flags_none.log |
| 1102 |
.. select Entries --match_columns content --query 'mroonga OR _key:Groonga' --query_flags NONE |
| 1103 |
|
| 1104 |
The ``select`` command searches records that contain one of two words |
| 1105 |
``mroonga`` or ``_key:Groonga`` in ``content`` from ``Entries`` table. |
| 1106 |
Note that ``_key:Groonga`` doesn't mean that the value of ``_key`` |
| 1107 |
column is equal to ``Groonga``. Because ``ALLOW_COLUMN`` flag is not |
| 1108 |
specified. |
| 1109 |
|
| 1110 |
See also :doc:`/reference/grn_expr/query_syntax`. |
| 1111 |
|
| 1112 |
.. _select-query-expander: |
| 1113 |
|
| 1114 |
``query_expander`` |
| 1115 |
"""""""""""""""""" |
| 1116 |
|
| 1117 |
It's for query expansion. Query expansion substitutes specific words |
| 1118 |
to another words in query. Normally, it's used for synonym search. |
| 1119 |
|
| 1120 |
It specifies a column that is used to substitute ``query`` parameter |
| 1121 |
value. The format of this parameter value is |
| 1122 |
"``${TABLE}.${COLUMN}``". For example, "``Terms.synonym``" specifies |
| 1123 |
``synonym`` column in ``Terms`` table. |
| 1124 |
|
| 1125 |
Table for query expansion is called "substitution table". Substitution |
| 1126 |
table's key must be ``ShortText``. So array table (``TABLE_NO_KEY``) |
| 1127 |
can't be used for query expansion. Because array table doesn't have |
| 1128 |
key. |
| 1129 |
|
| 1130 |
Column for query expansion is called "substitution |
| 1131 |
column". Substitution column's value type must be |
| 1132 |
``ShortText``. Column type must be vector (``COLUMN_VECTOR``). |
| 1133 |
|
| 1134 |
Query expansion substitutes key of substitution table in query with |
| 1135 |
values in substitution column. If a word in ``query`` is a key of |
| 1136 |
substitution table, the word is substituted with substitution column |
| 1137 |
value that is associated with the key. Substitution isn't performed |
| 1138 |
recursively. It means that substitution target words in substituted |
| 1139 |
query aren't substituted. |
| 1140 |
|
| 1141 |
Here is a sample substitution table to show a simple |
| 1142 |
``query_expander`` usage example. |
| 1143 |
|
| 1144 |
.. groonga-command |
| 1145 |
.. include:: ../../example/reference/commands/select/query_expander_substitution_table.log |
| 1146 |
.. table_create Thesaurus TABLE_PAT_KEY ShortText --normalizer NormalizerAuto |
| 1147 |
.. column_create Thesaurus synonym COLUMN_VECTOR ShortText |
| 1148 |
.. load --table Thesaurus |
| 1149 |
.. [ |
| 1150 |
.. {"_key": "mroonga", "synonym": ["mroonga", "tritonn", "groonga mysql"]}, |
| 1151 |
.. {"_key": "groonga", "synonym": ["groonga", "senna"]} |
| 1152 |
.. ] |
| 1153 |
|
| 1154 |
``Thesaurus`` substitution table has two synonyms, ``"mroonga"`` and |
| 1155 |
``"groonga"``. If an user searches with ``"mroonga"``, Groonga |
| 1156 |
searches with ``"((mroonga) OR (tritonn) OR (groonga mysql))"``. If an |
| 1157 |
user searches with ``"groonga"``, Groonga searches with ``"((groonga) |
| 1158 |
OR (senna))"``. |
| 1159 |
|
| 1160 |
Normally, it's good idea that substitution table uses a |
| 1161 |
normalizer. For example, if normalizer is used, substitute target word |
| 1162 |
is matched in case insensitive manner. See |
| 1163 |
:doc:`/reference/normalizers` for available normalizers. |
| 1164 |
|
| 1165 |
Note that those synonym values include the key value such as |
| 1166 |
``"mroonga"`` and ``"groonga"``. It's recommended that you include the |
| 1167 |
key value. If you don't include key value, substituted value doesn't |
| 1168 |
include the original substitute target value. Normally, including the |
| 1169 |
original value is better search result. If you have a word that you |
| 1170 |
don't want to be searched, you should not include the original |
| 1171 |
word. For example, you can implement "stop words" by an empty vector |
| 1172 |
value. |
| 1173 |
|
| 1174 |
Here is a simple ``query_expander`` usage example. |
| 1175 |
|
| 1176 |
.. groonga-command |
| 1177 |
.. include:: ../../example/reference/commands/select/query_expander_substitute.log |
| 1178 |
.. select Entries --match_columns content --query "mroonga" |
| 1179 |
.. select Entries --match_columns content --query "mroonga" --query_expander Thesaurus.synonym |
| 1180 |
.. select Entries --match_columns content --query "((mroonga) OR (tritonn) OR (groonga mysql))" |
| 1181 |
|
| 1182 |
The first ``select`` command doesn't use query expansion. So a record |
| 1183 |
that has ``"tritonn"`` isn't found. The second ``select`` command uses |
| 1184 |
query expansion. So a record that has ``"tritonn"`` is found. The |
| 1185 |
third ``select`` command doesn't use query expansion but it is same as |
| 1186 |
the second ``select`` command. The third one uses expanded query. |
| 1187 |
|
| 1188 |
Each substitute value can contain any :doc:`/reference/grn_expr/query_syntax` syntax |
| 1189 |
such as ``(...)`` and ``OR``. You can use complex substitution by |
| 1190 |
using those syntax. |
| 1191 |
|
| 1192 |
Here is a complex substitution usage example that uses query syntax. |
| 1193 |
|
| 1194 |
.. groonga-command |
| 1195 |
.. include:: ../../example/reference/commands/select/query_expander_complex.log |
| 1196 |
.. load --table Thesaurus |
| 1197 |
.. [ |
| 1198 |
.. {"_key": "popular", "synonym": ["popular", "n_likes:>=10"]} |
| 1199 |
.. ] |
| 1200 |
.. select Entries --match_columns content --query "popular" --query_expander Thesaurus.synonym |
| 1201 |
|
| 1202 |
The ``load`` command registers a new synonym ``"popular"``. It is |
| 1203 |
substituted with ``((popular) OR (n_likes:>=10))``. The substituted |
| 1204 |
query means that "popular" is containing the word "popular" or 10 or |
| 1205 |
more liked entries. |
| 1206 |
|
| 1207 |
The ``select`` command outputs records that ``n_likes`` column value |
| 1208 |
is equal to or more than ``10`` from ``Entries`` table. |
| 1209 |
|
| 1210 |
.. _select-n-workers: |
| 1211 |
|
| 1212 |
``n_workers`` |
| 1213 |
""""""""""""" |
| 1214 |
|
| 1215 |
.. versionadded:: 12.0.5 |
| 1216 |
|
| 1217 |
.. note:: |
| 1218 |
|
| 1219 |
This is an experimental feature. Currently, this feature is still not stable. |
| 1220 |
|
| 1221 |
This feature requires :doc:`/reference/command/command_version` 3 or later. |
| 1222 |
|
| 1223 |
This feature requires that Apache Arrow is enabled in Groonga. |
| 1224 |
|
| 1225 |
It depends on package provider whether Apache Arrow is enabled or not. |
| 1226 |
|
| 1227 |
To check whether Apache Arrow is enabled, you can use :doc:`/reference/commands/status` command that show the result of ``apache_arrow`` is ``true`` or not. |
| 1228 |
|
| 1229 |
If Apache Arrow is disabled, you should build Groonga from the source code with enabling Apache Arrow following the steps in :doc:`/install` or |
| 1230 |
request to enable Apache Arrow to the package provider. |
| 1231 |
|
| 1232 |
:ref:`select-drilldown` , :ref:`drilldowns <select-advanced-drilldown-related-parameters>` and :ref:`slices <select-slice-related-parameters>` |
| 1233 |
are executed in parallel when this parameter is specified ``-1`` or ``2`` or more. |
| 1234 |
|
| 1235 |
In a default setting, ``drilldown``, ``drilldowns`` and ``slices`` are executed in serial. |
| 1236 |
In other words, a next process is executed after a current process is finished. |
| 1237 |
So, queries tend to take a long time if there are a lot of ``drilldown``, ``drilldowns`` and ``slices``. |
| 1238 |
|
| 1239 |
``n_workers`` enables to execute independent ``drilldown``, ``drilldowns`` and ``slices`` in parallel. |
| 1240 |
The execution time of the total sum of processes can be shourtend by executing them in parallel. |
| 1241 |
This parallel execution is done for each ``select`` command. |
| 1242 |
|
| 1243 |
"independent" means not using ``drilldowns.table`` to reference the results of other drilldowns or slices. |
| 1244 |
|
| 1245 |
If there are dependencies as same meaning as using ``drilldowns.table``, it wait for finish the dependent drilldowns or slices. |
| 1246 |
Therefore, the degree of parallelism is reduced if they have dependencies. |
| 1247 |
|
| 1248 |
Executing in parallel means using multiple CPUs at the same time. |
| 1249 |
If executing in parallel without free CPU resource, it may actually slow down the execution time. |
| 1250 |
This is because they have to wait for the other process being executed by the target CPU to finish. |
| 1251 |
|
| 1252 |
It depends on a system configuration whether or not there are free CPU resources and how many ``n_workers`` should be specified. |
| 1253 |
|
| 1254 |
For example, consider using :doc:`/reference/executables/groonga-server-http` on a system with 6 CPUs. |
| 1255 |
|
| 1256 |
:doc:`/reference/executables/groonga-server-http` allocates 1 thread (= 1CPU) for each request. |
| 1257 |
|
| 1258 |
When the average number of concurrent connections is 6, there are no free CPU resources because 6 CPUs are already in use. |
| 1259 |
All the CPU is used to process each request. |
| 1260 |
|
| 1261 |
When the average number of concurrent connections is 2, there are 4 free CPU resources because only 2 CPUs are already in use. |
| 1262 |
When specifying ``2`` for ``n_workers``, the ``select`` command will use at most 3 CPUs, including the thread for processing requests. |
| 1263 |
Therefore, if two ``select`` commands with ``2`` specified for ``n_workers`` are requested at the same time, |
| 1264 |
they will use at most 6 CPUs in total and will be processed fastly by using all of the resources. |
| 1265 |
When specifying greater than ``2``, the degree of parallelism can be higher than the CPU resources, so it may actually slow down the execution time. |
| 1266 |
|
| 1267 |
``n_workers`` behaves as follows depending on the specified value. |
| 1268 |
|
| 1269 |
* When specifying ``0`` or ``1`` |
| 1270 |
|
| 1271 |
* Executes the `select` command in serial |
| 1272 |
|
| 1273 |
* When specifying ``2`` or more |
| 1274 |
|
| 1275 |
* Executes the `select` command in parallel with at most the specified number of threads. |
| 1276 |
|
| 1277 |
* When specifying ``-1`` or less |
| 1278 |
|
| 1279 |
* Executes the `select` command in parallel with the threads of at most the number of CPU cores. |
| 1280 |
|
| 1281 |
The default value of this parameter is ``0`` . |
| 1282 |
It means that the `select` command is executed in serial in default. |
| 1283 |
|
| 1284 |
.. note:: |
| 1285 |
|
| 1286 |
The default value can be changed by specifying the environment variable ``GRN_SELECT_N_WORKERS_DEFAULT``. |
| 1287 |
|
| 1288 |
Output related parameters |
| 1289 |
^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 1290 |
|
| 1291 |
.. _select-output-columns: |
| 1292 |
|
| 1293 |
``output_columns`` |
| 1294 |
"""""""""""""""""" |
| 1295 |
|
| 1296 |
Specifies output columns separated by ``,``. |
| 1297 |
|
| 1298 |
Here is a simple ``output_columns`` usage example. |
| 1299 |
|
| 1300 |
.. groonga-command |
| 1301 |
.. include:: ../../example/reference/commands/select/output_columns_simple.log |
| 1302 |
.. select Entries --output_columns '_id, _key' --limit 1 |
| 1303 |
|
| 1304 |
The ``select`` command just outputs ``_id`` and ``_key`` column |
| 1305 |
values. |
| 1306 |
|
| 1307 |
``*`` is a special value. It means that all columns that are not |
| 1308 |
:doc:`/reference/columns/pseudo`. |
| 1309 |
|
| 1310 |
Here is a ``*`` usage example. |
| 1311 |
|
| 1312 |
.. groonga-command |
| 1313 |
.. include:: ../../example/reference/commands/select/output_columns_asterisk.log |
| 1314 |
.. select Entries --output_columns '_key, *' --limit 1 |
| 1315 |
|
| 1316 |
The ``select`` command outputs ``_key`` pseudo column, ``content`` |
| 1317 |
column and ``n_likes`` column values but doesn't output ``_id`` pseudo |
| 1318 |
column value. |
| 1319 |
|
| 1320 |
The default value is ``_id, _key, *``. It means that all column |
| 1321 |
values except ``_score`` are outputted. |
| 1322 |
|
| 1323 |
.. _select-sortby: |
| 1324 |
|
| 1325 |
``sortby`` |
| 1326 |
"""""""""" |
| 1327 |
|
| 1328 |
.. deprecated:: 6.0.3 |
| 1329 |
Use :ref:`select-sort-keys` instead. |
| 1330 |
|
| 1331 |
.. _select-sort-keys: |
| 1332 |
|
| 1333 |
``sort_keys`` |
| 1334 |
""""""""""""" |
| 1335 |
|
| 1336 |
Specifies sort keys separated by ``,``. Each sort key is column |
| 1337 |
name. |
| 1338 |
|
| 1339 |
Here is a simple ``sort_keys`` usage example. |
| 1340 |
|
| 1341 |
.. groonga-command |
| 1342 |
.. include:: ../../example/reference/commands/select/sort_keys_simple.log |
| 1343 |
.. select Entries --sort_keys 'n_likes, _id' |
| 1344 |
|
| 1345 |
The ``select`` command sorts by ``n_likes`` column value in ascending |
| 1346 |
order. For records that has the same ``n_likes`` are sorted by ``_id`` |
| 1347 |
in ascending order. ``"Good-bye Senna"`` and ``"Good-bye Tritonn"`` |
| 1348 |
are the case. |
| 1349 |
|
| 1350 |
If you want to sort in descending order, add ``-`` before column name. |
| 1351 |
|
| 1352 |
Here is a descending order ``sort_keys`` usage example. |
| 1353 |
|
| 1354 |
.. groonga-command |
| 1355 |
.. include:: ../../example/reference/commands/select/sort_keys_descending.log |
| 1356 |
.. select Entries --sort_keys '-n_likes, _id' |
| 1357 |
|
| 1358 |
The ``select`` command sorts by ``n_likes`` column value in descending |
| 1359 |
order. But ascending order is used for sorting by ``_id``. |
| 1360 |
|
| 1361 |
You can use ``_score`` pseudo column in ``sort_keys`` if you use |
| 1362 |
``query`` or ``filter`` parameter. |
| 1363 |
|
| 1364 |
.. groonga-command |
| 1365 |
.. include:: ../../example/reference/commands/select/sort_keys_score_with_query.log |
| 1366 |
.. select Entries --match_columns content --query fast --sort_keys -_score --output_columns '_key, _score' |
| 1367 |
|
| 1368 |
The ``select`` command sorts matched records by hit score in |
| 1369 |
descending order and outputs record key and hit score. |
| 1370 |
|
| 1371 |
If you use ``_score`` without ``query`` nor ``filter`` parameters, |
| 1372 |
it's just ignored but get a warning in log file. |
| 1373 |
|
| 1374 |
.. _select-offset: |
| 1375 |
|
| 1376 |
``offset`` |
| 1377 |
"""""""""" |
| 1378 |
|
| 1379 |
Specifies offset to determine output records range. Offset is |
| 1380 |
zero-based. ``--offset 1`` means output range is started from the 2nd |
| 1381 |
record. |
| 1382 |
|
| 1383 |
.. groonga-command |
| 1384 |
.. include:: ../../example/reference/commands/select/offset_simple.log |
| 1385 |
.. select Entries --sort_keys _id --offset 3 --output_columns _key |
| 1386 |
|
| 1387 |
The ``select`` command outputs from the 4th record. |
| 1388 |
|
| 1389 |
You can specify negative value. It means that ``the number of matched |
| 1390 |
records + offset``. If you have 3 matched records and specify |
| 1391 |
``--offset -2``, you get records from the 2nd (``3 + -2 = 1``. ``1`` |
| 1392 |
means 2nd. Remember that offset is zero-based.) record to the 3rd |
| 1393 |
record. |
| 1394 |
|
| 1395 |
.. groonga-command |
| 1396 |
.. include:: ../../example/reference/commands/select/offset_negative.log |
| 1397 |
.. select Entries --sort_keys _id --offset -2 --output_columns _key |
| 1398 |
|
| 1399 |
The ``select`` command outputs from the 4th record because the total |
| 1400 |
number of records is ``5``. |
| 1401 |
|
| 1402 |
The default value is ``0``. |
| 1403 |
|
| 1404 |
.. _select-limit: |
| 1405 |
|
| 1406 |
``limit`` |
| 1407 |
""""""""" |
| 1408 |
|
| 1409 |
Specifies the max number of output records. If the number of |
| 1410 |
matched records is less than ``limit``, all records are outputted. |
| 1411 |
|
| 1412 |
Here is a simple ``limit`` usage example. |
| 1413 |
|
| 1414 |
.. groonga-command |
| 1415 |
.. include:: ../../example/reference/commands/select/limit_simple.log |
| 1416 |
.. select Entries --sort_keys _id --offset 2 --limit 3 --output_columns _key |
| 1417 |
|
| 1418 |
The ``select`` command outputs the 3rd, the 4th and the 5th records. |
| 1419 |
|
| 1420 |
You can specify negative value. It means that ``the number of matched |
| 1421 |
records + limit + 1``. For example, ``--limit -1`` outputs all |
| 1422 |
records. It's very useful value to show all records. |
| 1423 |
|
| 1424 |
Here is a simple negative ``limit`` value usage example. |
| 1425 |
|
| 1426 |
.. groonga-command |
| 1427 |
.. include:: ../../example/reference/commands/select/limit_negative.log |
| 1428 |
.. select Entries --limit -1 |
| 1429 |
|
| 1430 |
The ``select`` command outputs all records. |
| 1431 |
|
| 1432 |
The default value is ``10``. |
| 1433 |
|
| 1434 |
.. _select-scorer: |
| 1435 |
|
| 1436 |
``scorer`` |
| 1437 |
"""""""""" |
| 1438 |
|
| 1439 |
TODO: write in English and add example. |
| 1440 |
|
| 1441 |
検索条件にマッチする全てのレコードに対して適用するgrn_exprをscript形式で指定します。 |
| 1442 |
|
| 1443 |
scorerは、検索処理が完了し、ソート処理が実行される前に呼び出されます。従って、各レコードのスコアを操作する式を指定しておけば、検索結果のソート順序をカスタマイズできるようになります。 |
| 1444 |
|
| 1445 |
.. _select-fuzzy-query-related-parameters: |
| 1446 |
|
| 1447 |
Fuzzy query related parameters |
| 1448 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 1449 |
|
| 1450 |
.. versionadded:: 13.0.8 |
| 1451 |
|
| 1452 |
.. note:: |
| 1453 |
|
| 1454 |
This is an experimental feature. Currently, this feature is still |
| 1455 |
not stable. |
| 1456 |
|
| 1457 |
This section describes fuzzy query related parameters. See also |
| 1458 |
:ref:`select-usage-typo-tolerance` as a use case of fuzzy query. |
| 1459 |
|
| 1460 |
You need to specify at least :ref:`select-fuzzy-max-distance-ratio` or |
| 1461 |
:ref:`select-fuzzy-max-distance` to use fuzzy query. |
| 1462 |
|
| 1463 |
Fuzzy query is executed automatically when no record is matched with |
| 1464 |
the original query. It means that fuzzy query is implemented as one of |
| 1465 |
match escalation methods. See also |
| 1466 |
:ref:`select-match-escalation-threshold` for match escalation. |
| 1467 |
|
| 1468 |
.. _select-fuzzy-max-distance-ratio: |
| 1469 |
|
| 1470 |
``fuzzy_max_distance_ratio`` |
| 1471 |
"""""""""""""""""""""""""""" |
| 1472 |
|
| 1473 |
.. versionadded:: 13.0.8 |
| 1474 |
|
| 1475 |
.. note:: |
| 1476 |
|
| 1477 |
This is an experimental feature. Currently, this feature is still |
| 1478 |
not stable. |
| 1479 |
|
| 1480 |
The default value is ``0``. |
| 1481 |
|
| 1482 |
You need to specify :ref:`select-fuzzy-max-distance-ratio` or |
| 1483 |
:ref:`select-fuzzy-max-distance` to enable fuzzy query. If you specify |
| 1484 |
both of them, :ref:`select-fuzzy-max-distance-ratio` is used. |
| 1485 |
|
| 1486 |
You can specify how long edit distance is accepted based on the target |
| 1487 |
query. For most use cases, this parameter is more suitable than |
| 1488 |
:ref:`select-fuzzy-max-distance`. |
| 1489 |
|
| 1490 |
In general, long edit distance for short query isn't suitable. Because |
| 1491 |
it will increase noisy results. For example, ``hye`` with edit |
| 1492 |
distance ``3`` accepts the following terms: |
| 1493 |
|
| 1494 |
* ``hey`` (preferable result) |
| 1495 |
* ``eye`` (preferable result) |
| 1496 |
* ``bye`` (preferable result) |
| 1497 |
* ``hyper`` (preferable result?) |
| 1498 |
* ``hyphen`` (preferable result?) |
| 1499 |
|
| 1500 |
:ref:`select-fuzzy-max-distance` specifies a fixed size edit distance |
| 1501 |
for all queries (both of short queries and long queries). |
| 1502 |
|
| 1503 |
You can specify an edit distance for each query based on the number of |
| 1504 |
characters of the target query by this parameter. For example, edit |
| 1505 |
distance ``1`` is used for ``hye`` with ``--fuzzy_max_distance_ratio |
| 1506 |
0.34``. Edit distance ``2`` is used for ``hypehn`` with |
| 1507 |
``--fuzzy_max_distance_ratio 0.34``. It's calculated by |
| 1508 |
``floor(${THE_NUMBER_OF_CHARACTERS} * ${FUZZY_MAX_DISTANCE_RATIO})``: |
| 1509 |
|
| 1510 |
* ``hye``: ``floor(3 * 0.34) = floor(1.02) = 1`` |
| 1511 |
* ``hypehn``: ``floor(6 * 0.34) = floor(2.04) = 2`` |
| 1512 |
|
| 1513 |
In general, ``--fuzzy_max_distance_ratio 0.34`` is a good value. If |
| 1514 |
the value doesn't fix your use case, you can change the value. |
| 1515 |
|
| 1516 |
Here is a table that shows how many characters are accepted as typo |
| 1517 |
with ``--fuzzy_max_distance_ratio 0.34``: |
| 1518 |
|
| 1519 |
.. list-table:: |
| 1520 |
:header-rows: 1 |
| 1521 |
|
| 1522 |
* - The number of characters of a term |
| 1523 |
- The number of accepted typo characters |
| 1524 |
* - 1 |
| 1525 |
- 0 (``floor(1 * 0.34) = floor(0.34) = 0``) |
| 1526 |
* - 2 |
| 1527 |
- 0 (``floor(2 * 0.34) = floor(0.68) = 0``) |
| 1528 |
* - 3 |
| 1529 |
- 1 (``floor(3 * 0.34) = floor(1.02) = 1``) |
| 1530 |
* - 4 |
| 1531 |
- 1 (``floor(4 * 0.34) = floor(1.36) = 1``) |
| 1532 |
* - 5 |
| 1533 |
- 1 (``floor(5 * 0.34) = floor(1.7) = 1``) |
| 1534 |
* - 6 |
| 1535 |
- 2 (``floor(6 * 0.34) = floor(2.04) = 2``) |
| 1536 |
|
| 1537 |
Here is an example that accepts 1 typo character for ``vary`` and 2 |
| 1538 |
typo characters for ``Gnoonag``. This example specifies ``yes`` as |
| 1539 |
:ref:`select-match-escalation` to enable fuzzy query for all queries |
| 1540 |
(``vary`` and ``Gnoonag``). In general, you should not specify |
| 1541 |
``--match_escalation yes`` because it may increase noisy results. |
| 1542 |
|
| 1543 |
.. groonga-command |
| 1544 |
.. include:: ../../example/reference/commands/select/fuzzy_max_distance_ratio.log |
| 1545 |
.. select \ |
| 1546 |
.. --table Entries \ |
| 1547 |
.. --fuzzy_max_distance_ratio 0.34 \ |
| 1548 |
.. --match_columns content \ |
| 1549 |
.. --query 'vary Gnoonag' \ |
| 1550 |
.. --match_escalation yes \ |
| 1551 |
.. --output_columns content,_score |
| 1552 |
|
| 1553 |
.. _select-fuzzy-max-distance: |
| 1554 |
|
| 1555 |
``fuzzy_max_distance`` |
| 1556 |
"""""""""""""""""""""" |
| 1557 |
|
| 1558 |
.. versionadded:: 13.0.8 |
| 1559 |
|
| 1560 |
.. note:: |
| 1561 |
|
| 1562 |
This is an experimental feature. Currently, this feature is still |
| 1563 |
not stable. |
| 1564 |
|
| 1565 |
The default value is ``0``. |
| 1566 |
|
| 1567 |
You need to specify :ref:`select-fuzzy-max-distance-ratio` or |
| 1568 |
:ref:`select-fuzzy-max-distance` to enable fuzzy query. If you specify |
| 1569 |
both of them, :ref:`select-fuzzy-max-distance-ratio` is used. |
| 1570 |
|
| 1571 |
You can specify a fixed edit distance to be accepted by this |
| 1572 |
parameter. For most use cases, :ref:`select-fuzzy-max-distance` is |
| 1573 |
more suitable than this parameter. |
| 1574 |
|
| 1575 |
Here is an example that accepts 1 typo character for ``vary``: |
| 1576 |
|
| 1577 |
.. groonga-command |
| 1578 |
.. include:: ../../example/reference/commands/select/fuzzy_max_distance.log |
| 1579 |
.. select \ |
| 1580 |
.. --table Entries \ |
| 1581 |
.. --fuzzy_max_distance 1 \ |
| 1582 |
.. --match_columns content \ |
| 1583 |
.. --query vary \ |
| 1584 |
.. --output_columns content,_score |
| 1585 |
|
| 1586 |
.. _select-fuzzy-max-expansions: |
| 1587 |
|
| 1588 |
``fuzzy_max_expansions`` |
| 1589 |
"""""""""""""""""""""""" |
| 1590 |
|
| 1591 |
.. versionadded:: 13.0.8 |
| 1592 |
|
| 1593 |
.. note:: |
| 1594 |
|
| 1595 |
This is an experimental feature. Currently, this feature is still |
| 1596 |
not stable. |
| 1597 |
|
| 1598 |
The default value is ``10``. |
| 1599 |
|
| 1600 |
You can specify the max number of terms as fixed terms. If ``hye`` is |
| 1601 |
the given query, this parameter is ``2`` and ``hey``, ``eye`` and |
| 1602 |
``hyper`` are candidates of fixed terms, ``hey`` and ``eye`` (2 terms) |
| 1603 |
are only used as fixed terms. |
| 1604 |
|
| 1605 |
Here is an example that uses 1 fixed terms for ``alx``. ``all`` is |
| 1606 |
only used. ``also`` isn't used. |
| 1607 |
|
| 1608 |
.. groonga-command |
| 1609 |
.. include:: ../../example/reference/commands/select/fuzzy_max_expansions.log |
| 1610 |
.. select \ |
| 1611 |
.. --table Entries \ |
| 1612 |
.. --fuzzy_max_distance 2 \ |
| 1613 |
.. --fuzzy_max_expansions 1 \ |
| 1614 |
.. --match_columns content \ |
| 1615 |
.. --query alx \ |
| 1616 |
.. --output_columns content,_score |
| 1617 |
|
| 1618 |
.. _select-fuzzy-prefix-length: |
| 1619 |
|
| 1620 |
``fuzzy_prefix_length`` |
| 1621 |
""""""""""""""""""""""" |
| 1622 |
|
| 1623 |
.. versionadded:: 13.0.8 |
| 1624 |
|
| 1625 |
.. note:: |
| 1626 |
|
| 1627 |
This is an experimental feature. Currently, this feature is still |
| 1628 |
not stable. |
| 1629 |
|
| 1630 |
The default value is ``0``. |
| 1631 |
|
| 1632 |
You can specify the number of prefix characters. If this value is |
| 1633 |
``1`` and the given term is ``hye``, the prefix is ``h``. Fixed terms |
| 1634 |
must be started with ``h``. For example, ``hey`` can be used as a |
| 1635 |
fixed term but ``eye`` and ``bye`` can't be used as a fixed terms. |
| 1636 |
|
| 1637 |
This option will improve performance when a lexicon has many terms. |
| 1638 |
|
| 1639 |
Here is an example that requires ``gr`` prefix for fixed terms with |
| 1640 |
``groonag`` query. ``Groonga`` (case insensitive for this case because |
| 1641 |
you use :doc:`/reference/normalizers/normalizer_auto` for this case) |
| 1642 |
can be used for a fixed term but ``Mroonga`` can't be used for a fixed |
| 1643 |
term. Because ``Mroonga`` isn't started with ``gr``. |
| 1644 |
|
| 1645 |
.. groonga-command |
| 1646 |
.. include:: ../../example/reference/commands/select/fuzzy_prefix_length.log |
| 1647 |
.. select \ |
| 1648 |
.. --table Entries \ |
| 1649 |
.. --fuzzy_max_distance 2 \ |
| 1650 |
.. --fuzzy_prefix_length 2 \ |
| 1651 |
.. --match_columns content \ |
| 1652 |
.. --query groonag \ |
| 1653 |
.. --output_columns content,_score |
| 1654 |
|
| 1655 |
.. _select-fuzzy-with-transposition: |
| 1656 |
|
| 1657 |
``fuzzy_with_transposition`` |
| 1658 |
"""""""""""""""""""""""""""" |
| 1659 |
|
| 1660 |
.. versionadded:: 13.0.9 |
| 1661 |
|
| 1662 |
.. note:: |
| 1663 |
|
| 1664 |
This is an experimental feature. Currently, this feature is still |
| 1665 |
not stable. |
| 1666 |
|
| 1667 |
The default value is ``yes``. |
| 1668 |
|
| 1669 |
You can choose edit distance ``1`` or ``2`` for the transposition |
| 1670 |
case. An example of the transposition case is ``hello`` and ``ehllo``. |
| 1671 |
``h`` and ``e`` is transposed. If this parameter is ``yes``, the edit |
| 1672 |
distance of this case is ``1``. It's ``2`` (because insertion and |
| 1673 |
deletion are needed) otherwise. |
| 1674 |
|
| 1675 |
Here is an example that uses edit distance ``2`` for transposition. In |
| 1676 |
this example, you can't use ``Mroonga`` as a fixed term for ``groonag`` |
| 1677 |
because it has edit distance ``3``: |
| 1678 |
|
| 1679 |
1. Substitute ``g`` with ``M``: ``groonag`` -> ``Mroonag`` |
| 1680 |
2. Add ``a``: ``Mroonag`` -> ``Mroonaga`` |
| 1681 |
3. Remove ``a``: ``Mroonaga`` -> ``Mroonga`` |
| 1682 |
|
| 1683 |
.. groonga-command |
| 1684 |
.. include:: ../../example/reference/commands/select/fuzzy_with_transposition.log |
| 1685 |
.. select \ |
| 1686 |
.. --table Entries \ |
| 1687 |
.. --fuzzy_max_distance 2 \ |
| 1688 |
.. --fuzzy_with_transposition no \ |
| 1689 |
.. --match_columns content \ |
| 1690 |
.. --query groonag \ |
| 1691 |
.. --output_columns content,_score |
| 1692 |
|
| 1693 |
.. _select-fuzzy-tokenize: |
| 1694 |
|
| 1695 |
``fuzzy_with_tokenize`` |
| 1696 |
""""""""""""""""""""""" |
| 1697 |
|
| 1698 |
.. versionadded:: 13.0.9 |
| 1699 |
|
| 1700 |
.. note:: |
| 1701 |
|
| 1702 |
This is an experimental feature. Currently, this feature is still |
| 1703 |
not stable. |
| 1704 |
|
| 1705 |
The default value is ``no``. |
| 1706 |
|
| 1707 |
You can choose whether tokenize the given term or not before fuzzy |
| 1708 |
query. If tokenizer is :doc:`/reference/tokenizers/token_ngram` and |
| 1709 |
the given term is ``he11o``, it's tokenized to ``he``, ``11`` and |
| 1710 |
``o``. If this value is ``yes``, fixed terms are searched for each of |
| 1711 |
them. For example, ``hi`` is found as a fixed term of ``he``, ``12`` |
| 1712 |
is found as a fixed term of ``11`` and ``x`` is found as a fixed term |
| 1713 |
of ``o``. And ``hi12x`` is searched. If this value is ``no``, fixed |
| 1714 |
terms are searched for ``he11o``. For example, ``hello`` is found as a |
| 1715 |
fixed term of ``he11o`` and ``hello`` is searched. |
| 1716 |
|
| 1717 |
Note that each term is separated by ore or more space characters |
| 1718 |
before fuzzy query is executed. For example, ``hello world`` are |
| 1719 |
separated to ``hello`` and ``world`` by query parser. (See also |
| 1720 |
:doc:`/reference/grn_expr/query_syntax`.) ``hello`` and ``world`` are |
| 1721 |
processed separately. |
| 1722 |
|
| 1723 |
For morphological analyzer based tokenizer such as |
| 1724 |
:doc:`/reference/tokenizers/token_mecab`, ``no`` is suitable. Because |
| 1725 |
typo-ed term isn't tokenized as you expected for most cases. For |
| 1726 |
example, ``ともて`` (a typo of ``とても``) may be tokenized to ``とも |
| 1727 |
`` (adjective) and ``て`` (conjunctive particle) not ``ともて`` |
| 1728 |
(adverb). |
| 1729 |
|
| 1730 |
Here is an example that tokenizes the given term before fuzzy |
| 1731 |
query. In this example, you can't use ``Groonga`` as a fixed term for |
| 1732 |
``gr00nga`` because ``gr``, ``00`` and ``nga`` are processed separately. |
| 1733 |
|
| 1734 |
.. groonga-command |
| 1735 |
.. include:: ../../example/reference/commands/select/fuzzy_tokenize.log |
| 1736 |
.. select \ |
| 1737 |
.. --table Entries \ |
| 1738 |
.. --fuzzy_max_distance 2 \ |
| 1739 |
.. --fuzzy_tokenize yes \ |
| 1740 |
.. --match_columns content \ |
| 1741 |
.. --query gr00nga \ |
| 1742 |
.. --output_columns content,_score |
| 1743 |
|
| 1744 |
.. _select-dynamic-column-related-parameters: |
| 1745 |
|
| 1746 |
Dynamic column related parameters |
| 1747 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 1748 |
|
| 1749 |
.. versionadded:: 6.0.6 |
| 1750 |
|
| 1751 |
This section describes dynamic column related parameters. You can use |
| 1752 |
dynamic column for window function but this section doesn't describe |
| 1753 |
window function. See :ref:`select-window-function-related-parameters` |
| 1754 |
for window function. |
| 1755 |
|
| 1756 |
You can create zero or more columns and fill values into these columns |
| 1757 |
while a ``select`` execution. These columns are called as "dynamic |
| 1758 |
columns". You can use dynamic columns as same as normal columns after |
| 1759 |
dynamic columns are created. |
| 1760 |
|
| 1761 |
Dynamic column has performance merit because its values are computed |
| 1762 |
at once and reused computed values. |
| 1763 |
|
| 1764 |
Dynamic column increases memory usage because its values are kept |
| 1765 |
while the ``select`` execution. |
| 1766 |
|
| 1767 |
You need to use dynamic column in the following cases: |
| 1768 |
|
| 1769 |
* You want to name values like ``AS`` in SQL. |
| 1770 |
|
| 1771 |
* You want to use computed values for drilldown. Groonga doesn't |
| 1772 |
support drilldown target value computation in drilldown. |
| 1773 |
|
| 1774 |
* You want to use window function. |
| 1775 |
|
| 1776 |
There are some points to create dynamic columns. You must specify |
| 1777 |
``stage`` to each dynamic column to control dynamic columns creation |
| 1778 |
points. It's important that you choose proper point to get better |
| 1779 |
performance. |
| 1780 |
|
| 1781 |
For example, it's not a good idea that you create a dynamic column |
| 1782 |
that is only used for output for all records. The number of output |
| 1783 |
records will be a little even if there are many records in a |
| 1784 |
table. Because you will filter, sort and limit all records and output |
| 1785 |
only the limited records in many cases. |
| 1786 |
|
| 1787 |
See :ref:`select-columns-name-stage` for ``stage`` detail. |
| 1788 |
|
| 1789 |
Here are parameters for dynamic column. They don't include window |
| 1790 |
function related parameters. See |
| 1791 |
:ref:`select-window-function-related-parameters` for window function |
| 1792 |
related parameters: |
| 1793 |
|
| 1794 |
.. list-table:: |
| 1795 |
:header-rows: 1 |
| 1796 |
|
| 1797 |
* - Name |
| 1798 |
- Default value |
| 1799 |
- Required or optional |
| 1800 |
* - ``columns[${NAME}].stage`` |
| 1801 |
- ``null`` |
| 1802 |
- Required |
| 1803 |
* - ``columns[${NAME}].flags`` |
| 1804 |
- ``COLUMN_SCALAR`` |
| 1805 |
- Optional |
| 1806 |
* - ``columns[${NAME}].type`` |
| 1807 |
- ``null`` |
| 1808 |
- Required |
| 1809 |
* - ``columns[${NAME}].value`` |
| 1810 |
- ``null`` |
| 1811 |
- Required |
| 1812 |
|
| 1813 |
You need to specify multiple parameters for a dynamic |
| 1814 |
column. ``${NAME}`` is the name for each dynamic column. Parameters |
| 1815 |
that use the same ``${NAME}`` are treated as parameters for the same |
| 1816 |
dynamic column. Here is an example to specify parameters for 2 dynamic |
| 1817 |
columns (``name1`` and ``name2``):: |
| 1818 |
|
| 1819 |
--columns[name1].stage initial |
| 1820 |
--columns[name1].type UInt32 |
| 1821 |
--columns[name1].value 29 |
| 1822 |
|
| 1823 |
--columns[name2].stage filtered |
| 1824 |
--columns[name2].type ShortText |
| 1825 |
--columns[name2].value "29" |
| 1826 |
|
| 1827 |
.. _select-columns-name-stage: |
| 1828 |
|
| 1829 |
``columns[${NAME}].stage`` |
| 1830 |
"""""""""""""""""""""""""" |
| 1831 |
|
| 1832 |
.. versionadded:: 6.0.6 |
| 1833 |
|
| 1834 |
Specifies when the dynamic column is created. This is a required |
| 1835 |
parameter to create a dynamic column. |
| 1836 |
|
| 1837 |
Here are available stages: |
| 1838 |
|
| 1839 |
.. list-table:: |
| 1840 |
:header-rows: 1 |
| 1841 |
|
| 1842 |
* - Name |
| 1843 |
- Description |
| 1844 |
* - ``initial`` |
| 1845 |
- Dynamic column is created at first. |
| 1846 |
* - ``result_set`` |
| 1847 |
- Dynamic column is created before ``filtered`` stage. |
| 1848 |
|
| 1849 |
Can't use :ref:`select-columns-name-value` for this stage. |
| 1850 |
This stage does not initialize the column value. |
| 1851 |
Therefore, if you need to initialize it, please use the ``initial`` stage. |
| 1852 |
|
| 1853 |
This stage is for storing values by ``score_column``. |
| 1854 |
* - ``filtered`` |
| 1855 |
- Dynamic column is created after :ref:`select-query` and |
| 1856 |
:ref:`select-filter` are evaluated. |
| 1857 |
* - ``output`` |
| 1858 |
- Dynamic column is created before :ref:`select-output-columns` |
| 1859 |
is evaluated. |
| 1860 |
|
| 1861 |
Here is the ``select`` process flow with dynamic column creation |
| 1862 |
points. You should choose stage as late as possible: |
| 1863 |
|
| 1864 |
#. Creates dynamic columns for ``initial`` stage. All records have |
| 1865 |
these dynamic columns. |
| 1866 |
|
| 1867 |
#. Creates dynamic columns for ``result_set`` stage. All records have |
| 1868 |
these dynamic columns. The difference between ``initial`` stage and ``result_set`` stage is whether it is initialized or not. |
| 1869 |
|
| 1870 |
#. Evaluates :ref:`select-query` and :ref:`select-filter`. You can |
| 1871 |
use dynamic columns created in ``initial`` and ``result_set`` stage. |
| 1872 |
|
| 1873 |
#. Creates dynamic columns for ``filtered`` stage. Only filtered |
| 1874 |
records have these dynamic columns. |
| 1875 |
|
| 1876 |
#. Evaluates :ref:`select-adjuster`. You can use dynamic columns |
| 1877 |
created in ``initial`` stage and ``filtered`` stage. |
| 1878 |
|
| 1879 |
#. Evaluates :ref:`select-scorer`. You can use dynamic columns |
| 1880 |
created in ``initial`` stage and ``filtered`` stage. |
| 1881 |
|
| 1882 |
#. Evaluates :ref:`select-sort-keys`, :ref:`select-offset` and |
| 1883 |
:ref:`select-limit`. You can use dynamic columns created in |
| 1884 |
``initial`` stage and ``filtered`` stage. |
| 1885 |
|
| 1886 |
#. Evaluates :ref:`select-slice-related-parameters`. You can use |
| 1887 |
dynamic columns created in ``initial`` stage and ``filtered`` stage. |
| 1888 |
|
| 1889 |
#. Evaluates :ref:`select-drilldown-related-parameters` and |
| 1890 |
:ref:`select-advanced-drilldown-related-parameters`. You can use |
| 1891 |
dynamic columns created in ``initial`` stage and ``filtered`` stage. |
| 1892 |
Note that you can create dynamic columns in each drilldown. |
| 1893 |
|
| 1894 |
#. Creates dynamic columns for ``output`` stage. Only |
| 1895 |
:ref:`select-limit` records have these dynamic columns. |
| 1896 |
|
| 1897 |
#. Evaluates :ref:`select-output-columns`. You can use dynamic |
| 1898 |
columns created in ``initial`` stage, ``filtered`` stage and |
| 1899 |
``output`` stage. |
| 1900 |
|
| 1901 |
Here is an example that creates ``is_popular`` column at ``initial`` |
| 1902 |
stage. You can use ``is_popular`` in all parameters such as ``filter`` |
| 1903 |
and ``output_columns``: |
| 1904 |
|
| 1905 |
.. groonga-command |
| 1906 |
.. include:: ../../example/reference/commands/select/columns_name_stage.log |
| 1907 |
.. select Entries \ |
| 1908 |
.. --columns[is_popular].stage initial \ |
| 1909 |
.. --columns[is_popular].type Bool \ |
| 1910 |
.. --columns[is_popular].value 'n_likes >= 10' \ |
| 1911 |
.. --filter is_popular \ |
| 1912 |
.. --output_columns _id,is_popular,n_likes |
| 1913 |
|
| 1914 |
.. _select-columns-name-flags: |
| 1915 |
|
| 1916 |
``columns[${NAME}].flags`` |
| 1917 |
"""""""""""""""""""""""""" |
| 1918 |
|
| 1919 |
.. versionadded:: 6.0.6 |
| 1920 |
|
| 1921 |
Specifies flags for the dynamic column. It's the same as ``flags`` |
| 1922 |
parameter for :doc:`column_create`. See :ref:`column-create-flags` for |
| 1923 |
available flags. |
| 1924 |
|
| 1925 |
The default value is ``COLUMN_SCALAR``. |
| 1926 |
|
| 1927 |
Here is a ``columns[${NAME}].flags`` example. It creates a vector |
| 1928 |
column by ``COLUMN_VECTOR`` flags. ``plugin_register |
| 1929 |
functions/vector`` is for using :doc:`/reference/functions/vector_new` |
| 1930 |
function: |
| 1931 |
|
| 1932 |
.. groonga-command |
| 1933 |
.. include:: ../../example/reference/commands/select/columns_name_flags.log |
| 1934 |
.. plugin_register functions/vector |
| 1935 |
.. select Entries \ |
| 1936 |
.. --columns[vector].stage initial \ |
| 1937 |
.. --columns[vector].flags COLUMN_VECTOR \ |
| 1938 |
.. --columns[vector].type UInt32 \ |
| 1939 |
.. --columns[vector].value 'vector_new(1, 2, 3)' \ |
| 1940 |
.. --output_columns _id,vector |
| 1941 |
|
| 1942 |
.. _select-columns-name-type: |
| 1943 |
|
| 1944 |
``columns[${NAME}].type`` |
| 1945 |
""""""""""""""""""""""""" |
| 1946 |
|
| 1947 |
.. versionadded:: 6.0.6 |
| 1948 |
|
| 1949 |
Specifies value type for the dynamic column. It's the same as ``type`` |
| 1950 |
parameter for :doc:`column_create`. See :ref:`column-create-type` for |
| 1951 |
available types. |
| 1952 |
|
| 1953 |
This is a required parameter. |
| 1954 |
|
| 1955 |
Here is an example that creates a ``ShortText`` type column. Stored |
| 1956 |
value is casted to ``ShortText`` automatically. In this example, |
| 1957 |
number is casted to ``ShortText``: |
| 1958 |
|
| 1959 |
.. groonga-command |
| 1960 |
.. include:: ../../example/reference/commands/select/columns_name_type.log |
| 1961 |
.. select Entries \ |
| 1962 |
.. --columns[n_likes_string].stage initial \ |
| 1963 |
.. --columns[n_likes_string].type ShortText \ |
| 1964 |
.. --columns[n_likes_string].value n_likes \ |
| 1965 |
.. --output_columns _id,n_likes,n_likes_string |
| 1966 |
|
| 1967 |
.. _select-columns-name-value: |
| 1968 |
|
| 1969 |
``columns[${NAME}].value`` |
| 1970 |
"""""""""""""""""""""""""" |
| 1971 |
|
| 1972 |
.. versionadded:: 6.0.6 |
| 1973 |
|
| 1974 |
Specifies expression that generates values for the dynamic column. The |
| 1975 |
expression uses :doc:`/reference/grn_expr/script_syntax`. It's the |
| 1976 |
same syntax in :ref:`select-filter`. For example, ``1 + 1``, |
| 1977 |
``string_length("Hello")``, ``column * 1.08`` and so on are valid |
| 1978 |
expressions. |
| 1979 |
|
| 1980 |
You need to specify :doc:`/reference/window_function` as ``value`` |
| 1981 |
value and other window function related parameters when you use window |
| 1982 |
function. See :ref:`select-window-function-related-parameters` for |
| 1983 |
details. |
| 1984 |
|
| 1985 |
This is a required parameter. |
| 1986 |
|
| 1987 |
Here is an example that creates a new dynamic column that stores the |
| 1988 |
number of characters of content. This example uses |
| 1989 |
:doc:`/reference/functions/string_length` function in |
| 1990 |
``functions/string`` plugin to compute the number of characters in a |
| 1991 |
string. :doc:`plugin_register` is used to register |
| 1992 |
``functions/string`` plugin: |
| 1993 |
|
| 1994 |
.. groonga-command |
| 1995 |
.. include:: ../../example/reference/commands/select/columns_name_value.log |
| 1996 |
.. plugin_register functions/string |
| 1997 |
.. select Entries \ |
| 1998 |
.. --columns[content_length].stage initial \ |
| 1999 |
.. --columns[content_length].type UInt32 \ |
| 2000 |
.. --columns[content_length].value 'string_length(content)' \ |
| 2001 |
.. --output_columns _id,content,content_length |
| 2002 |
|
| 2003 |
.. _select-window-function-related-parameters: |
| 2004 |
|
| 2005 |
Window function related parameters |
| 2006 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 2007 |
|
| 2008 |
.. versionadded:: 6.0.6 |
| 2009 |
|
| 2010 |
This section describes window function related parameters. You need to |
| 2011 |
use dynamic column for using window function. See |
| 2012 |
:ref:`select-dynamic-column-related-parameters` for dynamic column. |
| 2013 |
|
| 2014 |
Window function in Groonga is similar to window function in |
| 2015 |
SQL. Normal function computes its result with only the current |
| 2016 |
record. On the other hand, window function computes its result with |
| 2017 |
multiple records. Window function is useful to data analysis because |
| 2018 |
it can process multiple records. |
| 2019 |
|
| 2020 |
You can find supported window functions at |
| 2021 |
:doc:`/reference/window_function`. For example, |
| 2022 |
:doc:`/reference/window_functions/window_sum` is a window function. It |
| 2023 |
sums numbers in the target records. |
| 2024 |
|
| 2025 |
Window function processes records that are grouped by the specified |
| 2026 |
group keys. For example, window function processes three groups |
| 2027 |
(``Hello`` group, ``Groonga`` group and ``Senna`` group) in the |
| 2028 |
following case. :doc:`/reference/window_functions/window_sum` sums |
| 2029 |
``n_likes`` values in each group: |
| 2030 |
|
| 2031 |
.. list-table:: |
| 2032 |
:header-rows: 1 |
| 2033 |
|
| 2034 |
* - Group No. |
| 2035 |
- Group key value |
| 2036 |
- ``n_likes`` value |
| 2037 |
- :doc:`/reference/window_functions/window_sum` result |
| 2038 |
* - 1 |
| 2039 |
- ``Hello`` |
| 2040 |
- 5 |
| 2041 |
- 5 |
| 2042 |
* - 2 |
| 2043 |
- ``Groonga`` |
| 2044 |
- 10 |
| 2045 |
- 25 |
| 2046 |
* - 2 |
| 2047 |
- ``Groonga`` |
| 2048 |
- 15 |
| 2049 |
- 25 |
| 2050 |
* - 3 |
| 2051 |
- ``Senna`` |
| 2052 |
- 3 |
| 2053 |
- 6 |
| 2054 |
* - 3 |
| 2055 |
- ``Senna`` |
| 2056 |
- 3 |
| 2057 |
- 6 |
| 2058 |
|
| 2059 |
You can specify no group keys. In the case, window function processes |
| 2060 |
only one group that includes all |
| 2061 |
records. :doc:`/reference/window_functions/window_sum` sums all |
| 2062 |
``n_likes`` values in the following case: |
| 2063 |
|
| 2064 |
.. list-table:: |
| 2065 |
:header-rows: 1 |
| 2066 |
|
| 2067 |
* - Group No. |
| 2068 |
- ``n_likes`` value |
| 2069 |
- :doc:`/reference/window_functions/window_sum` result |
| 2070 |
* - 1 |
| 2071 |
- 5 |
| 2072 |
- 36 |
| 2073 |
* - 1 |
| 2074 |
- 10 |
| 2075 |
- 36 |
| 2076 |
* - 1 |
| 2077 |
- 15 |
| 2078 |
- 36 |
| 2079 |
* - 1 |
| 2080 |
- 3 |
| 2081 |
- 36 |
| 2082 |
* - 1 |
| 2083 |
- 3 |
| 2084 |
- 36 |
| 2085 |
|
| 2086 |
Window function processes records in each group in the specified |
| 2087 |
order. You can specify no sort keys like the above group keys |
| 2088 |
example. |
| 2089 |
|
| 2090 |
The behavior when you specify no sort keys depends on each window |
| 2091 |
function specification. For example, |
| 2092 |
:doc:`/reference/window_functions/window_sum` uses different behavior |
| 2093 |
whether sort keys are specified or not. If you specify not sort keys, |
| 2094 |
:doc:`/reference/window_functions/window_sum` sums values of all |
| 2095 |
records in the group and puts it to all target records like the above |
| 2096 |
group keys example. If you specify sort keys, |
| 2097 |
:doc:`/reference/window_functions/window_sum` behaves as cumulative |
| 2098 |
sum. :doc:`/reference/window_functions/window_sum` sums values of all |
| 2099 |
records in the group in sequence and puts the current sum to the |
| 2100 |
current record like the following: |
| 2101 |
|
| 2102 |
.. list-table:: |
| 2103 |
:header-rows: 1 |
| 2104 |
|
| 2105 |
* - Group No. |
| 2106 |
- Group key value |
| 2107 |
- Sort key value |
| 2108 |
- ``n_likes`` value |
| 2109 |
- :doc:`/reference/window_functions/window_sum` result |
| 2110 |
- Note |
| 2111 |
* - 1 |
| 2112 |
- ``Hello`` |
| 2113 |
- 1 |
| 2114 |
- 5 |
| 2115 |
- 5 |
| 2116 |
- The first record in group No. 1. (``5 = 5``) |
| 2117 |
* - 2 |
| 2118 |
- ``Groonga`` |
| 2119 |
- 90 |
| 2120 |
- 10 |
| 2121 |
- 10 |
| 2122 |
- The first record in group No. 2. (``10 = 10``) |
| 2123 |
* - 2 |
| 2124 |
- ``Groonga`` |
| 2125 |
- 91 |
| 2126 |
- 15 |
| 2127 |
- 25 |
| 2128 |
- The second record in group No. 2. (``10 + 15 = 25``) |
| 2129 |
* - 3 |
| 2130 |
- ``Senna`` |
| 2131 |
- 200 |
| 2132 |
- 3 |
| 2133 |
- 8 |
| 2134 |
- The second record in group No. 3. (``5 + 3 = 8``) |
| 2135 |
* - 3 |
| 2136 |
- ``Senna`` |
| 2137 |
- 100 |
| 2138 |
- 5 |
| 2139 |
- 5 |
| 2140 |
- The first record in group No. 3. (``5 = 5``) |
| 2141 |
|
| 2142 |
Here are parameters for window function. You need to specify both |
| 2143 |
window function related parameters and required dynamic columns |
| 2144 |
parameters. Because window function is implemented based on dynamic |
| 2145 |
column. See :ref:`select-dynamic-column-related-parameters` for |
| 2146 |
dynamic column related parameters: |
| 2147 |
|
| 2148 |
.. list-table:: |
| 2149 |
:header-rows: 1 |
| 2150 |
|
| 2151 |
* - Name |
| 2152 |
- Required or optional |
| 2153 |
- Note |
| 2154 |
* - ``columns[${NAME}].value`` |
| 2155 |
- Required |
| 2156 |
- Use :doc:`/reference/window_function`. |
| 2157 |
* - ``columns[${NAME}].window.sort_keys`` |
| 2158 |
- Required if ``columns[${NAME}].window.group_keys`` isn't specified. |
| 2159 |
- |
| 2160 |
* - ``columns[${NAME}].window.group_keys`` |
| 2161 |
- Required if ``columns[${NAME}].window.sort_keys`` isn't specified. |
| 2162 |
- |
| 2163 |
|
| 2164 |
.. _select-columns-name-window-sort-keys: |
| 2165 |
|
| 2166 |
``columns[${NAME}].window.sort_keys`` |
| 2167 |
""""""""""""""""""""""""""""""""""""" |
| 2168 |
|
| 2169 |
.. versionadded:: 6.0.6 |
| 2170 |
|
| 2171 |
Specifies sort keys in each group. Window function processes records |
| 2172 |
in each group in the specified order. |
| 2173 |
|
| 2174 |
Sort keys are separated by ``,``. Each sort key is column name. It's |
| 2175 |
the same as :ref:`select-sort-keys`. |
| 2176 |
|
| 2177 |
You must specify :ref:`select-columns-name-window-sort-keys` or |
| 2178 |
:ref:`select-columns-name-window-group-keys` to use window function. |
| 2179 |
|
| 2180 |
Here is an example that computes cumulative sum per |
| 2181 |
``Entries.tag``. Each group is sorted by ``Entries._key``: |
| 2182 |
|
| 2183 |
.. groonga-command |
| 2184 |
.. include:: ../../example/reference/commands/select/columns_name_window_sort_keys.log |
| 2185 |
.. select \ |
| 2186 |
.. --table Entries \ |
| 2187 |
.. --columns[n_likes_cumulative_sum_per_tag].stage initial \ |
| 2188 |
.. --columns[n_likes_cumulative_sum_per_tag].type UInt32 \ |
| 2189 |
.. --columns[n_likes_cumulative_sum_per_tag].value 'window_sum(n_likes)' \ |
| 2190 |
.. --columns[n_likes_cumulative_sum_per_tag].window.sort_keys _key \ |
| 2191 |
.. --columns[n_likes_cumulative_sum_per_tag].window.group_keys tag \ |
| 2192 |
.. --sort_keys _key \ |
| 2193 |
.. --output_columns tag,_key,n_likes,n_likes_cumulative_sum_per_tag |
| 2194 |
|
| 2195 |
.. _select-columns-name-window-group-keys: |
| 2196 |
|
| 2197 |
``columns[${NAME}].window.group_keys`` |
| 2198 |
"""""""""""""""""""""""""""""""""""""" |
| 2199 |
|
| 2200 |
.. versionadded:: 7.0.0 |
| 2201 |
|
| 2202 |
Specifies group keys. Window function processes records in each |
| 2203 |
group. If you specify no group keys, window function processes one |
| 2204 |
group that includes all records. |
| 2205 |
|
| 2206 |
Group keys are separated by ``,``. Each group key is column name. It's |
| 2207 |
the same as :ref:`select-drilldown`. |
| 2208 |
|
| 2209 |
You must specify :ref:`select-columns-name-window-sort-keys` or |
| 2210 |
:ref:`select-columns-name-window-group-keys` to use window function. |
| 2211 |
|
| 2212 |
Here is an example that computes sum per ``Entries.tag``: |
| 2213 |
|
| 2214 |
.. groonga-command |
| 2215 |
.. include:: ../../example/reference/commands/select/columns_name_window_group_keys.log |
| 2216 |
.. select \ |
| 2217 |
.. --table Entries \ |
| 2218 |
.. --columns[n_likes_sum_per_tag].stage initial \ |
| 2219 |
.. --columns[n_likes_sum_per_tag].type UInt32 \ |
| 2220 |
.. --columns[n_likes_sum_per_tag].value 'window_sum(n_likes)' \ |
| 2221 |
.. --columns[n_likes_sum_per_tag].window.group_keys tag \ |
| 2222 |
.. --sort_keys _key \ |
| 2223 |
.. --output_columns tag,_key,n_likes,n_likes_sum_per_tag |
| 2224 |
|
| 2225 |
.. _select-drilldown-related-parameters: |
| 2226 |
|
| 2227 |
Drilldown related parameters |
| 2228 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 2229 |
|
| 2230 |
This section describes basic drilldown related parameters. Advanced |
| 2231 |
drilldown related parameters are described in another section. |
| 2232 |
|
| 2233 |
.. _select-drilldown: |
| 2234 |
|
| 2235 |
``drilldown`` |
| 2236 |
""""""""""""" |
| 2237 |
|
| 2238 |
Specifies keys for grouping separated by ``,``. |
| 2239 |
|
| 2240 |
Matched records by specified search conditions are grouped by each |
| 2241 |
key. If you specify no search condition, all records are grouped by |
| 2242 |
each key. |
| 2243 |
|
| 2244 |
Here is a simple ``drilldown`` example: |
| 2245 |
|
| 2246 |
.. groonga-command |
| 2247 |
.. include:: ../../example/reference/commands/select/drilldown_simple.log |
| 2248 |
.. select Entries \ |
| 2249 |
.. --output_columns _key,tag \ |
| 2250 |
.. --drilldown tag |
| 2251 |
|
| 2252 |
The ``select`` command outputs the following information: |
| 2253 |
|
| 2254 |
* There is one record that has "Hello" tag. |
| 2255 |
* There is two records that has "Groonga" tag. |
| 2256 |
* There is two records that has "Senna" tag. |
| 2257 |
|
| 2258 |
Here is a ``drilldown`` with search condition example: |
| 2259 |
|
| 2260 |
.. groonga-command |
| 2261 |
.. include:: ../../example/reference/commands/select/drilldown_with_filter.log |
| 2262 |
.. select Entries \ |
| 2263 |
.. --output_columns _key,tag \ |
| 2264 |
.. --filter 'n_likes >= 5' \ |
| 2265 |
.. --drilldown tag |
| 2266 |
|
| 2267 |
The ``select`` command outputs the following information: |
| 2268 |
|
| 2269 |
* In records that have 5 or larger as ``n_likes`` value: |
| 2270 |
|
| 2271 |
* There is one record that has "Hello" tag. |
| 2272 |
* There is two records that has "Groonga" tag. |
| 2273 |
|
| 2274 |
Here is a ``drilldown`` with multiple group keys example: |
| 2275 |
|
| 2276 |
.. groonga-command |
| 2277 |
.. include:: ../../example/reference/commands/select/drilldown_multiple.log |
| 2278 |
.. select Entries \ |
| 2279 |
.. --limit 0 \ |
| 2280 |
.. --output_columns _id \ |
| 2281 |
.. --drilldown tag,n_likes |
| 2282 |
|
| 2283 |
The ``select`` command outputs the following information: |
| 2284 |
|
| 2285 |
* About ``tag``: |
| 2286 |
|
| 2287 |
* There is one record that has "Hello" tag. |
| 2288 |
* There is two records that has "Groonga" tag. |
| 2289 |
* There is two records that has "Senna" tag. |
| 2290 |
|
| 2291 |
* About ``n_likes``: |
| 2292 |
|
| 2293 |
* There is one record that has "Hello" tag. |
| 2294 |
* There is two records that has "Groonga" tag. |
| 2295 |
* There is two records that has "Senna" tag. |
| 2296 |
|
| 2297 |
.. _select-drilldown-sortby: |
| 2298 |
|
| 2299 |
``drilldown_sortby`` |
| 2300 |
"""""""""""""""""""" |
| 2301 |
|
| 2302 |
.. deprecated:: 6.0.3 |
| 2303 |
Use :ref:`select-drilldown-sort-keys` instead. |
| 2304 |
|
| 2305 |
.. _select-drilldown-sort-keys: |
| 2306 |
|
| 2307 |
``drilldown_sort_keys`` |
| 2308 |
""""""""""""""""""""""" |
| 2309 |
|
| 2310 |
Specifies sort keys for drilldown outputs separated by ``,``. Each |
| 2311 |
sort key is column name. |
| 2312 |
|
| 2313 |
You can refer the number of grouped records by ``_nsubrecs`` |
| 2314 |
:doc:`/reference/columns/pseudo`. |
| 2315 |
|
| 2316 |
Here is a simple ``drilldown_sort_keys`` example: |
| 2317 |
|
| 2318 |
.. groonga-command |
| 2319 |
.. include:: ../../example/reference/commands/select/drilldown_sort_keys_simple.log |
| 2320 |
.. select Entries \ |
| 2321 |
.. --limit 0 \ |
| 2322 |
.. --output_columns _id \ |
| 2323 |
.. --drilldown tag \ |
| 2324 |
.. --drilldown_sort_keys '-_nsubrecs, _key' |
| 2325 |
|
| 2326 |
Drilldown result is sorted by the number of grouped records (= |
| 2327 |
``_nsubrecs`` ) in descending order. If there are grouped results that |
| 2328 |
the number of records in the group are the same, these grouped results |
| 2329 |
are sorted by grouped key (= ``_key`` ) in ascending order. |
| 2330 |
|
| 2331 |
The sort keys are used in all group keys specified in ``drilldown``: |
| 2332 |
|
| 2333 |
.. groonga-command |
| 2334 |
.. include:: ../../example/reference/commands/select/drilldown_sort_keys_simple.log |
| 2335 |
.. select Entries \ |
| 2336 |
.. --limit 0 \ |
| 2337 |
.. --output_columns _id \ |
| 2338 |
.. --drilldown 'tag, n_likes' \ |
| 2339 |
.. --drilldown_sort_keys '-_nsubrecs, _key' |
| 2340 |
|
| 2341 |
The same sort keys are used in ``tag`` drilldown and ``n_likes`` |
| 2342 |
drilldown. |
| 2343 |
|
| 2344 |
If you want to use different sort keys for each drilldown, use |
| 2345 |
:ref:`select-advanced-drilldown-related-parameters`. |
| 2346 |
|
| 2347 |
.. _select-drilldown-output-columns: |
| 2348 |
|
| 2349 |
``drilldown_output_columns`` |
| 2350 |
"""""""""""""""""""""""""""" |
| 2351 |
|
| 2352 |
Specifies output columns for drilldown separated by ``,``. |
| 2353 |
|
| 2354 |
Here is a ``drilldown_output_columns`` example: |
| 2355 |
|
| 2356 |
.. groonga-command |
| 2357 |
.. include:: ../../example/reference/commands/select/drilldown_output_columns_simple.log |
| 2358 |
.. select Entries \ |
| 2359 |
.. --limit 0 \ |
| 2360 |
.. --output_columns _id \ |
| 2361 |
.. --drilldown tag \ |
| 2362 |
.. --drilldown_output_columns _key |
| 2363 |
|
| 2364 |
The ``select`` command just outputs grouped key. |
| 2365 |
|
| 2366 |
If grouped key is a referenced type column (= column that its type is |
| 2367 |
a table), you can access column of the table referenced by the |
| 2368 |
referenced type column. |
| 2369 |
|
| 2370 |
Here are a schema definition and sample data to show drilldown against |
| 2371 |
referenced type column: |
| 2372 |
|
| 2373 |
.. groonga-command |
| 2374 |
.. include:: ../../example/reference/commands/select/drilldown_output_columns_referenced_type_column_definition.log |
| 2375 |
.. table_create Tags TABLE_HASH_KEY ShortText --normalizer NormalizerAuto |
| 2376 |
.. column_create Tags label COLUMN_SCALAR ShortText |
| 2377 |
.. column_create Tags priority COLUMN_SCALAR Int32 |
| 2378 |
.. |
| 2379 |
.. table_create Items TABLE_HASH_KEY ShortText |
| 2380 |
.. column_create Items tag COLUMN_SCALAR Tags |
| 2381 |
.. |
| 2382 |
.. load --table Tags |
| 2383 |
.. [ |
| 2384 |
.. {"_key": "groonga", label: "Groonga", priority: 10}, |
| 2385 |
.. {"_key": "mroonga", label: "Mroonga", priority: 5} |
| 2386 |
.. ] |
| 2387 |
.. |
| 2388 |
.. load --table Items |
| 2389 |
.. [ |
| 2390 |
.. {"_key": "A", "tag": "groonga"}, |
| 2391 |
.. {"_key": "B", "tag": "groonga"}, |
| 2392 |
.. {"_key": "C", "tag": "mroonga"} |
| 2393 |
.. ] |
| 2394 |
|
| 2395 |
``Tags`` table is a referenced table. ``Items.tag`` is a referenced |
| 2396 |
type column. |
| 2397 |
|
| 2398 |
You can refer ``Tags.label`` by ``label`` in |
| 2399 |
``drilldown_output_columns``: |
| 2400 |
|
| 2401 |
.. groonga-command |
| 2402 |
.. include:: ../../example/reference/commands/select/drilldown_output_columns_referenced_type_column_label.log |
| 2403 |
.. select Items \ |
| 2404 |
.. --limit 0 \ |
| 2405 |
.. --output_columns _id \ |
| 2406 |
.. --drilldown tag \ |
| 2407 |
.. --drilldown_output_columns '_key, label' |
| 2408 |
|
| 2409 |
You can use ``*`` to refer all columns in referenced table (= ``Tags``): |
| 2410 |
|
| 2411 |
.. groonga-command |
| 2412 |
.. include:: ../../example/reference/commands/select/drilldown_output_columns_referenced_type_column_asterisk.log |
| 2413 |
.. select Items \ |
| 2414 |
.. --limit 0 \ |
| 2415 |
.. --output_columns _id \ |
| 2416 |
.. --drilldown tag \ |
| 2417 |
.. --drilldown_output_columns '_key, *' |
| 2418 |
|
| 2419 |
``*`` is expanded to ``label, priority``. |
| 2420 |
|
| 2421 |
The default value of ``drilldown_output_columns`` is ``_key, |
| 2422 |
_nsubrecs``. It means that grouped key and the number of records in |
| 2423 |
the group are output. |
| 2424 |
|
| 2425 |
You can use more :doc:`/reference/columns/pseudo` in |
| 2426 |
``drilldown_output_columns`` such as ``_max``, ``_min``, ``_sum`` and |
| 2427 |
``_avg`` when you use :ref:`select-drilldown-calc-types`. See |
| 2428 |
``drilldown_calc_types`` document for details. |
| 2429 |
|
| 2430 |
.. _select-drilldown-offset: |
| 2431 |
|
| 2432 |
``drilldown_offset`` |
| 2433 |
"""""""""""""""""""" |
| 2434 |
|
| 2435 |
Specifies offset to determine range of drilldown output |
| 2436 |
records. Offset is zero-based. ``--drilldown_offset 1`` means output |
| 2437 |
range is started from the 2nd record. |
| 2438 |
|
| 2439 |
Here is a ``drilldown_offset`` example: |
| 2440 |
|
| 2441 |
.. groonga-command |
| 2442 |
.. include:: ../../example/reference/commands/select/drilldown_offset_simple.log |
| 2443 |
.. select Entries \ |
| 2444 |
.. --limit 0 \ |
| 2445 |
.. --output_columns _id \ |
| 2446 |
.. --drilldown tag \ |
| 2447 |
.. --drilldown_sort_keys _key \ |
| 2448 |
.. --drilldown_offset 1 |
| 2449 |
|
| 2450 |
The ``select`` command outputs from the 2nd record. |
| 2451 |
|
| 2452 |
You can specify negative value. It means that ``the number of grouped |
| 2453 |
results + offset``. If you have 3 grouped results and specify |
| 2454 |
``--drilldown_offset -2``, you get grouped results from the 2st |
| 2455 |
(``3 + -2 = 1``. ``1`` means 2nd. Remember that offset is zero-based.) |
| 2456 |
grouped result to the 3rd grouped result. |
| 2457 |
|
| 2458 |
.. groonga-command |
| 2459 |
.. include:: ../../example/reference/commands/select/drilldown_offset_negative.log |
| 2460 |
.. select Entries \ |
| 2461 |
.. --limit 0 \ |
| 2462 |
.. --output_columns _id \ |
| 2463 |
.. --drilldown tag \ |
| 2464 |
.. --drilldown_sort_keys _key \ |
| 2465 |
.. --drilldown_offset -2 |
| 2466 |
|
| 2467 |
The ``select`` command outputs from the 2nd grouped result because the |
| 2468 |
total number of grouped results is ``3``. |
| 2469 |
|
| 2470 |
The default value of ``drilldown_offset`` is ``0``. |
| 2471 |
|
| 2472 |
.. _select-drilldown-limit: |
| 2473 |
|
| 2474 |
``drilldown_limit`` |
| 2475 |
""""""""""""""""""" |
| 2476 |
|
| 2477 |
Specifies the max number of groups in a drilldown. If the number of |
| 2478 |
groups is less than ``drilldown_limit``, all groups are outputted. |
| 2479 |
|
| 2480 |
Here is a ``drilldown_limit`` example: |
| 2481 |
|
| 2482 |
.. groonga-command |
| 2483 |
.. include:: ../../example/reference/commands/select/drilldown_limit_simple.log |
| 2484 |
.. select Entries \ |
| 2485 |
.. --limit 0 \ |
| 2486 |
.. --output_columns _id \ |
| 2487 |
.. --drilldown tag \ |
| 2488 |
.. --drilldown_sort_keys _key \ |
| 2489 |
.. --drilldown_offset 1 \ |
| 2490 |
.. --drilldown_limit 2 |
| 2491 |
|
| 2492 |
The ``select`` command outputs the 2rd and the 3rd groups. |
| 2493 |
|
| 2494 |
You can specify negative value. It means that ``the number of groups + |
| 2495 |
drilldown_limit + 1``. For example, ``--drilldown_limit -1`` outputs |
| 2496 |
all groups. It's very useful value to show all groups. |
| 2497 |
|
| 2498 |
Here is a negative ``drilldown_limit`` value example. |
| 2499 |
|
| 2500 |
.. groonga-command |
| 2501 |
.. include:: ../../example/reference/commands/select/drilldown_limit_negative.log |
| 2502 |
.. select Entries \ |
| 2503 |
.. --limit 0 \ |
| 2504 |
.. --output_columns _id \ |
| 2505 |
.. --drilldown tag \ |
| 2506 |
.. --drilldown_sort_keys _key \ |
| 2507 |
.. --drilldown_limit -1 |
| 2508 |
|
| 2509 |
The ``select`` command outputs all groups. |
| 2510 |
|
| 2511 |
The default value of ``drilldown_limit`` is ``10``. |
| 2512 |
|
| 2513 |
.. _select-drilldown-calc-types: |
| 2514 |
|
| 2515 |
``drilldown_calc_types`` |
| 2516 |
"""""""""""""""""""""""" |
| 2517 |
|
| 2518 |
Specifies how to calculate (aggregate) values in grouped records by |
| 2519 |
a drilldown. You can specify multiple calculation types separated by |
| 2520 |
"``,``". For example, ``MAX,MIN``. |
| 2521 |
|
| 2522 |
Calculation target values are read from a column of grouped |
| 2523 |
records. The column is specified by |
| 2524 |
:ref:`select-drilldown-calc-target`. |
| 2525 |
|
| 2526 |
You can read calculated value by :doc:`/reference/columns/pseudo` such |
| 2527 |
as ``_max`` and ``_min`` in :ref:`select-drilldown-output-columns`. |
| 2528 |
|
| 2529 |
You can use the following calculation types: |
| 2530 |
|
| 2531 |
.. list-table:: |
| 2532 |
:header-rows: 1 |
| 2533 |
|
| 2534 |
* - Type name |
| 2535 |
- :doc:`/reference/columns/pseudo` name |
| 2536 |
- Need :ref:`select-drilldown-calc-target` |
| 2537 |
- Description |
| 2538 |
* - ``NONE`` |
| 2539 |
- Nothing. |
| 2540 |
- Not needs. |
| 2541 |
- Just ignored. |
| 2542 |
* - ``COUNT`` |
| 2543 |
- ``_nsubrecs`` |
| 2544 |
- Not needs. |
| 2545 |
- Counting grouped records. It's always enabled. So you don't |
| 2546 |
need to specify it. |
| 2547 |
* - ``MAX`` |
| 2548 |
- ``_max`` |
| 2549 |
- Needs. |
| 2550 |
- Finding the maximum integer value from integer values in |
| 2551 |
grouped records. |
| 2552 |
* - ``MIN`` |
| 2553 |
- ``_min`` |
| 2554 |
- Needs. |
| 2555 |
- Finding the minimum integer value from integer values in |
| 2556 |
grouped records. |
| 2557 |
* - ``SUM`` |
| 2558 |
- ``_sum`` |
| 2559 |
- Needs. |
| 2560 |
- Summing integer values in grouped records. |
| 2561 |
* - ``AVG`` |
| 2562 |
- ``_avg`` |
| 2563 |
- Needs. |
| 2564 |
- Averaging integer/float values in grouped records. |
| 2565 |
|
| 2566 |
Here is a ``MAX`` example: |
| 2567 |
|
| 2568 |
.. groonga-command |
| 2569 |
.. include:: ../../example/reference/commands/select/drilldown_calc_types_max.log |
| 2570 |
.. select Entries \ |
| 2571 |
.. --limit -1 \ |
| 2572 |
.. --output_columns _id,n_likes \ |
| 2573 |
.. --drilldown tag \ |
| 2574 |
.. --drilldown_calc_types MAX \ |
| 2575 |
.. --drilldown_calc_target n_likes \ |
| 2576 |
.. --drilldown_output_columns _key,_max |
| 2577 |
|
| 2578 |
The ``select`` command groups all records by ``tag`` column value, |
| 2579 |
finding the maximum ``n_likes`` column value for each group and |
| 2580 |
outputs pairs of grouped key and the maximum ``n_likes`` column value |
| 2581 |
for the group. It uses ``_max`` :doc:`/reference/columns/pseudo` to |
| 2582 |
read the maximum ``n_likes`` column value. |
| 2583 |
|
| 2584 |
Here is a ``MIN`` example: |
| 2585 |
|
| 2586 |
.. groonga-command |
| 2587 |
.. include:: ../../example/reference/commands/select/drilldown_calc_types_min.log |
| 2588 |
.. select Entries \ |
| 2589 |
.. --limit -1 \ |
| 2590 |
.. --output_columns _id,n_likes \ |
| 2591 |
.. --drilldown tag \ |
| 2592 |
.. --drilldown_calc_types MIN \ |
| 2593 |
.. --drilldown_calc_target n_likes \ |
| 2594 |
.. --drilldown_output_columns _key,_min |
| 2595 |
|
| 2596 |
The ``select`` command groups all records by ``tag`` column value, |
| 2597 |
finding the minimum ``n_likes`` column value for each group and |
| 2598 |
outputs pairs of grouped key and the minimum ``n_likes`` column value |
| 2599 |
for the group. It uses ``_min`` :doc:`/reference/columns/pseudo` to |
| 2600 |
read the minimum ``n_likes`` column value. |
| 2601 |
|
| 2602 |
Here is a ``SUM`` example: |
| 2603 |
|
| 2604 |
.. groonga-command |
| 2605 |
.. include:: ../../example/reference/commands/select/drilldown_calc_types_sum.log |
| 2606 |
.. select Entries \ |
| 2607 |
.. --limit -1 \ |
| 2608 |
.. --output_columns _id,n_likes \ |
| 2609 |
.. --drilldown tag \ |
| 2610 |
.. --drilldown_calc_types SUM \ |
| 2611 |
.. --drilldown_calc_target n_likes \ |
| 2612 |
.. --drilldown_output_columns _key,_sum |
| 2613 |
|
| 2614 |
The ``select`` command groups all records by ``tag`` column value, |
| 2615 |
sums all ``n_likes`` column values for each group and outputs pairs |
| 2616 |
of grouped key and the summed ``n_likes`` column values for the |
| 2617 |
group. It uses ``_sum`` :doc:`/reference/columns/pseudo` to read the |
| 2618 |
summed ``n_likes`` column values. |
| 2619 |
|
| 2620 |
Here is a ``AVG`` example: |
| 2621 |
|
| 2622 |
.. groonga-command |
| 2623 |
.. include:: ../../example/reference/commands/select/drilldown_calc_types_avg.log |
| 2624 |
.. select Entries \ |
| 2625 |
.. --limit -1 \ |
| 2626 |
.. --output_columns _id,n_likes \ |
| 2627 |
.. --drilldown tag \ |
| 2628 |
.. --drilldown_calc_types AVG \ |
| 2629 |
.. --drilldown_calc_target n_likes \ |
| 2630 |
.. --drilldown_output_columns _key,_avg |
| 2631 |
|
| 2632 |
The ``select`` command groups all records by ``tag`` column value, |
| 2633 |
averages all ``n_likes`` column values for each group and outputs |
| 2634 |
pairs of grouped key and the averaged ``n_likes`` column values for |
| 2635 |
the group. It uses ``_avg`` :doc:`/reference/columns/pseudo` to read |
| 2636 |
the averaged ``n_likes`` column values. |
| 2637 |
|
| 2638 |
Here is an example that uses all calculation types: |
| 2639 |
|
| 2640 |
.. groonga-command |
| 2641 |
.. include:: ../../example/reference/commands/select/drilldown_calc_types_all.log |
| 2642 |
.. select Entries \ |
| 2643 |
.. --limit -1 \ |
| 2644 |
.. --output_columns _id,n_likes \ |
| 2645 |
.. --drilldown tag \ |
| 2646 |
.. --drilldown_calc_types MAX,MIN,SUM,AVG \ |
| 2647 |
.. --drilldown_calc_target n_likes \ |
| 2648 |
.. --drilldown_output_columns _key,_nsubrecs,_max,_min,_sum,_avg |
| 2649 |
|
| 2650 |
The ``select`` command specifies multiple calculation types separated |
| 2651 |
by "``,``" like ``MAX,MIN,SUM,AVG``. You can use ``_nsubrecs`` |
| 2652 |
:doc:`/reference/columns/pseudo` in |
| 2653 |
:ref:`select-drilldown-output-columns` without specifying ``COUNT`` in |
| 2654 |
``drilldown_calc_types``. Because ``COUNT`` is always enabled. |
| 2655 |
|
| 2656 |
The default value of ``drilldown_calc_types`` is ``NONE``. It means |
| 2657 |
that only ``COUNT`` is enabled. Because ``NONE`` is just ignored and |
| 2658 |
``COUNT`` is always enabled. |
| 2659 |
|
| 2660 |
.. _select-drilldown-calc-target: |
| 2661 |
|
| 2662 |
``drilldown_calc_target`` |
| 2663 |
""""""""""""""""""""""""" |
| 2664 |
|
| 2665 |
.. versionadded:: 6.0.3 |
| 2666 |
|
| 2667 |
Specifies the target column for :ref:`select-drilldown-calc-types`. |
| 2668 |
|
| 2669 |
If you specify a calculation type that needs a target column such as |
| 2670 |
``MAX`` in :ref:`select-drilldown-calc-types` but you omit |
| 2671 |
``drilldown_calc_target``, the calculation result is always ``0``. |
| 2672 |
|
| 2673 |
You can specify only one column name like ``--drilldown_calc_target |
| 2674 |
n_likes``. You can't specify multiple column name like |
| 2675 |
``--drilldown_calc_target _key,n_likes``. |
| 2676 |
|
| 2677 |
You can use referenced value from the target record by combining |
| 2678 |
"``.``" like ``--drilldown_calc_target |
| 2679 |
reference_column.nested_reference_column.value``. |
| 2680 |
|
| 2681 |
See :ref:`select-drilldown-calc-types` to know how to use |
| 2682 |
``drilldown_calc_target``. |
| 2683 |
|
| 2684 |
The default value of ``drilldown_calc_target`` is ``null``. It means |
| 2685 |
that no calculation target column is specified. |
| 2686 |
|
| 2687 |
.. _select-drilldown-filter: |
| 2688 |
|
| 2689 |
``drilldown_filter`` |
| 2690 |
"""""""""""""""""""" |
| 2691 |
|
| 2692 |
.. versionadded:: 6.0.3 |
| 2693 |
|
| 2694 |
Specifies the filter condition against the drilled down result. |
| 2695 |
|
| 2696 |
The syntax is :doc:`/reference/grn_expr/script_syntax`. It's the same |
| 2697 |
as :ref:`select-filter`. |
| 2698 |
|
| 2699 |
Here is an example to suppress tags that are occurred only once: |
| 2700 |
|
| 2701 |
.. groonga-command |
| 2702 |
.. include:: ../../example/reference/commands/select/drilldown_filter.log |
| 2703 |
.. select Entries \ |
| 2704 |
.. --limit -1 \ |
| 2705 |
.. --output_columns _id,tag \ |
| 2706 |
.. --drilldown tag \ |
| 2707 |
.. --drilldown_filter '_nsubrecs > 1' \ |
| 2708 |
.. --drilldown_output_columns _key,_nsubrecs |
| 2709 |
|
| 2710 |
.. _select-drilldown-max-n-target-records: |
| 2711 |
|
| 2712 |
``drilldown_max_n_target_records`` |
| 2713 |
"""""""""""""""""""""""""""""""""" |
| 2714 |
|
| 2715 |
.. versionadded:: 12.0.0 |
| 2716 |
|
| 2717 |
Specifies the max number of records of the drilldown target table |
| 2718 |
(filtered result) to use drilldown. If the number of filtered result |
| 2719 |
is larger than the specified value, some records in filtered result |
| 2720 |
aren't used for drilldown. |
| 2721 |
|
| 2722 |
If the specified value is negative, it's processed same as |
| 2723 |
:ref:`select-limit`. For example, ``-1`` uses all records. The default |
| 2724 |
value is ``-1``. It means that all filtered records are used by |
| 2725 |
default. |
| 2726 |
|
| 2727 |
This feature is useful when filtered result may be very large. A |
| 2728 |
drilldown against large filtered result may be slow. You can limit the |
| 2729 |
max number of records to be used for drilldown by this feature. |
| 2730 |
|
| 2731 |
Here is an example to limit the max number of records to be used for |
| 2732 |
drilldown. The last 2 records, ``{"_id": 4, "tag": "Senna"}`` and |
| 2733 |
``{"_id": 5, "tag": "Senna"}``, aren't used: |
| 2734 |
|
| 2735 |
.. groonga-command |
| 2736 |
.. include:: ../../example/reference/commands/select/drilldown_max_n_target_records.log |
| 2737 |
.. select Entries \ |
| 2738 |
.. --limit -1 \ |
| 2739 |
.. --output_columns _id,tag \ |
| 2740 |
.. --drilldown tag \ |
| 2741 |
.. --drilldown_max_n_target_records 3 |
| 2742 |
|
| 2743 |
.. _select-advanced-drilldown-related-parameters: |
| 2744 |
|
| 2745 |
Advanced drilldown related parameters |
| 2746 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 2747 |
|
| 2748 |
.. versionadded:: 4.0.8 |
| 2749 |
|
| 2750 |
You can get multiple drilldown results by specifying multiple group |
| 2751 |
keys by :ref:`select-drilldown`. But you need to use the same |
| 2752 |
configuration for all drilldowns. For example, |
| 2753 |
:ref:`select-drilldown-output-columns` is used by all drilldowns. |
| 2754 |
|
| 2755 |
You can use a configuration for each drilldown by the following |
| 2756 |
parameters: |
| 2757 |
|
| 2758 |
* ``drilldowns[${LABEL}].keys`` |
| 2759 |
* ``drilldowns[${LABEL}].table`` |
| 2760 |
* ``drilldowns[${LABEL}].sort_keys`` |
| 2761 |
* ``drilldowns[${LABEL}].output_columns`` |
| 2762 |
* ``drilldowns[${LABEL}].offset`` |
| 2763 |
* ``drilldowns[${LABEL}].limit`` |
| 2764 |
* ``drilldowns[${LABEL}].calc_types`` |
| 2765 |
* ``drilldowns[${LABEL}].calc_target`` |
| 2766 |
* ``drilldowns[${LABEL}].filter`` |
| 2767 |
* ``drilldowns[${LABEL}].max_n_target_records`` |
| 2768 |
* ``drilldowns[${LABEL}].key_vector_expansion`` |
| 2769 |
* ``drilldowns[${LABEL}].columns[${NAME}].stage=null`` |
| 2770 |
* ``drilldowns[${LABEL}].columns[${NAME}].flags=COLUMN_SCALAR`` |
| 2771 |
* ``drilldowns[${LABEL}].columns[${NAME}].type=null`` |
| 2772 |
* ``drilldowns[${LABEL}].columns[${NAME}].value=null`` |
| 2773 |
* ``drilldowns[${LABEL}].columns[${NAME}].window.sort_keys=null`` |
| 2774 |
* ``drilldowns[${LABEL}].columns[${NAME}].window.group_keys=null`` |
| 2775 |
|
| 2776 |
``${LABEL}`` is a variable. You can use the following characters for |
| 2777 |
``${LABEL}``: |
| 2778 |
|
| 2779 |
* Alphabets |
| 2780 |
* Digits |
| 2781 |
* ``.`` |
| 2782 |
* ``_`` |
| 2783 |
|
| 2784 |
``${NAME}`` is a variable. You can use the following characters for |
| 2785 |
``${NAME}``: |
| 2786 |
|
| 2787 |
* Alphabets |
| 2788 |
* Digits |
| 2789 |
* ``_`` |
| 2790 |
|
| 2791 |
.. note:: |
| 2792 |
|
| 2793 |
You can use more characters but it's better that you use only these |
| 2794 |
characters. |
| 2795 |
|
| 2796 |
Parameters that has the same ``${LABEL}`` value are grouped. Grouped |
| 2797 |
parameters are used for one drilldown. |
| 2798 |
|
| 2799 |
For example, there are 2 groups for the following parameters: |
| 2800 |
|
| 2801 |
* ``--drilldowns[label1].keys _key`` |
| 2802 |
* ``--drilldowns[label1].output_columns _nsubrecs`` |
| 2803 |
* ``--drilldowns[label2].keys tag`` |
| 2804 |
* ``--drilldowns[label2].output_columns _key,_nsubrecs`` |
| 2805 |
|
| 2806 |
``drilldowns[label1].keys`` and ``drilldowns[label1].output_columns`` |
| 2807 |
are grouped. ``drilldowns[label2].keys`` and |
| 2808 |
``drilldowns[label2].output_columns`` are also grouped. |
| 2809 |
|
| 2810 |
In ``label1`` group, ``_key`` is used for group key and ``_nsubrecs`` |
| 2811 |
is used for output columns. |
| 2812 |
|
| 2813 |
In ``label2`` group, ``tag`` is used for group key and |
| 2814 |
``_key,_nsubrecs`` is used for output columns. |
| 2815 |
|
| 2816 |
See document for corresponding ``drilldown_XXX`` parameter to know how |
| 2817 |
to use it for the following parameters: |
| 2818 |
|
| 2819 |
* ``drilldowns[${LABEL}].sort_keys``: :ref:`select-drilldown-sort-keys` |
| 2820 |
* ``drilldowns[${LABEL}].offset``: :ref:`select-drilldown-offset` |
| 2821 |
* ``drilldowns[${LABEL}].limit``: :ref:`select-drilldown-limit` |
| 2822 |
* ``drilldowns[${LABEL}].calc_types``: :ref:`select-drilldown-calc-types` |
| 2823 |
* ``drilldowns[${LABEL}].calc_target``: :ref:`select-drilldown-calc-target` |
| 2824 |
* ``drilldowns[${LABEL}].filter``: :ref:`select-drilldown-filter` |
| 2825 |
* ``drilldowns[${LABEL}].max_n_target_records``: :ref:`select-drilldown-max-n-target-records` |
| 2826 |
|
| 2827 |
See document for corresponding ``columns[${NAME}].XXX`` parameter to |
| 2828 |
know how to use it for the following parameters: |
| 2829 |
|
| 2830 |
* ``drilldowns[${LABEL}].columns[${NAME}].flags=COLUMN_SCALAR``: |
| 2831 |
:ref:`select-columns-name-flags` |
| 2832 |
* ``drilldowns[${LABEL}].columns[${NAME}].type=null``: |
| 2833 |
:ref:`select-columns-name-type` |
| 2834 |
* ``drilldowns[${LABEL}].columns[${NAME}].value=null``: |
| 2835 |
:ref:`select-columns-name-value` |
| 2836 |
* ``drilldowns[${LABEL}].columns[${NAME}].window.sort_keys=null``: |
| 2837 |
:ref:`select-columns-name-window-sort-keys` |
| 2838 |
* ``drilldowns[${LABEL}].columns[${NAME}].window.group_keys=null``: |
| 2839 |
:ref:`select-columns-name-window-group-keys` |
| 2840 |
|
| 2841 |
The following parameters are needed more description: |
| 2842 |
|
| 2843 |
* ``drilldowns[${LABEL}].keys`` |
| 2844 |
* ``drilldowns[${LABEL}].table`` |
| 2845 |
* ``drilldowns[${LABEL}].output_columns`` |
| 2846 |
* ``drilldowns[${LABEL}].columns[${NAME}].stage=null`` |
| 2847 |
|
| 2848 |
Output format is different a bit. It's also needed more description. |
| 2849 |
|
| 2850 |
.. _select-drilldowns-label-keys: |
| 2851 |
|
| 2852 |
``drilldowns[${LABEL}].keys`` |
| 2853 |
""""""""""""""""""""""""""""" |
| 2854 |
|
| 2855 |
.. versionadded:: 4.0.8 |
| 2856 |
|
| 2857 |
:ref:`select-drilldown` can specify multiple keys for multiple |
| 2858 |
drilldowns. But it can't specify multiple keys for one drilldown. |
| 2859 |
|
| 2860 |
``drilldowns[${LABEL}].keys`` can't specify multiple keys for multiple |
| 2861 |
drilldowns. But it can specify multiple keys for one drilldown. |
| 2862 |
|
| 2863 |
You can specify multiple keys separated by "``,``". |
| 2864 |
|
| 2865 |
Here is an example to group by multiple keys, ``tag`` and ``n_likes`` |
| 2866 |
column values: |
| 2867 |
|
| 2868 |
.. groonga-command |
| 2869 |
.. include:: ../../example/reference/commands/select/drilldowns_label_keys_multiple.log |
| 2870 |
.. select Entries \ |
| 2871 |
.. --limit -1 \ |
| 2872 |
.. --output_columns tag,n_likes \ |
| 2873 |
.. --drilldowns[tag.n_likes].keys tag,n_likes \ |
| 2874 |
.. --drilldowns[tag.n_likes].output_columns _value.tag,_value.n_likes,_nsubrecs |
| 2875 |
|
| 2876 |
``tag.n_likes`` is used as the label for the drilldown parameters |
| 2877 |
group. You can refer grouped keys by ``_value.${KEY_NAME}`` syntax in |
| 2878 |
:ref:`select-drilldowns-label-output-columns`. ``${KEY_NAME}`` is a |
| 2879 |
column name to be used by group key. ``tag`` and ``n_likes`` are |
| 2880 |
``${KEY_NAME}`` in this case. |
| 2881 |
|
| 2882 |
Note that you can't use ``_value.${KEY_NAME}`` syntax when you just |
| 2883 |
specify one key as ``drilldowns[${LABEL}].keys`` like ``--drilldowns[tag].keys |
| 2884 |
tag``. You should use ``_key`` for the case. It's the same rule in |
| 2885 |
:ref:`select-drilldown-output-columns`. |
| 2886 |
|
| 2887 |
.. _select-drilldowns-label-table: |
| 2888 |
|
| 2889 |
``drilldowns[${LABEL}].table`` |
| 2890 |
"""""""""""""""""""""""""""""" |
| 2891 |
|
| 2892 |
.. versionadded:: 6.0.2 |
| 2893 |
|
| 2894 |
Specify ``${LABEL}`` of other ``drilldowns`` or ``slices``. |
| 2895 |
|
| 2896 |
You can drilldown the result of specified ``${LABEL}``. |
| 2897 |
It means that this parameter enables a nested drilldown. |
| 2898 |
|
| 2899 |
Here is an example to execute the nested drilldown. The final result takes first drilldown by ``tag`` and then 2nd drilldown by ``category`` against first result. |
| 2900 |
|
| 2901 |
.. groonga-command |
| 2902 |
.. include:: ../../example/reference/commands/select/drilldowns_label_table.log |
| 2903 |
.. table_create NestedDrilldownTags TABLE_PAT_KEY ShortText |
| 2904 |
.. column_create NestedDrilldownTags category COLUMN_SCALAR ShortText |
| 2905 |
.. table_create NestedDrilldownMemos TABLE_HASH_KEY ShortText |
| 2906 |
.. column_create NestedDrilldownMemos tag COLUMN_SCALAR NestedDrilldownTags |
| 2907 |
.. load --table NestedDrilldownMemos |
| 2908 |
.. [ |
| 2909 |
.. {"_key": "Groonga is fast!", "tag": "Groonga"}, |
| 2910 |
.. {"_key": "Groonga sticker!", "tag": "Groonga"}, |
| 2911 |
.. {"_key": "Mroonga sticker!", "tag": "Mroonga"}, |
| 2912 |
.. {"_key": "Rroonga is fast!", "tag": "Rroonga"} |
| 2913 |
.. ] |
| 2914 |
.. load --table NestedDrilldownTags |
| 2915 |
.. [ |
| 2916 |
.. {"_key": "Groonga", "category": "C/C++"}, |
| 2917 |
.. {"_key": "Mroonga", "category": "C/C++"}, |
| 2918 |
.. {"_key": "PGroonga", "category": "C/C++"}, |
| 2919 |
.. {"_key": "Rroonga", "category": "Ruby"} |
| 2920 |
.. ] |
| 2921 |
.. select NestedDrilldownMemos \ |
| 2922 |
.. --drilldowns[Tag].keys tag \ |
| 2923 |
.. --drilldowns[Tag].output_columns _key \ |
| 2924 |
.. --drilldowns[Category].table Tag \ |
| 2925 |
.. --drilldowns[Category].keys category \ |
| 2926 |
.. --drilldowns[Category].output_columns _key,_nsubrecs |
| 2927 |
|
| 2928 |
In this example; |
| 2929 |
The schema contains the table named as ``NestedDrilldownMemo`` which has the column named as ``tag``, |
| 2930 |
the table named as ``NestedDrilldownTags`` which has the column named as ``category``. |
| 2931 |
|
| 2932 |
``Tag`` drilldowns ``NestedDrilldownMemos`` by ``tag``. |
| 2933 |
Thus, the result of ``Tag`` contains one row each for ``Groonga``, ``Mroonga`` and ``Rroonga``. |
| 2934 |
And then, ``Category`` drilldowns ``Tag`` by ``category``. |
| 2935 |
Thus the result of ``Category`` contains two records has ``C/C++`` and one records has ``Ruby``. |
| 2936 |
|
| 2937 |
.. _select-drilldowns-label-key-vector-expansions: |
| 2938 |
|
| 2939 |
``drilldowns[${LABEL}].key_vector_expansion`` |
| 2940 |
""""""""""""""""""""""""""""""""""""""""""""" |
| 2941 |
|
| 2942 |
.. versionadded:: 12.1.1 |
| 2943 |
|
| 2944 |
This specifies how to expand key when keys for drilldown are vector. Currently, ``NONE`` or ``POWER_SET`` are able to be specified. |
| 2945 |
|
| 2946 |
This work only time when one key is target for drilldown. This doesn't work time when more than 2 keys are target for drilldown. |
| 2947 |
|
| 2948 |
.. _select-drilldowns-label-key-vector-expansions-none: |
| 2949 |
|
| 2950 |
``NONE`` |
| 2951 |
~~~~~~~~ |
| 2952 |
|
| 2953 |
This works as same as ``key_vector_expansion`` is not specified. |
| 2954 |
|
| 2955 |
Keys would not be expanded. Each element within a vector works as each key. |
| 2956 |
|
| 2957 |
Following is a sample to aggregate total number of individual and combination occurrence for 3 tags, ``Groonga``, ``Mroonga``, and ``PGroonga``. |
| 2958 |
|
| 2959 |
.. groonga-command |
| 2960 |
.. include:: ../../example/reference/commands/select/drilldowns_label_none.log |
| 2961 |
.. table_create NoneExpantionDrilldownMemos TABLE_HASH_KEY ShortText |
| 2962 |
.. column_create NoneExpantionDrilldownMemos tags COLUMN_VECTOR ShortText |
| 2963 |
.. load --table NoneExpantionDrilldownMemos |
| 2964 |
.. [ |
| 2965 |
.. {"_key": "Groonga is fast!", "tags": ["Groonga"]}, |
| 2966 |
.. {"_key": "Mroonga uses Groonga!", "tags": ["Groonga", "Mroonga"]}, |
| 2967 |
.. {"_key": "PGroonga uses Groonga!", "tags": ["Groonga", "PGroonga"]}, |
| 2968 |
.. {"_key": "Mroonga and PGroonga are Groonga family", "tags": ["Groonga", "Mroonga", "PGroonga"]} |
| 2969 |
.. ] |
| 2970 |
.. select NoneExpantionDrilldownMemos \ |
| 2971 |
.. --drilldowns[tags].keys tags \ |
| 2972 |
.. --drilldowns[tags].key_vector_expansion NONE \ |
| 2973 |
.. --drilldowns[tags].columns[none_expantion].stage initial \ |
| 2974 |
.. --drilldowns[tags].columns[none_expantion].value _key \ |
| 2975 |
.. --drilldowns[tags].columns[none_expantion].flags COLUMN_VECTOR \ |
| 2976 |
.. --drilldowns[tags].sort_keys 'none_expantion' \ |
| 2977 |
.. --drilldowns[tags].output_columns 'none_expantion, _nsubrecs' \ |
| 2978 |
.. --limit 0 |
| 2979 |
|
| 2980 |
Following are facts from the results. |
| 2981 |
|
| 2982 |
.. csv-table:: |
| 2983 |
|
| 2984 |
"tag","number of occurrence( ``_nsubrecs`` )" |
| 2985 |
"``Groonga``", "4" |
| 2986 |
"``Mroonga``", "2" |
| 2987 |
"``PGroonga``", "2" |
| 2988 |
|
| 2989 |
.. _select-drilldowns-label-key-vector-expansions-power-set: |
| 2990 |
|
| 2991 |
``POWER_SET`` |
| 2992 |
~~~~~~~~~~~~~ |
| 2993 |
|
| 2994 |
This aggregates total with expanding vectors to the power set. |
| 2995 |
In this case, a target vector is considered as multi set. |
| 2996 |
Thus, each element is considered as an individual element when there are multiple elements with same value. |
| 2997 |
|
| 2998 |
For example, there is a vector ``[A, B, C]``. In this case, a target set is ``{A, B, C}``. |
| 2999 |
The power set is aggregation for all of subsets within a set. Following shows all of subset within a set ``{A, B, C}``. |
| 3000 |
However, Groonga does not use empty set, that number of elements is 0. It is because empty set is not useful for results of drilldown. |
| 3001 |
Please report at `issue <https://github.com/groonga/groonga/issues>`_, if you find a case to use empty set. |
| 3002 |
|
| 3003 |
* Subset with 1 element |
| 3004 |
|
| 3005 |
* ``{A}`` |
| 3006 |
* ``{B}`` |
| 3007 |
* ``{C}`` |
| 3008 |
|
| 3009 |
* Subset with 2 elements |
| 3010 |
|
| 3011 |
* ``{A, B}`` |
| 3012 |
* ``{B, C}`` |
| 3013 |
* ``{A, C}`` |
| 3014 |
|
| 3015 |
* Subset with 3 elements |
| 3016 |
|
| 3017 |
* ``{A, B, C}`` |
| 3018 |
|
| 3019 |
Those are all subsets for ``{A, B, C}``. |
| 3020 |
Since the power set is aggregation of those subsets, ``{{A}, {B}, {C}, {A, B}, {B, C}, {A, C}, {A, B, C}}`` is a power set for the vector. |
| 3021 |
|
| 3022 |
``POWER_SET`` aggregates with each subset for ``{{A}, {B}, {C}, {A, B}, {B, C}, {A, C}, {A, B, C}}``. |
| 3023 |
|
| 3024 |
For example, there is a case to aggregate ``[A, B, C]`` and ``[B, C, D]`` with the power set. |
| 3025 |
|
| 3026 |
A power set for ``[A, B, C]`` is ``{{A}, {B}, {C}, {A, B}, {B, C}, {A, C}, {A, B, C}}`` as previously explained. |
| 3027 |
Likewise a power set for ``[B, C, D]`` is ``{{B}, {C}, {D}, {B, C}, {C, D}, {B, D}, {B, C, D}}``. |
| 3028 |
|
| 3029 |
Aggregating occurrence of each subset in each power set is shown in result as follows. |
| 3030 |
|
| 3031 |
.. csv-table:: |
| 3032 |
|
| 3033 |
"subset", "number of occurrence( ``_nsubrecs`` )" |
| 3034 |
"``{A}``", "1" |
| 3035 |
"``{B}``", "2" |
| 3036 |
"``{C}``", "2" |
| 3037 |
"``{D}``", "1" |
| 3038 |
"``{A, B}``", "1" |
| 3039 |
"``{A, C}``", "1" |
| 3040 |
"``{B, C}``", "2" |
| 3041 |
"``{B, D}``", "1" |
| 3042 |
"``{C, D}``", "1" |
| 3043 |
"``{A, B, C}``", "1" |
| 3044 |
"``{B, C, D}``", "1" |
| 3045 |
|
| 3046 |
This aggregating methods is useful when it is requirement to sum total number of occurrence for individual tags and combination of tags at once. |
| 3047 |
|
| 3048 |
Following is an example to aggregate total occurrence for individual and combination of 3 tags, ``Groonga``, ``Mroonga``, and ``PGroonga``. |
| 3049 |
|
| 3050 |
.. groonga-command |
| 3051 |
.. include:: ../../example/reference/commands/select/drilldowns_label_power_set.log |
| 3052 |
.. table_create PowerSetDrilldownMemos TABLE_HASH_KEY ShortText |
| 3053 |
.. column_create PowerSetDrilldownMemos tags COLUMN_VECTOR ShortText |
| 3054 |
.. load --table PowerSetDrilldownMemos |
| 3055 |
.. [ |
| 3056 |
.. {"_key": "Groonga is fast!", "tags": ["Groonga"]}, |
| 3057 |
.. {"_key": "Mroonga uses Groonga!", "tags": ["Groonga", "Mroonga"]}, |
| 3058 |
.. {"_key": "PGroonga uses Groonga!", "tags": ["Groonga", "PGroonga"]}, |
| 3059 |
.. {"_key": "Mroonga and PGroonga are Groonga family", "tags": ["Groonga", "Mroonga", "PGroonga"]} |
| 3060 |
.. ] |
| 3061 |
.. select PowerSetDrilldownMemos \ |
| 3062 |
.. --drilldowns[tags].keys tags \ |
| 3063 |
.. --drilldowns[tags].key_vector_expansion POWER_SET \ |
| 3064 |
.. --drilldowns[tags].columns[power_set].stage initial \ |
| 3065 |
.. --drilldowns[tags].columns[power_set].value _key \ |
| 3066 |
.. --drilldowns[tags].columns[power_set].flags COLUMN_VECTOR \ |
| 3067 |
.. --drilldowns[tags].sort_keys 'power_set' \ |
| 3068 |
.. --drilldowns[tags].output_columns 'power_set, _nsubrecs' \ |
| 3069 |
.. --limit 0 |
| 3070 |
|
| 3071 |
With this aggregation result, following information would be known. |
| 3072 |
|
| 3073 |
.. csv-table:: |
| 3074 |
|
| 3075 |
"tag","number of occurrence( ``_nsubrecs`` )" |
| 3076 |
"``Groonga``", "4" |
| 3077 |
"``Mroonga``", "2" |
| 3078 |
"``PGroonga``", "2" |
| 3079 |
"``Groonga`` and ``Mroonga``", "2" |
| 3080 |
"``Groonga`` and ``PGroonga``", "2" |
| 3081 |
"``Mroonga`` and ``PGroonga``", "1" |
| 3082 |
"``Groonga`` and ``Mroonga`` and ``PGroonga``", "1" |
| 3083 |
|
| 3084 |
This result allows to analyze correlation between each tag and combination such as whether often used. |
| 3085 |
For example with this sample, it can be analyzed that ``Groonga`` and ``Mroonga`` are used twice at same time and within those twice, |
| 3086 |
``PGroonga`` is also used at same time for once. |
| 3087 |
|
| 3088 |
.. _select-drilldowns-label-output-columns: |
| 3089 |
|
| 3090 |
``drilldowns[${LABEL}].output_columns`` |
| 3091 |
""""""""""""""""""""""""""""""""""""""" |
| 3092 |
|
| 3093 |
.. versionadded:: 4.0.8 |
| 3094 |
|
| 3095 |
It's almost same as :ref:`select-drilldown-output-columns`. The |
| 3096 |
difference between :ref:`select-drilldown-output-columns` and |
| 3097 |
``drilldowns[${LABEL}].output_columns`` is how to refer group keys. |
| 3098 |
|
| 3099 |
:ref:`select-drilldown-output-columns` uses ``_key`` |
| 3100 |
:doc:`/reference/columns/pseudo` to refer group |
| 3101 |
key. ``drilldowns[${LABEL}].output_columns`` also uses ``_key`` |
| 3102 |
:doc:`/reference/columns/pseudo` to refer group key when you specify |
| 3103 |
only one group key by :ref:`select-drilldowns-label-keys`. |
| 3104 |
|
| 3105 |
Here is an example to refer single group key by ``_key`` |
| 3106 |
:doc:`/reference/columns/pseudo`: |
| 3107 |
|
| 3108 |
.. groonga-command |
| 3109 |
.. include:: ../../example/reference/commands/select/drilldowns_label_output_columns_single_group_key.log |
| 3110 |
.. select Entries \ |
| 3111 |
.. --limit 0 \ |
| 3112 |
.. --output_columns _id \ |
| 3113 |
.. --drilldowns[tag.n_likes].keys tag \ |
| 3114 |
.. --drilldowns[tag.n_likes].output_columns _key |
| 3115 |
|
| 3116 |
But you can't refer each group key by ``_key`` |
| 3117 |
:doc:`/reference/columns/pseudo` in |
| 3118 |
``drilldowns[${LABEL}].output_columns``. You need to use |
| 3119 |
``_value.${KEY_NAME}`` syntax. ``${KEY_NAME}`` is a column name that is |
| 3120 |
used for group key in :ref:`select-drilldowns-label-keys`. |
| 3121 |
|
| 3122 |
Here is an example to refer each group key in multiple group keys by |
| 3123 |
``_value.${KEY_NAME}`` syntax: |
| 3124 |
|
| 3125 |
.. groonga-command |
| 3126 |
.. include:: ../../example/reference/commands/select/drilldowns_label_output_columns_multiple_group_key.log |
| 3127 |
.. select Entries \ |
| 3128 |
.. --limit 0 \ |
| 3129 |
.. --output_columns _id \ |
| 3130 |
.. --drilldowns[tag.n_likes].keys tag,n_likes \ |
| 3131 |
.. --drilldowns[tag.n_likes].output_columns _value.tag,_value.n_likes |
| 3132 |
|
| 3133 |
.. tip:: Why ``_value.${KEY_NAME}`` syntax? |
| 3134 |
|
| 3135 |
It's implementation specific information. |
| 3136 |
|
| 3137 |
``_key`` is a vector value. The vector value is consists of all |
| 3138 |
group keys. You can see byte sequence of the vector value by |
| 3139 |
referring ``_key`` in ``drilldowns[${LABEL}].output_columns``. |
| 3140 |
|
| 3141 |
There is one grouped record in ``_value`` to refer each grouped |
| 3142 |
values when you specify multiple group keys to |
| 3143 |
:ref:`select-drilldowns-label-keys`. So you can refer each group key |
| 3144 |
by ``_value.${KEY_NAME}`` syntax. |
| 3145 |
|
| 3146 |
On the other hand, there is no grouped record in ``_value`` when |
| 3147 |
you specify only one group key to |
| 3148 |
:ref:`select-drilldowns-label-keys`. So you can't refer group key by |
| 3149 |
``_value.${KEY_NAME}`` syntax. |
| 3150 |
|
| 3151 |
.. _select-drilldowns-label-columns-name-stage: |
| 3152 |
|
| 3153 |
``drilldowns[${LABEL}].columns[${NAME}].stage`` |
| 3154 |
""""""""""""""""""""""""""""""""""""""""""""""" |
| 3155 |
|
| 3156 |
.. versionadded:: 6.0.5 |
| 3157 |
|
| 3158 |
Specifies when the dynamic column is created. This is a required |
| 3159 |
parameter to create a dynamic column. |
| 3160 |
|
| 3161 |
Here are available stages: |
| 3162 |
|
| 3163 |
.. list-table:: |
| 3164 |
:header-rows: 1 |
| 3165 |
|
| 3166 |
* - Name |
| 3167 |
- Description |
| 3168 |
* - ``initial`` |
| 3169 |
- Dynamic column is created at first. |
| 3170 |
* - ``filtered`` |
| 3171 |
- Dynamic column is created after ``drilldowns[${LABEL}].filter`` |
| 3172 |
is evaluated. |
| 3173 |
* - ``output`` |
| 3174 |
- Dynamic column is created before :ref:`select-drilldowns-label-output-columns` |
| 3175 |
is evaluated. |
| 3176 |
|
| 3177 |
.. note:: |
| 3178 |
|
| 3179 |
``filtered`` stage and ``output`` stage will be able to use from 10.0.3 or later. |
| 3180 |
|
| 3181 |
Here is one drilldown process flow with dynamic column creation |
| 3182 |
points. You should choose stage as late as possible: |
| 3183 |
|
| 3184 |
#. Evaluates :ref:`select-drilldowns-label-keys`, |
| 3185 |
``drilldowns[${LABEL}].calc_types`` and |
| 3186 |
``drilldowns[${LABEL}].calc_target``. |
| 3187 |
|
| 3188 |
#. Creates dynamic columns for ``initial`` stage. All drilldown |
| 3189 |
result records have these dynamic columns. |
| 3190 |
|
| 3191 |
#. Evaluates ``drilldowns[${LABEL}].filter``. You can use dynamic |
| 3192 |
columns created in ``initial`` stage. |
| 3193 |
|
| 3194 |
#. Creates dynamic columns for ``filtered`` stage. |
| 3195 |
Only filtered records have these dynamic columns. |
| 3196 |
|
| 3197 |
#. Evaluates ``drilldowns[${LABEL}].sort_keys``, |
| 3198 |
``drilldowns[${LABEL}].offset`` and |
| 3199 |
``drilldowns[${LABEL}].limit``. You can use dynamic columns |
| 3200 |
created in ``initial`` stage and ``filtered`` stage. |
| 3201 |
|
| 3202 |
#. Creates dynamic columns for ``output`` stage. |
| 3203 |
Only ``drilldowns[${LABEL}].limit`` records have these dynamic columns. |
| 3204 |
|
| 3205 |
#. Evaluates :ref:`select-drilldowns-label-output-columns`. You can |
| 3206 |
use dynamic columns created in ``initial`` stage, ``filtered`` stage, |
| 3207 |
and ``output`` stage. |
| 3208 |
|
| 3209 |
Here is a ``drilldowns[${LABEL}].columns[${NAME}].stage`` example. It |
| 3210 |
creates ``is_popular`` column at ``initial`` stage. You can use |
| 3211 |
``is_popular`` in all parameters such as |
| 3212 |
``drilldowns[${LABEL}].filter`` and |
| 3213 |
``drilldowns[${LABEL}].output_columns``: |
| 3214 |
|
| 3215 |
.. groonga-command |
| 3216 |
.. include:: ../../example/reference/commands/select/drilldowns_label_columns_name_stage.log |
| 3217 |
.. select Entries \ |
| 3218 |
.. --drilldowns[tag].keys tag \ |
| 3219 |
.. --drilldowns[tag].columns[is_popular].stage initial \ |
| 3220 |
.. --drilldowns[tag].columns[is_popular].type Bool \ |
| 3221 |
.. --drilldowns[tag].columns[is_popular].value '_nsubrecs > 1' \ |
| 3222 |
.. --drilldowns[tag].filter is_popular \ |
| 3223 |
.. --drilldowns[tag].output_columns _key,is_popular,_nsubrecs |
| 3224 |
|
| 3225 |
.. versionadded:: 4.0.8 |
| 3226 |
|
| 3227 |
.. _select-drilldowns-label-output-format: |
| 3228 |
|
| 3229 |
Output format for ``drilldowns[${LABEL}]`` style |
| 3230 |
"""""""""""""""""""""""""""""""""""""""""""""""" |
| 3231 |
|
| 3232 |
There is a difference in output format between :ref:`select-drilldown` |
| 3233 |
and :ref:`select-drilldowns-label-keys`. :ref:`select-drilldown` uses |
| 3234 |
array to output multiple drilldown results. |
| 3235 |
:ref:`select-drilldowns-label-keys` uses pairs of label and drilldown |
| 3236 |
result. |
| 3237 |
|
| 3238 |
:ref:`select-drilldown` uses the following output format:: |
| 3239 |
|
| 3240 |
[ |
| 3241 |
HEADER, |
| 3242 |
[ |
| 3243 |
SEARCH_RESULT, |
| 3244 |
DRILLDOWN_RESULT1, |
| 3245 |
DRILLDOWN_RESULT2, |
| 3246 |
... |
| 3247 |
] |
| 3248 |
] |
| 3249 |
|
| 3250 |
:ref:`select-drilldowns-label-keys` uses the following output format:: |
| 3251 |
|
| 3252 |
[ |
| 3253 |
HEADER, |
| 3254 |
[ |
| 3255 |
SEARCH_RESULT, |
| 3256 |
{ |
| 3257 |
"LABEL1": DRILLDOWN_RESULT1, |
| 3258 |
"LABEL2": DRILLDOWN_RESULT2, |
| 3259 |
... |
| 3260 |
} |
| 3261 |
] |
| 3262 |
] |
| 3263 |
|
| 3264 |
.. _select-slice-related-parameters: |
| 3265 |
|
| 3266 |
Slice related parameters |
| 3267 |
^^^^^^^^^^^^^^^^^^^^^^^^ |
| 3268 |
|
| 3269 |
.. versionadded:: 6.0.3 |
| 3270 |
|
| 3271 |
This section describes slice related parameters. |
| 3272 |
|
| 3273 |
TODO |
| 3274 |
|
| 3275 |
Here are parameters for slice: |
| 3276 |
|
| 3277 |
.. list-table:: |
| 3278 |
:header-rows: 1 |
| 3279 |
|
| 3280 |
* - Name |
| 3281 |
- Required |
| 3282 |
* - ``--slices[${LABEL}].match_columns`` |
| 3283 |
- Optional |
| 3284 |
* - ``--slices[${LABEL}].query`` |
| 3285 |
- Required if ``--slices[${LABEL}].filter`` isn't specified. |
| 3286 |
* - ``--slices[${LABEL}].filter`` |
| 3287 |
- Required if ``--slices[${LABEL}].query`` isn't specified. |
| 3288 |
* - ``--slices[${LABEL}].query_expander`` |
| 3289 |
- Optional |
| 3290 |
* - ``--slices[${LABEL}].query_flags`` |
| 3291 |
- Optional |
| 3292 |
* - ``--slices[${LABEL}].sort_keys`` |
| 3293 |
- Optional |
| 3294 |
* - ``--slices[${LABEL}].output_columns`` |
| 3295 |
- Optional |
| 3296 |
* - ``--slices[${LABEL}].offset`` |
| 3297 |
- Optional |
| 3298 |
* - ``--slices[${LABEL}].limit`` |
| 3299 |
- Optional |
| 3300 |
|
| 3301 |
.. _select-slices-label-match-columns: |
| 3302 |
|
| 3303 |
``slices[${LABEL}].match_columns`` |
| 3304 |
"""""""""""""""""""""""""""""""""" |
| 3305 |
|
| 3306 |
TODO |
| 3307 |
|
| 3308 |
.. _select-slices-label-query: |
| 3309 |
|
| 3310 |
``slices[${LABEL}].query`` |
| 3311 |
"""""""""""""""""""""""""" |
| 3312 |
|
| 3313 |
TODO |
| 3314 |
|
| 3315 |
.. _select-slices-label-filter: |
| 3316 |
|
| 3317 |
``slices[${LABEL}].filter`` |
| 3318 |
""""""""""""""""""""""""""" |
| 3319 |
|
| 3320 |
TODO |
| 3321 |
|
| 3322 |
.. _select-slices-label-query-expander: |
| 3323 |
|
| 3324 |
``slices[${LABEL}].query_expander`` |
| 3325 |
""""""""""""""""""""""""""""""""""" |
| 3326 |
|
| 3327 |
TODO |
| 3328 |
|
| 3329 |
.. _select-slices-label-query-flags: |
| 3330 |
|
| 3331 |
``slices[${LABEL}].query_flags`` |
| 3332 |
"""""""""""""""""""""""""""""""" |
| 3333 |
|
| 3334 |
TODO |
| 3335 |
|
| 3336 |
.. _select-slices-label-sort-keys: |
| 3337 |
|
| 3338 |
``slices[${LABEL}].sort_keys`` |
| 3339 |
"""""""""""""""""""""""""""""" |
| 3340 |
|
| 3341 |
TODO |
| 3342 |
|
| 3343 |
.. _select-slices-label-output-columns: |
| 3344 |
|
| 3345 |
``slices[${LABEL}].output_columns`` |
| 3346 |
""""""""""""""""""""""""""""""""""" |
| 3347 |
|
| 3348 |
TODO |
| 3349 |
|
| 3350 |
.. _select-slices-label-offset: |
| 3351 |
|
| 3352 |
``slices[${LABEL}].offset`` |
| 3353 |
""""""""""""""""""""""""""" |
| 3354 |
|
| 3355 |
TODO |
| 3356 |
|
| 3357 |
.. _select-slices-label-limit: |
| 3358 |
|
| 3359 |
``slices[${LABEL}].limit`` |
| 3360 |
"""""""""""""""""""""""""" |
| 3361 |
|
| 3362 |
TODO |
| 3363 |
|
| 3364 |
Cache related parameter |
| 3365 |
^^^^^^^^^^^^^^^^^^^^^^^ |
| 3366 |
|
| 3367 |
.. _select-cache: |
| 3368 |
|
| 3369 |
``cache`` |
| 3370 |
""""""""" |
| 3371 |
|
| 3372 |
Specifies whether caching the result of this query or not. |
| 3373 |
|
| 3374 |
If the result of this query is cached, the next same query returns |
| 3375 |
response quickly by using the cache. |
| 3376 |
|
| 3377 |
It doesn't control whether existing cached result is used or not. |
| 3378 |
|
| 3379 |
Here are available values: |
| 3380 |
|
| 3381 |
.. list-table:: |
| 3382 |
:header-rows: 1 |
| 3383 |
|
| 3384 |
* - Value |
| 3385 |
- Description |
| 3386 |
* - ``no`` |
| 3387 |
- Don't cache the output of this query. |
| 3388 |
* - ``yes`` |
| 3389 |
- Cache the output of this query. |
| 3390 |
It's the default value. |
| 3391 |
|
| 3392 |
Here is an example to disable caching the result of this query: |
| 3393 |
|
| 3394 |
.. groonga-command |
| 3395 |
.. include:: ../../example/reference/commands/select/cache_no.log |
| 3396 |
.. select Entries --cache no |
| 3397 |
|
| 3398 |
The default value is ``yes``. |
| 3399 |
|
| 3400 |
Score related parameters |
| 3401 |
^^^^^^^^^^^^^^^^^^^^^^^^ |
| 3402 |
|
| 3403 |
There is a score related parameter, ``adjuster``. |
| 3404 |
|
| 3405 |
.. _select-adjuster: |
| 3406 |
|
| 3407 |
|
| 3408 |
``adjuster`` |
| 3409 |
"""""""""""" |
| 3410 |
|
| 3411 |
Specifies one or more score adjust expressions. You need to use |
| 3412 |
``adjuster`` with ``query`` or ``filter``. ``adjuster`` doesn't work |
| 3413 |
with not searched request. |
| 3414 |
|
| 3415 |
You can increase score of specific records by ``adjuster``. You can |
| 3416 |
use ``adjuster`` to set high score for important records. |
| 3417 |
|
| 3418 |
For example, you can use ``adjuster`` to increase score of records |
| 3419 |
that have ``groonga`` tag. |
| 3420 |
|
| 3421 |
Here is the syntax:: |
| 3422 |
|
| 3423 |
--adjuster "SCORE_ADJUST_EXPRESSION1 + SCORE_ADJUST_EXPRESSION2 + ..." |
| 3424 |
|
| 3425 |
Here is the ``SCORE_ADJUST_EXPRESSION`` syntax:: |
| 3426 |
|
| 3427 |
COLUMN @ "KEYWORD" * FACTOR |
| 3428 |
|
| 3429 |
Note the following: |
| 3430 |
|
| 3431 |
* ``COLUMN`` must be indexed. |
| 3432 |
* ``"KEYWORD"`` must be a string. |
| 3433 |
* ``FACTOR`` must be a positive integer. |
| 3434 |
|
| 3435 |
Here is a sample ``adjuster`` usage example that uses just one |
| 3436 |
``SCORE_ADJUST_EXPRESSION``: |
| 3437 |
|
| 3438 |
.. groonga-command |
| 3439 |
.. include:: ../../example/reference/commands/select/adjuster_one.log |
| 3440 |
.. select Entries \ |
| 3441 |
.. --filter true \ |
| 3442 |
.. --adjuster 'content @ "groonga" * 5' \ |
| 3443 |
.. --output_columns _key,content,_score |
| 3444 |
|
| 3445 |
The ``select`` command matches all records. Then it applies |
| 3446 |
``adjuster``. The adjuster increases score of records that have |
| 3447 |
``"groonga"`` in ``Entries.content`` column by 5. There is only one |
| 3448 |
record that has ``"groonga"`` in ``Entries.content`` column. So the |
| 3449 |
record that its key is ``"Groonga"`` has score 6 (``= 1 + 5``). |
| 3450 |
|
| 3451 |
You can omit ``FACTOR``. If you omit ``FACTOR``, it is treated as 1. |
| 3452 |
|
| 3453 |
Here is a sample ``adjuster`` usage example that omits ``FACTOR``: |
| 3454 |
|
| 3455 |
.. groonga-command |
| 3456 |
.. include:: ../../example/reference/commands/select/adjuster_no_factor.log |
| 3457 |
.. select Entries \ |
| 3458 |
.. --filter true \ |
| 3459 |
.. --adjuster 'content @ "groonga"' \ |
| 3460 |
.. --output_columns _key,content,_score |
| 3461 |
|
| 3462 |
The ``adjuster`` in the ``select`` command doesn't have ``FACTOR``. So |
| 3463 |
the factor is treated as 1. There is only one record that has |
| 3464 |
``"groonga"`` in ``Entries.content`` column. So the record that its |
| 3465 |
key is ``"Groonga"`` has score 2 (``= 1 + 1``). |
| 3466 |
|
| 3467 |
Here is a sample ``adjuster`` usage example that uses multiple |
| 3468 |
``SCORE_ADJUST_EXPRESSION``: |
| 3469 |
|
| 3470 |
.. groonga-command |
| 3471 |
.. include:: ../../example/reference/commands/select/adjuster_multiple.log |
| 3472 |
.. select Entries \ |
| 3473 |
.. --filter true \ |
| 3474 |
.. --adjuster 'content @ "groonga" * 5 + content @ "started" * 3' \ |
| 3475 |
.. --output_columns _key,content,_score |
| 3476 |
|
| 3477 |
The ``adjuster`` in the ``select`` command has two |
| 3478 |
``SCORE_ADJUST_EXPRESSION`` s. The final increased score is sum of |
| 3479 |
scores of these ``SCORE_ADJUST_EXPRESSION`` s. All |
| 3480 |
``SCORE_ADJUST_EXPRESSION`` s in the ``select`` command are applied to |
| 3481 |
a record that its key is ``"Groonga"``. So the final increased score |
| 3482 |
of the record is sum of scores of all ``SCORE_ADJUST_EXPRESSION`` s. |
| 3483 |
|
| 3484 |
The first ``SCORE_ADJUST_EXPRESSION`` is ``content @ "groonga" * 5``. |
| 3485 |
It increases score by 5. |
| 3486 |
|
| 3487 |
The second ``SCORE_ADJUST_EXPRESSION`` is ``content @ "started" * 3``. |
| 3488 |
It increases score by 3. |
| 3489 |
|
| 3490 |
The final increased score is 9 (``= 1 + 5 + 3``). |
| 3491 |
|
| 3492 |
A ``SCORE_ADJUST_EXPRESSION`` has a factor for ``"KEYWORD"``. This |
| 3493 |
means that increased scores of all records that has ``"KEYWORD"`` are |
| 3494 |
the same value. You can change increase score for each record that has |
| 3495 |
the same ``"KEYWORD"``. It is useful to tune search score. See |
| 3496 |
:ref:`weight-vector-column` for details. |
| 3497 |
|
| 3498 |
.. _select-return-value: |
| 3499 |
|
| 3500 |
Return value |
| 3501 |
------------ |
| 3502 |
|
| 3503 |
The command returns a response with the following format:: |
| 3504 |
|
| 3505 |
[ |
| 3506 |
HEADER, |
| 3507 |
[ |
| 3508 |
SEARCH_RESULT, |
| 3509 |
DRILLDOWN_RESULT_1, |
| 3510 |
DRILLDOWN_RESULT_2, |
| 3511 |
..., |
| 3512 |
DRILLDOWN_RESULT_N |
| 3513 |
] |
| 3514 |
] |
| 3515 |
|
| 3516 |
If the command fails, error details are in ``HEADER``. |
| 3517 |
|
| 3518 |
See :doc:`/reference/command/output_format` for ``HEADER``. |
| 3519 |
|
| 3520 |
There are zero or more ``DRILLDOWN_RESULT``. If no ``drilldown`` and |
| 3521 |
``drilldowns[${LABEL}].keys`` are specified, they are omitted like the |
| 3522 |
following:: |
| 3523 |
|
| 3524 |
[ |
| 3525 |
HEADER, |
| 3526 |
[ |
| 3527 |
SEARCH_RESULT |
| 3528 |
] |
| 3529 |
] |
| 3530 |
|
| 3531 |
If ``drilldown`` has two or more keys like ``--drilldown "_key, |
| 3532 |
column1, column2"``, multiple ``DRILLDOWN_RESULT`` exist:: |
| 3533 |
|
| 3534 |
[ |
| 3535 |
HEADER, |
| 3536 |
[ |
| 3537 |
SEARCH_RESULT, |
| 3538 |
DRILLDOWN_RESULT_FOR_KEY, |
| 3539 |
DRILLDOWN_RESULT_FOR_COLUMN1, |
| 3540 |
DRILLDOWN_RESULT_FOR_COLUMN2 |
| 3541 |
] |
| 3542 |
] |
| 3543 |
|
| 3544 |
If ``drilldowns[${LABEL}].keys`` is used, only one ``DRILLDOWN_RESULT`` |
| 3545 |
exist:: |
| 3546 |
|
| 3547 |
[ |
| 3548 |
HEADER, |
| 3549 |
[ |
| 3550 |
SEARCH_RESULT, |
| 3551 |
DRILLDOWN_RESULT_FOR_LABELED_DRILLDOWN |
| 3552 |
] |
| 3553 |
] |
| 3554 |
|
| 3555 |
``DRILLDOWN_RESULT`` format is different between ``drilldown`` and |
| 3556 |
``drilldowns[${LABEL}].keys``. It's described later. |
| 3557 |
|
| 3558 |
``SEARCH_RESULT`` is the following format:: |
| 3559 |
|
| 3560 |
[ |
| 3561 |
[N_HITS], |
| 3562 |
COLUMNS, |
| 3563 |
RECORDS |
| 3564 |
] |
| 3565 |
|
| 3566 |
See :ref:`select-simple-usage` for concrete example of the format. |
| 3567 |
|
| 3568 |
``N_HITS`` is the number of matched records before :ref:`select-limit` |
| 3569 |
is applied. |
| 3570 |
|
| 3571 |
``COLUMNS`` describes about output columns specified by |
| 3572 |
:ref:`select-output-columns`. It uses the following format:: |
| 3573 |
|
| 3574 |
[ |
| 3575 |
[COLUMN_NAME_1, COLUMN_TYPE_1], |
| 3576 |
[COLUMN_NAME_2, COLUMN_TYPE_2], |
| 3577 |
..., |
| 3578 |
[COLUMN_NAME_N, COLUMN_TYPE_N] |
| 3579 |
] |
| 3580 |
|
| 3581 |
``COLUMNS`` includes one or more output column information. Each |
| 3582 |
output column information includes the followings: |
| 3583 |
|
| 3584 |
* Column name as string |
| 3585 |
* Column type as string or ``null`` |
| 3586 |
|
| 3587 |
Column name is extracted from value specified as |
| 3588 |
:ref:`select-output-columns`. |
| 3589 |
|
| 3590 |
Column type is Groonga's type name or ``null``. It doesn't describe |
| 3591 |
whether the column value is vector or scalar. You need to determine it |
| 3592 |
by whether real column value is array or not. |
| 3593 |
|
| 3594 |
See :doc:`/reference/types` for type details. |
| 3595 |
|
| 3596 |
``null`` is used when column value type isn't determined. For example, |
| 3597 |
function call in :ref:`select-output-columns` such as |
| 3598 |
``--output_columns "snippet_html(content)"`` uses ``null``. |
| 3599 |
|
| 3600 |
Here is an example of ``COLUMNS``:: |
| 3601 |
|
| 3602 |
[ |
| 3603 |
["_id", "UInt32"], |
| 3604 |
["_key", "ShortText"], |
| 3605 |
["n_likes", "UInt32"], |
| 3606 |
] |
| 3607 |
|
| 3608 |
``RECORDS`` includes column values for each matched record. Included |
| 3609 |
records are selected by :ref:`select-offset` and |
| 3610 |
:ref:`select-limit`. It uses the following format:: |
| 3611 |
|
| 3612 |
[ |
| 3613 |
[ |
| 3614 |
RECORD_1_COLUMN_1, |
| 3615 |
RECORD_1_COLUMN_2, |
| 3616 |
..., |
| 3617 |
RECORD_1_COLUMN_N |
| 3618 |
], |
| 3619 |
[ |
| 3620 |
RECORD_2_COLUMN_1, |
| 3621 |
RECORD_2_COLUMN_2, |
| 3622 |
..., |
| 3623 |
RECORD_2_COLUMN_N |
| 3624 |
], |
| 3625 |
... |
| 3626 |
[ |
| 3627 |
RECORD_N_COLUMN_1, |
| 3628 |
RECORD_N_COLUMN_2, |
| 3629 |
..., |
| 3630 |
RECORD_N_COLUMN_N |
| 3631 |
] |
| 3632 |
] |
| 3633 |
|
| 3634 |
Here is an example ``RECORDS``:: |
| 3635 |
|
| 3636 |
[ |
| 3637 |
[ |
| 3638 |
1, |
| 3639 |
"The first post!", |
| 3640 |
5 |
| 3641 |
], |
| 3642 |
[ |
| 3643 |
2, |
| 3644 |
"Groonga", |
| 3645 |
10 |
| 3646 |
], |
| 3647 |
[ |
| 3648 |
3, |
| 3649 |
"Mroonga", |
| 3650 |
15 |
| 3651 |
] |
| 3652 |
] |
| 3653 |
|
| 3654 |
``DRILLDOWN_RESULT`` format is different between ``drilldown`` and |
| 3655 |
``drilldowns[${LABEL}].keys``. |
| 3656 |
|
| 3657 |
``drilldown`` uses the same format as ``SEARCH_RESULT``:: |
| 3658 |
|
| 3659 |
[ |
| 3660 |
[N_HITS], |
| 3661 |
COLUMNS, |
| 3662 |
RECORDS |
| 3663 |
] |
| 3664 |
|
| 3665 |
And ``drilldown`` generates one or more ``DRILLDOWN_RESULT`` when |
| 3666 |
:ref:`select-drilldown` has one ore more keys. |
| 3667 |
|
| 3668 |
``drilldowns[${LABEL}].keys`` uses the following format. Multiple |
| 3669 |
``drilldowns[${LABEL}].keys`` are mapped to one object (key-value |
| 3670 |
pairs):: |
| 3671 |
|
| 3672 |
{ |
| 3673 |
"LABEL_1": [ |
| 3674 |
[N_HITS], |
| 3675 |
COLUMNS, |
| 3676 |
RECORDS |
| 3677 |
], |
| 3678 |
"LABEL_2": [ |
| 3679 |
[N_HITS], |
| 3680 |
COLUMNS, |
| 3681 |
RECORDS |
| 3682 |
], |
| 3683 |
..., |
| 3684 |
"LABEL_N": [ |
| 3685 |
[N_HITS], |
| 3686 |
COLUMNS, |
| 3687 |
RECORDS |
| 3688 |
] |
| 3689 |
} |
| 3690 |
|
| 3691 |
Each ``drilldowns[${LABEL}].keys`` corresponds to the following:: |
| 3692 |
|
| 3693 |
"LABEL": [ |
| 3694 |
[N_HITS], |
| 3695 |
COLUMNS, |
| 3696 |
RECORDS |
| 3697 |
] |
| 3698 |
|
| 3699 |
The following value part is the same format as ``SEARCH_RESULT``:: |
| 3700 |
|
| 3701 |
[ |
| 3702 |
[N_HITS], |
| 3703 |
COLUMNS, |
| 3704 |
RECORDS |
| 3705 |
] |
| 3706 |
|
| 3707 |
See also :ref:`select-drilldowns-label-output-format` for |
| 3708 |
``drilldowns[${LABEL}]`` style drilldown output format. |
| 3709 |
|
| 3710 |
See also |
| 3711 |
-------- |
| 3712 |
|
| 3713 |
* :doc:`/reference/grn_expr/query_syntax` |
| 3714 |
* :doc:`/reference/grn_expr/script_syntax` |