| 1 |
.. -*- rst -*- |
| 2 |
|
| 3 |
.. groonga-command |
| 4 |
.. database: reference_grn_expr_script_syntax |
| 5 |
|
| 6 |
Script syntax |
| 7 |
============= |
| 8 |
|
| 9 |
Script syntax is a syntax to specify complex search condition. It is |
| 10 |
similar to ECMAScript. For example, ``_key == "book"`` means that |
| 11 |
groonga searches records that ``_key`` value is ``"book"``. All values |
| 12 |
are string in :doc:`query_syntax` but its own type in script |
| 13 |
syntax. For example, ``"book"`` is string, ``1`` is integer, |
| 14 |
``TokenBigram`` is the object whose name is ``TokenBigram`` and so on. |
| 15 |
|
| 16 |
Script syntax doesn't support full ECMAScript syntax. For example, |
| 17 |
script syntax doesn't support statement such as ``if`` control |
| 18 |
statement, ``for`` iteration statement and variable definition |
| 19 |
statement. Function definion is not supported too. But script syntax |
| 20 |
adds the original additional operators. They are described after |
| 21 |
ECMAScript syntax is described. |
| 22 |
|
| 23 |
.. _script-syntax-security: |
| 24 |
|
| 25 |
Security |
| 26 |
-------- |
| 27 |
|
| 28 |
For security reason, you should not pass an input from users to |
| 29 |
Groonga directly. If there is an evil user, the user may input a query |
| 30 |
that retrieves records that should not be shown to the user. |
| 31 |
|
| 32 |
Think about the following case. |
| 33 |
|
| 34 |
A Groonga application constructs a Groonga request by the following |
| 35 |
program:: |
| 36 |
|
| 37 |
filter = "column @ \"#{user_input}\"" |
| 38 |
select_options = { |
| 39 |
# ... |
| 40 |
:filter => filter, |
| 41 |
} |
| 42 |
groonga_client.select(select_options) |
| 43 |
|
| 44 |
``user_input`` is an input from user. If the input is ``query``, |
| 45 |
here is the constructed :ref:`select-filter` parameter:: |
| 46 |
|
| 47 |
column @ "query" |
| 48 |
|
| 49 |
If the input is ``x" || true || "``, here is the constructed |
| 50 |
:ref:`select-filter` parameter:: |
| 51 |
|
| 52 |
column @ "x" || true || "" |
| 53 |
|
| 54 |
This query matches to all records. The user will get all records from |
| 55 |
your database. The user may be evil. |
| 56 |
|
| 57 |
It's better that you just receive an user input as a value. It means |
| 58 |
that you don't accept that user input can contain operator such as |
| 59 |
``@`` and ``&&``. If you accept operator, user can create evil query. |
| 60 |
|
| 61 |
If user input has only value, you blocks evil query by escaping user |
| 62 |
input value. Here is a list how to escape user input value: |
| 63 |
|
| 64 |
* True value: Convert it to ``true``. |
| 65 |
* False value: Convert it to ``false``. |
| 66 |
* Numerical value: Convert it to :ref:`script-syntax-literal-integer` |
| 67 |
or :ref:`script-syntax-literal-float`. For example, ``1.2``, |
| 68 |
``-10``, ``314e-2`` and so on. |
| 69 |
* String value: Replace ``"`` with ``\"`` and ``\`` with ``\\`` in |
| 70 |
the string value and surround substituted string value by |
| 71 |
``"``. For example, ``double " quote and back \ slash`` should be |
| 72 |
converted to ``"double \" quote and back \\ slash"``. |
| 73 |
|
| 74 |
Sample data |
| 75 |
----------- |
| 76 |
|
| 77 |
Here are a schema definition and sample data to show usage. |
| 78 |
|
| 79 |
.. groonga-command |
| 80 |
.. include:: ../../example/reference/grn_expr/query_syntax/setup.log |
| 81 |
.. table_create Entries TABLE_PAT_KEY ShortText |
| 82 |
.. column_create Entries content COLUMN_SCALAR Text |
| 83 |
.. column_create Entries n_likes COLUMN_SCALAR UInt32 |
| 84 |
.. table_create Terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto |
| 85 |
.. column_create Terms entries_key_index COLUMN_INDEX|WITH_POSITION Entries _key |
| 86 |
.. column_create Terms entries_content_index COLUMN_INDEX|WITH_POSITION Entries content |
| 87 |
.. load --table Entries |
| 88 |
.. [ |
| 89 |
.. {"_key": "The first post!", |
| 90 |
.. "content": "Welcome! This is my first post!", |
| 91 |
.. "n_likes": 5}, |
| 92 |
.. {"_key": "Groonga", |
| 93 |
.. "content": "I started to use Groonga. It's very fast!", |
| 94 |
.. "n_likes": 10}, |
| 95 |
.. {"_key": "Mroonga", |
| 96 |
.. "content": "I also started to use Mroonga. It's also very fast! Really fast!", |
| 97 |
.. "n_likes": 15}, |
| 98 |
.. {"_key": "Good-bye Senna", |
| 99 |
.. "content": "I migrated all Senna system!", |
| 100 |
.. "n_likes": 3}, |
| 101 |
.. {"_key": "Good-bye Tritonn", |
| 102 |
.. "content": "I also migrated all Tritonn system!", |
| 103 |
.. "n_likes": 3} |
| 104 |
.. ] |
| 105 |
|
| 106 |
There is a table, ``Entries``, for blog entries. An entry has title, |
| 107 |
content and the number of likes for the entry. Title is key of |
| 108 |
``Entries``. Content is value of ``Entries.content`` column. The |
| 109 |
number of likes is value of ``Entries.n_likes`` column. |
| 110 |
|
| 111 |
``Entries._key`` column and ``Entries.content`` column are indexed |
| 112 |
using ``TokenBigram`` tokenizer. So both ``Entries._key`` and |
| 113 |
``Entries.content`` are fulltext search ready. |
| 114 |
|
| 115 |
OK. The schema and data for examples are ready. |
| 116 |
|
| 117 |
.. _script-syntax-literals: |
| 118 |
|
| 119 |
Literals |
| 120 |
-------- |
| 121 |
|
| 122 |
.. _script-syntax-literal-integer: |
| 123 |
|
| 124 |
Integer |
| 125 |
^^^^^^^ |
| 126 |
|
| 127 |
Integer literal is sequence of ``0`` to ``9`` such as |
| 128 |
``1234567890``. ``+`` or ``-`` can be prepended as sign such as |
| 129 |
``+29`` and ``-29``. Integer literal must be decimal. Octal notation, |
| 130 |
hex and so on can't be used. |
| 131 |
|
| 132 |
The maximum value of integer literal is ``9223372036854775807`` (``= 2 |
| 133 |
** 63 - 1``). The minimum value of integer literal is |
| 134 |
``-9223372036854775808`` (``= -(2 ** 63)``). |
| 135 |
|
| 136 |
.. _script-syntax-literal-float: |
| 137 |
|
| 138 |
Float |
| 139 |
^^^^^ |
| 140 |
|
| 141 |
Float literal is sequence of ``0`` to ``9``, ``.`` and ``0`` to ``9`` |
| 142 |
such as ``3.14``. ``+`` or ``-`` can be prepended as sign such as |
| 143 |
``+3.14`` and ``-3.14``. ``${RADIX}e${EXPORNENTIAL}`` and |
| 144 |
``${RADIX}E${EXPORNENTIAL}`` formats are also supported. For example, |
| 145 |
``314e-2`` is the same as ``3.14``. |
| 146 |
|
| 147 |
.. _script-syntax-literal-string: |
| 148 |
|
| 149 |
String |
| 150 |
^^^^^^ |
| 151 |
|
| 152 |
String literal is ``"..."``. You need to escape ``"`` in literal by |
| 153 |
prepending ``\`` such as ``\"``. For example, ``"Say \"Hello!\"."`` is |
| 154 |
a literal for ``Say "Hello!".`` string. |
| 155 |
|
| 156 |
String encoding must be the same as encoding of database. The default |
| 157 |
encoding is UTF-8. It can be changed by ``--with-default-encoding`` |
| 158 |
configure option, ``--encoding`` :doc:`/reference/executables/groonga` option |
| 159 |
and so on. |
| 160 |
|
| 161 |
.. _script-syntax-literal-boolean: |
| 162 |
|
| 163 |
Boolean |
| 164 |
^^^^^^^ |
| 165 |
|
| 166 |
Boolean literal is ``true`` and ``false``. ``true`` means true and |
| 167 |
``false`` means false. |
| 168 |
|
| 169 |
.. _script-syntax-literal-null: |
| 170 |
|
| 171 |
Null |
| 172 |
^^^^ |
| 173 |
|
| 174 |
Null literal is ``null``. Groonga doesn't support null value but null |
| 175 |
literal is supported. |
| 176 |
|
| 177 |
.. _script-syntax-literal-time: |
| 178 |
|
| 179 |
Time |
| 180 |
^^^^ |
| 181 |
|
| 182 |
.. note:: |
| 183 |
|
| 184 |
This is the groonga original notation. |
| 185 |
|
| 186 |
Time literal doesn't exit. There are string time notation, integer |
| 187 |
time notation and float time notation. |
| 188 |
|
| 189 |
String time notation is ``"YYYY/MM/DD hh:mm:ss.uuuuuu"`` or |
| 190 |
``"YYYY-MM-DD hh:mm:ss.uuuuuu"``. ``YYYY`` is year, ``MM`` is month, |
| 191 |
``DD`` is day, ``hh`` is hour, ``mm`` is minute, ``ss`` is second and |
| 192 |
``uuuuuu`` is micro second. It is local time. For example, |
| 193 |
``"2012/07/23 02:41:10.436218"`` is ``2012-07-23T02:41:10.436218`` in |
| 194 |
ISO 8601 format. |
| 195 |
|
| 196 |
Integer time notation is the number of seconds that have elapsed since |
| 197 |
midnight UTC, January 1, 1970. It is also known as POSIX time. For |
| 198 |
example, ``1343011270`` is ``2012-07-23T02:41:10Z`` in ISO 8601 format. |
| 199 |
|
| 200 |
Float time notation is the number of seconds and micro seconds that |
| 201 |
have elapsed since midnight UTC, January 1, 1970. For example, |
| 202 |
``1343011270.436218`` is ``2012-07-23T02:41:10.436218Z`` in ISO 8601 |
| 203 |
format. |
| 204 |
|
| 205 |
.. _script-syntax-literal-geo-point: |
| 206 |
|
| 207 |
Geo point |
| 208 |
^^^^^^^^^ |
| 209 |
|
| 210 |
.. note:: |
| 211 |
|
| 212 |
This is the groonga original notation. |
| 213 |
|
| 214 |
Geo point literal doesn't exist. There is string geo point notation. |
| 215 |
|
| 216 |
String geo point notation has the following patterns: |
| 217 |
|
| 218 |
* ``"LATITUDE_IN_MSECxLONGITUDE_IN_MSEC"`` |
| 219 |
* ``"LATITUDE_IN_MSEC,LONGITUDE_IN_MSEC"`` |
| 220 |
* ``"LATITUDE_IN_DEGREExLONGITUDE_IN_DEGREE"`` |
| 221 |
* ``"LATITUDE_IN_DEGREE,LONGITUDE_IN_DEGREE"`` |
| 222 |
|
| 223 |
``x`` and ``,`` can be used for separator. Latitude and longitude can |
| 224 |
be represented in milliseconds or degree. |
| 225 |
|
| 226 |
.. _script-syntax-literal-array: |
| 227 |
|
| 228 |
Array |
| 229 |
^^^^^ |
| 230 |
|
| 231 |
Array literal is ``[element1, element2, ...]``. |
| 232 |
|
| 233 |
.. _script-syntax-literal-object: |
| 234 |
|
| 235 |
Object literal |
| 236 |
^^^^^^^^^^^^^^ |
| 237 |
|
| 238 |
Object literal is ``{name1: value1, name2: value2, ...}``. Groonga |
| 239 |
doesn't support object literal yet. |
| 240 |
|
| 241 |
Control syntaxes |
| 242 |
---------------- |
| 243 |
|
| 244 |
Script syntax doesn't support statement. So you cannot use control |
| 245 |
statement such as ``if``. You can only use ``A ? B : C`` expression as |
| 246 |
control syntax. |
| 247 |
|
| 248 |
``A ? B : C`` returns ``B`` if ``A`` is true, ``C`` otherwise. |
| 249 |
|
| 250 |
Here is a simple example: |
| 251 |
|
| 252 |
.. groonga-command |
| 253 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_control_syntax_ternary_operator.log |
| 254 |
.. select Entries --filter 'n_likes == (_id == 1 ? 5 : 3)' |
| 255 |
|
| 256 |
The expression matches records that ``_id`` column value is equal to ``1`` |
| 257 |
and ``n_likes`` column value is equal to ``5`` or ``_id`` column value is |
| 258 |
not equal to 1 and ``n_likes`` column value is equal to ``3``. |
| 259 |
|
| 260 |
Grouping |
| 261 |
-------- |
| 262 |
|
| 263 |
Its syntax is ``(...)``. ``...`` is comma separated expression list. |
| 264 |
|
| 265 |
``(...)`` groups one ore more expressions and they can be processed as |
| 266 |
an expression. ``a && b || c`` means that ``a`` and ``b`` are matched |
| 267 |
or ``c`` is matched. ``a && (b || c)`` means that ``a`` and one of |
| 268 |
``b`` and ``c`` are matched. |
| 269 |
|
| 270 |
Here is a simple example: |
| 271 |
|
| 272 |
.. groonga-command |
| 273 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_grouping.log |
| 274 |
.. select Entries --filter 'n_likes < 5 && content @ "senna" || content @ "fast"' |
| 275 |
.. select Entries --filter 'n_likes < 5 && (content @ "senna" || content @ "fast")' |
| 276 |
|
| 277 |
The first expression doesn't use grouping. It matches records that |
| 278 |
``n_likes < 5`` and ``content @ "senna"`` are matched or |
| 279 |
``content @ "fast"`` is matched. |
| 280 |
|
| 281 |
The second expression uses grouping. It matches records that ``n_likes |
| 282 |
< 5`` and one of ``content @ "senna"`` or ``content @ "fast"`` are |
| 283 |
matched. |
| 284 |
|
| 285 |
Function call |
| 286 |
------------- |
| 287 |
|
| 288 |
Its syntax is ``name(argument1, argument2, ...)``. |
| 289 |
|
| 290 |
``name(argument1, argument2, ...)`` calls a function that is named |
| 291 |
``name`` with arguments ``argument1``, ``argument2`` and ``...``. |
| 292 |
|
| 293 |
See :doc:`/reference/function` for available function list. |
| 294 |
|
| 295 |
Here is a simple example: |
| 296 |
|
| 297 |
.. groonga-command |
| 298 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_function.log |
| 299 |
.. select Entries --filter 'edit_distance(_key, "Groonga") <= 1' |
| 300 |
|
| 301 |
The expression uses :doc:`/reference/functions/edit_distance`. It |
| 302 |
matches records that ``_key`` column value is similar to |
| 303 |
``"Groonga"``. Similarity of ``"Groonga"`` is computed as edit |
| 304 |
distance. If edit distance is less than or equal to 1, the value is |
| 305 |
treated as similar. In this case, ``"Groonga"`` and ``"Mroonga"`` are |
| 306 |
treated as similar. |
| 307 |
|
| 308 |
Basic operators |
| 309 |
--------------- |
| 310 |
|
| 311 |
Groonga supports operators defined in ECMAScript. |
| 312 |
|
| 313 |
Arithmetic operators |
| 314 |
^^^^^^^^^^^^^^^^^^^^ |
| 315 |
|
| 316 |
Here are arithmetic operators. |
| 317 |
|
| 318 |
Addition operator |
| 319 |
""""""""""""""""" |
| 320 |
|
| 321 |
Its syntax is ``number1 + number2``. |
| 322 |
|
| 323 |
The operator adds ``number1`` and ``number2`` and returns the result. |
| 324 |
|
| 325 |
Here is a simple example: |
| 326 |
|
| 327 |
.. groonga-command |
| 328 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_addition_operator.log |
| 329 |
.. select Entries --filter 'n_likes == 10 + 5' |
| 330 |
|
| 331 |
The expression matches records that ``n_likes`` column value is equal |
| 332 |
to ``15`` (= ``10 + 5``). |
| 333 |
|
| 334 |
Subtraction operator |
| 335 |
"""""""""""""""""""" |
| 336 |
|
| 337 |
Its syntax is ``number1 - number2``. |
| 338 |
|
| 339 |
The operator subtracts ``number2`` from ``number1`` and returns the result. |
| 340 |
|
| 341 |
Here is a simple example: |
| 342 |
|
| 343 |
.. groonga-command |
| 344 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_subtraction_operator.log |
| 345 |
.. select Entries --filter 'n_likes == 20 - 5' |
| 346 |
|
| 347 |
The expression matches records that ``n_likes`` column value is equal |
| 348 |
to ``15`` (= ``20 - 5``). |
| 349 |
|
| 350 |
Multiplication operator |
| 351 |
""""""""""""""""""""""" |
| 352 |
|
| 353 |
Its syntax is ``number1 * number2``. |
| 354 |
|
| 355 |
The operator multiplies ``number1`` and ``number2`` and returns the result. |
| 356 |
|
| 357 |
Here is a simple example: |
| 358 |
|
| 359 |
.. groonga-command |
| 360 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_multiplication_operator.log |
| 361 |
.. select Entries --filter 'n_likes == 3 * 5' |
| 362 |
|
| 363 |
The expression matches records that ``n_likes`` column value is equal |
| 364 |
to ``15`` (= ``3 * 5``). |
| 365 |
|
| 366 |
Division operator |
| 367 |
""""""""""""""""" |
| 368 |
|
| 369 |
Its syntax is ``number1 / number2`` and ``number1 % number2``. |
| 370 |
|
| 371 |
The operator divides ``number2`` by ``number1``. ``/`` returns the |
| 372 |
quotient of result. ``%`` returns the remainder of result. |
| 373 |
|
| 374 |
Here is simple examples. |
| 375 |
|
| 376 |
.. groonga-command |
| 377 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_division_operator_quotient.log |
| 378 |
.. select Entries --filter 'n_likes == 26 / 7' |
| 379 |
|
| 380 |
The expression matches records that ``n_likes`` column value is equal |
| 381 |
to ``3`` (= ``26 / 7``). |
| 382 |
|
| 383 |
.. groonga-command |
| 384 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_division_operator_remainder.log |
| 385 |
.. select Entries --filter 'n_likes == 26 % 7' |
| 386 |
|
| 387 |
The expression matches records that ``n_likes`` column value is equal |
| 388 |
to ``5`` (= ``26 % 7``). |
| 389 |
|
| 390 |
Logical operators |
| 391 |
^^^^^^^^^^^^^^^^^ |
| 392 |
|
| 393 |
Here are logical operators. |
| 394 |
|
| 395 |
Logical NOT operator |
| 396 |
"""""""""""""""""""" |
| 397 |
|
| 398 |
Its syntax is ``!condition``. |
| 399 |
|
| 400 |
The operator inverts boolean value of ``condition``. |
| 401 |
|
| 402 |
Here is a simple example: |
| 403 |
|
| 404 |
.. groonga-command |
| 405 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_logical_not_operator.log |
| 406 |
.. select Entries --filter '!(n_likes == 5)' |
| 407 |
|
| 408 |
The expression matches records that ``n_likes`` column value is not |
| 409 |
equal to ``5``. |
| 410 |
|
| 411 |
Logical AND operator |
| 412 |
"""""""""""""""""""" |
| 413 |
|
| 414 |
Its syntax is ``condition1 && condition2``. |
| 415 |
|
| 416 |
The operator returns true if both of ``condition1`` and |
| 417 |
``condition2`` are true, false otherwise. |
| 418 |
|
| 419 |
Here is a simple example: |
| 420 |
|
| 421 |
.. groonga-command |
| 422 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_logical_and_operator.log |
| 423 |
.. select Entries --filter 'content @ "fast" && n_likes >= 10' |
| 424 |
|
| 425 |
The expression matches records that ``content`` column value has the |
| 426 |
word ``fast`` and ``n_likes`` column value is greater or equal to |
| 427 |
``10``. |
| 428 |
|
| 429 |
Logical OR operator |
| 430 |
""""""""""""""""""" |
| 431 |
|
| 432 |
Its syntax is ``condition1 || condition2``. |
| 433 |
|
| 434 |
The operator returns true if either ``condition1`` or ``condition2`` is |
| 435 |
true, false otherwise. |
| 436 |
|
| 437 |
Here is a simple example: |
| 438 |
|
| 439 |
.. groonga-command |
| 440 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_logical_or_operator.log |
| 441 |
.. select Entries --filter 'n_likes == 5 || n_likes == 10' |
| 442 |
|
| 443 |
The expression matches records that ``n_likes`` column value is equal |
| 444 |
to ``5`` or ``10``. |
| 445 |
|
| 446 |
Logical AND NOT operator |
| 447 |
"""""""""""""""""""""""" |
| 448 |
|
| 449 |
Its syntax is ``condition1 &! condition2``. |
| 450 |
|
| 451 |
The operator returns true if ``condition1`` is true but ``condition2`` |
| 452 |
is false, false otherwise. It returns difference set. |
| 453 |
|
| 454 |
Here is a simple example: |
| 455 |
|
| 456 |
.. groonga-command |
| 457 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_logical_but_operator.log |
| 458 |
.. select Entries --filter 'content @ "fast" &! content @ "mroonga"' |
| 459 |
|
| 460 |
The expression matches records that ``content`` column value has the |
| 461 |
word ``fast`` but doesn't have the word ``mroonga``. |
| 462 |
|
| 463 |
.. _script-syntax-bitwise-operators: |
| 464 |
|
| 465 |
Bitwise operators |
| 466 |
^^^^^^^^^^^^^^^^^ |
| 467 |
|
| 468 |
Here are bitwise operators. |
| 469 |
|
| 470 |
.. _script-syntax-bitwise-not: |
| 471 |
|
| 472 |
Bitwise NOT operator |
| 473 |
"""""""""""""""""""" |
| 474 |
|
| 475 |
Its syntax is ``~number``. |
| 476 |
|
| 477 |
The operator returns bitwise NOT of ``number``. |
| 478 |
|
| 479 |
Here is a simple example: |
| 480 |
|
| 481 |
.. groonga-command |
| 482 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_bitwise_not_operator.log |
| 483 |
.. select Entries --filter '~n_likes == -6' |
| 484 |
|
| 485 |
The expression matches records that ``n_likes`` column value is equal |
| 486 |
to ``5`` because bitwise NOT of ``5`` is equal to ``-6``. |
| 487 |
|
| 488 |
.. _script-syntax-bitwise-and: |
| 489 |
|
| 490 |
Bitwise AND operator |
| 491 |
"""""""""""""""""""" |
| 492 |
|
| 493 |
Its syntax is ``number1 & number2``. |
| 494 |
|
| 495 |
The operator returns bitwise AND between ``number1`` and ``number2``. |
| 496 |
|
| 497 |
Here is a simple example: |
| 498 |
|
| 499 |
.. groonga-command |
| 500 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_bitwise_and_operator.log |
| 501 |
.. select Entries --filter '(n_likes & 1) == 1' |
| 502 |
|
| 503 |
The expression matches records that ``n_likes`` column value is even |
| 504 |
number because bitwise AND between an even number and ``1`` is equal |
| 505 |
to ``1`` and bitwise AND between an odd number and ``1`` is equal to |
| 506 |
``0``. |
| 507 |
|
| 508 |
.. _script-syntax-bitwise-or: |
| 509 |
|
| 510 |
Bitwise OR operator |
| 511 |
^^^^^^^^^^^^^^^^^^^ |
| 512 |
|
| 513 |
Its syntax is ``number1 | number2``. |
| 514 |
|
| 515 |
The operator returns bitwise OR between ``number1`` and ``number2``. |
| 516 |
|
| 517 |
Here is a simple example: |
| 518 |
|
| 519 |
.. groonga-command |
| 520 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_bitwise_or_operator.log |
| 521 |
.. select Entries --filter 'n_likes == (1 | 4)' |
| 522 |
|
| 523 |
The expression matches records that ``n_likes`` column value is equal |
| 524 |
to ``5`` (= ``1 | 4``). |
| 525 |
|
| 526 |
.. _script-syntax-bitwise-xor: |
| 527 |
|
| 528 |
Bitwise XOR operator |
| 529 |
^^^^^^^^^^^^^^^^^^^^ |
| 530 |
|
| 531 |
Its syntax is ``number1 ^ number2``. |
| 532 |
|
| 533 |
The operator returns bitwise XOR between ``number1`` and ``number2``. |
| 534 |
|
| 535 |
Here is a simple example: |
| 536 |
|
| 537 |
.. groonga-command |
| 538 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_bitwise_xor_operator.log |
| 539 |
.. select Entries --filter 'n_likes == (10 ^ 15)' |
| 540 |
|
| 541 |
The expression matches records that ``n_likes`` column value is equal |
| 542 |
to ``5`` (= ``10 ^ 15``). |
| 543 |
|
| 544 |
.. _script-syntax-shift-operators: |
| 545 |
|
| 546 |
Shift operators |
| 547 |
^^^^^^^^^^^^^^^ |
| 548 |
|
| 549 |
Here are shift operators. |
| 550 |
|
| 551 |
.. _script-syntax-shift-left: |
| 552 |
|
| 553 |
Left shift operator |
| 554 |
""""""""""""""""""" |
| 555 |
|
| 556 |
Its syntax is ``number1 << number2``. |
| 557 |
|
| 558 |
The operator performs a bitwise left shift operation on ``number1`` by |
| 559 |
``number2``. |
| 560 |
|
| 561 |
Here is a simple example: |
| 562 |
|
| 563 |
.. groonga-command |
| 564 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_left_shift_operator.log |
| 565 |
.. select Entries --filter 'n_likes == (5 << 1)' |
| 566 |
|
| 567 |
The expression matches records that ``n_likes`` column value is equal |
| 568 |
to ``10`` (= ``5 << 1``). |
| 569 |
|
| 570 |
.. _script-syntax-shift-signed-right: |
| 571 |
|
| 572 |
Signed right shift operator |
| 573 |
""""""""""""""""""""""""""" |
| 574 |
|
| 575 |
Its syntax is ``number1 >> number2``. |
| 576 |
|
| 577 |
The operator shifts bits of ``number1`` to right by ``number2``. The sign |
| 578 |
of the result is the same as ``number1``. |
| 579 |
|
| 580 |
Here is a simple example: |
| 581 |
|
| 582 |
.. groonga-command |
| 583 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_signed_right_shift_operator.log |
| 584 |
.. select Entries --filter 'n_likes == -(-10 >> 1)' |
| 585 |
|
| 586 |
The expression matches records that ``n_likes`` column value is equal |
| 587 |
to ``5`` (= ``-(-10 >> 1)`` = ``-(-5)``). |
| 588 |
|
| 589 |
.. _script-syntax-shift-unsigned-right: |
| 590 |
|
| 591 |
Unsigned right shift operator |
| 592 |
""""""""""""""""""""""""""""" |
| 593 |
|
| 594 |
Its syntax is ``number1 >>> number2``. |
| 595 |
|
| 596 |
The operator shifts bits of ``number1`` to right by ``number2``. The |
| 597 |
leftmost ``number2`` bits are filled by ``0``. |
| 598 |
|
| 599 |
Here is a simple example: |
| 600 |
|
| 601 |
.. groonga-command |
| 602 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_unsigned_right_shift_operator.log |
| 603 |
.. select Entries --filter 'n_likes == (2147483648 - (-10 >>> 1))' |
| 604 |
|
| 605 |
The expression matches records that ``n_likes`` column value is equal |
| 606 |
to ``5`` (= ``2147483648 - (-10 >>> 1)`` = ``2147483648 - 2147483643``). |
| 607 |
|
| 608 |
Comparison operators |
| 609 |
^^^^^^^^^^^^^^^^^^^^ |
| 610 |
|
| 611 |
Here are comparison operators. |
| 612 |
|
| 613 |
.. _script-syntax-equal-operator: |
| 614 |
|
| 615 |
Equal operator |
| 616 |
"""""""""""""" |
| 617 |
|
| 618 |
Its syntax is ``object1 == object2``. |
| 619 |
|
| 620 |
The operator returns true if ``object1`` equals to ``object2``, false |
| 621 |
otherwise. |
| 622 |
|
| 623 |
Here is a simple example: |
| 624 |
|
| 625 |
.. groonga-command |
| 626 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_equal_operator.log |
| 627 |
.. select Entries --filter 'n_likes == 5' |
| 628 |
|
| 629 |
The expression matches records that ``n_likes`` column value is equal |
| 630 |
to ``5``. |
| 631 |
|
| 632 |
Not equal operator |
| 633 |
"""""""""""""""""" |
| 634 |
|
| 635 |
Its syntax is ``object1 != object2``. |
| 636 |
|
| 637 |
The operator returns true if ``object1`` does not equal to |
| 638 |
``object2``, false otherwise. |
| 639 |
|
| 640 |
Here is a simple example: |
| 641 |
|
| 642 |
.. groonga-command |
| 643 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_not_equal_operator.log |
| 644 |
.. select Entries --filter 'n_likes != 5' |
| 645 |
|
| 646 |
The expression matches records that ``n_likes`` column value is not |
| 647 |
equal to ``5``. |
| 648 |
|
| 649 |
Less than operator |
| 650 |
"""""""""""""""""" |
| 651 |
|
| 652 |
TODO: ... |
| 653 |
|
| 654 |
Less than or equal to operator |
| 655 |
"""""""""""""""""""""""""""""" |
| 656 |
|
| 657 |
TODO: ... |
| 658 |
|
| 659 |
Greater than operator |
| 660 |
""""""""""""""""""""" |
| 661 |
|
| 662 |
TODO: ... |
| 663 |
|
| 664 |
Greater than or equal to operator |
| 665 |
""""""""""""""""""""""""""""""""" |
| 666 |
|
| 667 |
TODO: ... |
| 668 |
|
| 669 |
Assignment operators |
| 670 |
-------------------- |
| 671 |
|
| 672 |
|
| 673 |
Addition assignment operator |
| 674 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 675 |
|
| 676 |
Its syntax is ``column1 += column2``. |
| 677 |
|
| 678 |
The operator performs addition assignment operation on column1 by column2. |
| 679 |
|
| 680 |
.. groonga-command |
| 681 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_addition_assignment_operator.log |
| 682 |
.. select Entries --output_columns _key,n_likes,_score --filter true --scorer '_score += n_likes' |
| 683 |
|
| 684 |
The value of ``_score`` by ``--filter`` is always 1 in this case, |
| 685 |
then performs addition assignment operation such as '_score = _score + n_likes' for each records. |
| 686 |
|
| 687 |
For example, the value of ``_score`` about the record which stores "Good-bye Senna" as the ``_key`` |
| 688 |
is 3. |
| 689 |
|
| 690 |
So the expression ``1 + 3`` is evaluated and stored to ``_score`` column as the execution result. |
| 691 |
|
| 692 |
Subtraction assignment operator |
| 693 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 694 |
|
| 695 |
Its syntax is ``column1 -= column2``. |
| 696 |
|
| 697 |
The operator performs subtraction assignment operation on column1 by column2. |
| 698 |
|
| 699 |
.. groonga-command |
| 700 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_subtraction_assignment_operator.log |
| 701 |
.. select Entries --output_columns _key,n_likes,_score --filter true --scorer '_score -= n_likes' |
| 702 |
|
| 703 |
The value of ``_score`` by ``--filter`` is always 1 in this case, |
| 704 |
then performs subtraction assignment operation such as '_score = _score - n_likes' for each records. |
| 705 |
|
| 706 |
For example, the value of ``_score`` about the record which stores "Good-bye Senna" as the ``_key`` |
| 707 |
is 3. |
| 708 |
|
| 709 |
So the expression ``1 - 3`` is evaluated and stored to ``_score`` column as the execution result. |
| 710 |
|
| 711 |
Multiplication assignment operator |
| 712 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 713 |
|
| 714 |
Its syntax is ``column1 *= column2``. |
| 715 |
|
| 716 |
The operator performs multiplication assignment operation on column1 by column2. |
| 717 |
|
| 718 |
.. groonga-command |
| 719 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_multiplication_assignment_operator.log |
| 720 |
.. select Entries --output_columns _key,n_likes,_score --filter true --scorer '_score *= n_likes' |
| 721 |
|
| 722 |
The value of ``_score`` by ``--filter`` is always 1 in this case, |
| 723 |
then performs subtraction assignment operation such as '_score = _score * n_likes' for each records. |
| 724 |
|
| 725 |
For example, the value of ``_score`` about the record which stores "Good-bye Senna" as the ``_key`` |
| 726 |
is 3. |
| 727 |
|
| 728 |
So the expression ``1 * 3`` is evaluated and stored to ``_score`` column as the execution result. |
| 729 |
|
| 730 |
Division assignment operator |
| 731 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 732 |
|
| 733 |
Its syntax is ``column1 /= column2``. |
| 734 |
|
| 735 |
The operator performs division assignment operation on column1 by column2. |
| 736 |
|
| 737 |
.. groonga-command |
| 738 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_division_assignment_operator.log |
| 739 |
.. select Entries --output_columns _key,n_likes,_score --filter true --scorer '_score /= n_likes' |
| 740 |
|
| 741 |
The value of ``_score`` by ``--filter`` is always 1 in this case, |
| 742 |
then performs subtraction assignment operation such as '_score = _score / n_likes' for each records. |
| 743 |
|
| 744 |
For example, the value of ``_score`` about the record which stores "Good-bye Senna" as the ``_key`` |
| 745 |
is 3. |
| 746 |
|
| 747 |
So the expression ``1 / 3`` is evaluated and stored to ``_score`` column as the execution result. |
| 748 |
|
| 749 |
Modulo assignment operator |
| 750 |
^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 751 |
|
| 752 |
Its syntax is ``column1 %= column2``. |
| 753 |
|
| 754 |
The operator performs modulo assignment operation on column1 by column2. |
| 755 |
|
| 756 |
.. groonga-command |
| 757 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_modulo_assignment_operator.log |
| 758 |
.. select Entries --output_columns _key,n_likes,_score --filter true --scorer '_score %= n_likes' |
| 759 |
|
| 760 |
The value of ``_score`` by ``--filter`` is always 1 in this case, |
| 761 |
then performs subtraction assignment operation such as '_score = _score % n_likes' for each records. |
| 762 |
|
| 763 |
For example, the value of ``_score`` about the record which stores "Good-bye Senna" as the ``_key`` |
| 764 |
is 3. |
| 765 |
|
| 766 |
So the expression ``1 % 3`` is evaluated and stored to ``_score`` column as the execution result. |
| 767 |
|
| 768 |
Bitwise left shift assignment operator |
| 769 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 770 |
|
| 771 |
Its syntax is ``column1 <<= column2``. |
| 772 |
|
| 773 |
The operator performs left shift assignment operation on column1 by column2. |
| 774 |
|
| 775 |
.. groonga-command |
| 776 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_left_shift_assignment_operator.log |
| 777 |
.. select Entries --output_columns _key,n_likes,_score --filter true --scorer '_score <<= n_likes' |
| 778 |
|
| 779 |
The value of ``_score`` by ``--filter`` is always 1 in this case, |
| 780 |
then performs subtraction assignment operation such as '_score = _score << n_likes' for each records. |
| 781 |
|
| 782 |
For example, the value of ``_score`` about the record which stores "Good-bye Senna" as the ``_key`` |
| 783 |
is 3. |
| 784 |
|
| 785 |
So the expression ``1 << 3`` is evaluated and stored to ``_score`` column as the execution result. |
| 786 |
|
| 787 |
Bitwise signed right shift assignment operator |
| 788 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 789 |
|
| 790 |
Its syntax is ``column2 >>= column2``. |
| 791 |
|
| 792 |
The operator performs signed right shift assignment operation on column1 by column2. |
| 793 |
|
| 794 |
Bitwise unsigned right shift assignment operator |
| 795 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 796 |
|
| 797 |
Its syntax is ``column1 >>>= column2``. |
| 798 |
|
| 799 |
The operator performs unsigned right shift assignment operation on column1 by column2. |
| 800 |
|
| 801 |
Bitwise AND assignment operator |
| 802 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 803 |
|
| 804 |
Its syntax is ``column1 &= column2``. |
| 805 |
|
| 806 |
The operator performs bitwise AND assignment operation on column1 by column2. |
| 807 |
|
| 808 |
.. groonga-command |
| 809 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_and_assignment_operator.log |
| 810 |
.. select Entries --output_columns _key,n_likes,_score --filter true --scorer '_score &= n_likes' |
| 811 |
|
| 812 |
The value of ``_score`` by ``--filter`` is always 1 in this case, |
| 813 |
then performs subtraction assignment operation such as '_score = _score & n_likes' for each records. |
| 814 |
|
| 815 |
For example, the value of ``_score`` about the record which stores "Groonga" as the ``_key`` |
| 816 |
is 10. |
| 817 |
|
| 818 |
So the expression ``1 & 10`` is evaluated and stored to ``_score`` column as the execution result. |
| 819 |
|
| 820 |
.. _script-syntax-bitwise-or-assign: |
| 821 |
|
| 822 |
Bitwise OR assignment operator |
| 823 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 824 |
|
| 825 |
Its syntax is ``column1 |= column2``. |
| 826 |
|
| 827 |
The operator performs bitwise OR assignment operation on column1 by column2. |
| 828 |
|
| 829 |
.. groonga-command |
| 830 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_or_assignment_operator.log |
| 831 |
.. select Entries --output_columns _key,n_likes,_score --filter true --scorer '_score |= n_likes' |
| 832 |
|
| 833 |
The value of ``_score`` by ``--filter`` is always 1 in this case, |
| 834 |
then performs subtraction assignment operation such as '_score = _score | n_likes' for each records. |
| 835 |
|
| 836 |
For example, the value of ``_score`` about the record which stores "Groonga" as the ``_key`` |
| 837 |
is 10. |
| 838 |
|
| 839 |
So the expression ``1 | 10`` is evaluated and stored to ``_score`` column as the execution result. |
| 840 |
|
| 841 |
Bitwise XOR assignment operator |
| 842 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 843 |
|
| 844 |
Its syntax is ``column1 ^= column2``. |
| 845 |
|
| 846 |
The operator performs bitwise XOR assignment operation on column1 by column2. |
| 847 |
|
| 848 |
.. groonga-command |
| 849 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_xor_assignment_operator.log |
| 850 |
.. select Entries --output_columns _key,n_likes,_score --filter true --scorer '_score ^= n_likes' |
| 851 |
|
| 852 |
The value of ``_score`` by ``--filter`` is always 1 in this case, |
| 853 |
then performs subtraction assignment operation such as '_score = _score ^ n_likes' for each records. |
| 854 |
|
| 855 |
For example, the value of ``_score`` about the record which stores "Good-bye Senna" as the ``_key`` |
| 856 |
is 3. |
| 857 |
|
| 858 |
So the expression ``1 ^ 3`` is evaluated and stored to ``_score`` column as the execution result. |
| 859 |
|
| 860 |
Original operators |
| 861 |
------------------ |
| 862 |
|
| 863 |
Script syntax adds the original binary operators to ECMAScript |
| 864 |
syntax. They operate search specific operations. They are starts with |
| 865 |
``@`` or ``*``. |
| 866 |
|
| 867 |
.. _script-syntax-match-operator: |
| 868 |
|
| 869 |
Match operator |
| 870 |
^^^^^^^^^^^^^^ |
| 871 |
|
| 872 |
Its syntax is ``column @ value``. |
| 873 |
|
| 874 |
The operator searches ``value`` by inverted index of ``column``. |
| 875 |
Normally, full text search is operated but tag search can be operated. |
| 876 |
Because tag search is also implemented by inverted index. |
| 877 |
|
| 878 |
:doc:`query_syntax` uses this operator by default. |
| 879 |
|
| 880 |
Here is a simple example: |
| 881 |
|
| 882 |
.. groonga-command |
| 883 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_match_operator.log |
| 884 |
.. select Entries --filter 'content @ "fast"' --output_columns content |
| 885 |
|
| 886 |
The expression matches records that contain a word ``fast`` in |
| 887 |
``content`` column value. |
| 888 |
|
| 889 |
.. _script-syntax-prefix-search-operator: |
| 890 |
|
| 891 |
Prefix search operator |
| 892 |
^^^^^^^^^^^^^^^^^^^^^^ |
| 893 |
|
| 894 |
Its syntax is ``column @^ value``. |
| 895 |
|
| 896 |
The operator does prefix search with ``value``. Prefix search searches |
| 897 |
records that contain a word that starts with ``value``. |
| 898 |
|
| 899 |
You can use fast prefix search against a column. The column must be |
| 900 |
indexed and index table must be patricia trie table |
| 901 |
(``TABLE_PAT_KEY``) or double array trie table |
| 902 |
(``TABLE_DAT_KEY``). You can also use fast prefix search against |
| 903 |
``_key`` pseudo column of patricia trie table or double array trie |
| 904 |
table. You don't need to index ``_key``. |
| 905 |
|
| 906 |
Prefix search can be used with other table types but it causes all |
| 907 |
records scan. It's not problem for small records but it spends more |
| 908 |
time for large records. |
| 909 |
|
| 910 |
Here is a simple example: |
| 911 |
|
| 912 |
.. groonga-command |
| 913 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_prefix_search_operator.log |
| 914 |
.. select Entries --filter '_key @^ "Goo"' --output_columns _key |
| 915 |
|
| 916 |
The expression matches records that contain a word that starts with |
| 917 |
``Goo`` in ``_key`` pseudo column value. ``Good-bye Senna`` and |
| 918 |
``Good-bye Tritonn`` are matched with the expression. |
| 919 |
|
| 920 |
.. _script-syntax-suffix-search-operator: |
| 921 |
|
| 922 |
Suffix search operator |
| 923 |
^^^^^^^^^^^^^^^^^^^^^^ |
| 924 |
|
| 925 |
Its syntax is ``column @$ value``. |
| 926 |
|
| 927 |
This operator does suffix search with ``value``. Suffix search |
| 928 |
searches records that contain a word that ends with ``value``. |
| 929 |
|
| 930 |
You can use fast suffix search against a column. The column must be |
| 931 |
indexed and index table must be patricia trie table |
| 932 |
(``TABLE_PAT_KEY``) with ``KEY_WITH_SIS`` flag. You can also use fast |
| 933 |
suffix search against ``_key`` pseudo column of patricia trie table |
| 934 |
(``TABLE_PAT_KEY``) with ``KEY_WITH_SIS`` flag. You don't need to |
| 935 |
index ``_key``. We recommended that you use index column based fast |
| 936 |
suffix search instead of ``_key`` based fast suffix search. ``_key`` |
| 937 |
based fast suffix search returns automatically registered |
| 938 |
substrings. (TODO: write document about suffix search and link to it |
| 939 |
from here.) |
| 940 |
|
| 941 |
.. note:: |
| 942 |
|
| 943 |
Fast suffix search can be used only for non-ASCII characters such |
| 944 |
as hiragana in Japanese. You cannot use fast suffix search for |
| 945 |
ASCII character. |
| 946 |
|
| 947 |
Suffix search can be used with other table types or patricia trie |
| 948 |
table without ``KEY_WITH_SIS`` flag but it causes all records |
| 949 |
scan. It's not problem for small records but it spends more time for |
| 950 |
large records. |
| 951 |
|
| 952 |
Here is a simple example. It uses fast suffix search for hiragana in |
| 953 |
Japanese that is one of non-ASCII characters. |
| 954 |
|
| 955 |
.. groonga-command |
| 956 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_suffix_search_operator.log |
| 957 |
.. table_create Titles TABLE_NO_KEY |
| 958 |
.. column_create Titles content COLUMN_SCALAR ShortText |
| 959 |
.. table_create SuffixSearchTerms TABLE_PAT_KEY|KEY_WITH_SIS ShortText |
| 960 |
.. column_create SuffixSearchTerms index COLUMN_INDEX Titles content |
| 961 |
.. load --table Titles |
| 962 |
.. [ |
| 963 |
.. {"content": "ぐるんが"}, |
| 964 |
.. {"content": "むるんが"}, |
| 965 |
.. {"content": "せな"}, |
| 966 |
.. {"content": "とりとん"} |
| 967 |
.. ] |
| 968 |
.. select Titles --query 'content:$んが' |
| 969 |
|
| 970 |
The expression matches records that have value that ends with ``んが`` |
| 971 |
in ``content`` column value. ``ぐるんが`` and ``むるんが`` are matched |
| 972 |
with the expression. |
| 973 |
|
| 974 |
.. _script-syntax-near-search-operator: |
| 975 |
|
| 976 |
Near search operator |
| 977 |
^^^^^^^^^^^^^^^^^^^^ |
| 978 |
|
| 979 |
Its syntax is one of them:: |
| 980 |
|
| 981 |
column *N "word1 word2 ..." |
| 982 |
column *N${MAX_INTERVAL} "word1 word2 ..." |
| 983 |
column *N${MAX_INTERVAL},${MAX_TOKEN_INTERVAL_1}|${MAX_TOKEN_INTERVAL_2}|... "word1 word2 ..." |
| 984 |
|
| 985 |
Here are the examples of the second form:: |
| 986 |
|
| 987 |
column *N29 "word1 word2 ..." |
| 988 |
column *N-1 "word1 word2 ..." |
| 989 |
|
| 990 |
The first example means that ``29`` is used for the max interval. |
| 991 |
|
| 992 |
The second example means that ``-1`` is used for the max interval. |
| 993 |
``-1`` max interval means no limit. |
| 994 |
|
| 995 |
Here are examples of the third form:: |
| 996 |
|
| 997 |
column *N10,2|3 "word1 word2 word3" |
| 998 |
column *N10,2 "word1 word2 word3" |
| 999 |
|
| 1000 |
The first example means that ``2`` is used for the max interval of the |
| 1001 |
first interval and ``3`` is used for the max interval of the second |
| 1002 |
interval. |
| 1003 |
|
| 1004 |
The second example means that ``2`` is used for the first max interval |
| 1005 |
of the first interval and ``-1`` is used for the max interval of the |
| 1006 |
second interval. Because the omitted max interval is treated as |
| 1007 |
``-1``. |
| 1008 |
|
| 1009 |
The max intervals of each token (word) are described later. |
| 1010 |
|
| 1011 |
The operator does near search with words ``word1 word2 ...``. Near |
| 1012 |
search searches records that contain the words and the words are |
| 1013 |
appeared in the specified order and the max interval. |
| 1014 |
|
| 1015 |
The max interval is ``10`` by default. The unit of the max interval is |
| 1016 |
the number of characters in N-gram family tokenizers and the number of |
| 1017 |
words in morphological analysis family tokenizers. |
| 1018 |
|
| 1019 |
However, ``TokenBigram`` doesn't split ASCII only word into tokens. |
| 1020 |
Because ``TokenBigram`` uses white-space-separate like tokenize method |
| 1021 |
for ASCII characters in this case. |
| 1022 |
|
| 1023 |
So the unit for ASCII words with ``TokenBigram`` is the number of |
| 1024 |
words even if ``TokenBigram`` is a N-gram family tokenizer. |
| 1025 |
|
| 1026 |
Note that an index column for full text search must be defined for |
| 1027 |
``column``. |
| 1028 |
|
| 1029 |
Here is a simple example: |
| 1030 |
|
| 1031 |
.. groonga-command |
| 1032 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_near_search_operator.log |
| 1033 |
.. select Entries --filter 'content *N "I fast"' --output_columns content |
| 1034 |
.. select Entries --filter 'content *N "I Really"' --output_columns content |
| 1035 |
.. select Entries --filter 'content *N "also Really"' --output_columns content |
| 1036 |
|
| 1037 |
The first expression matches records that contain ``I`` and ``fast`` |
| 1038 |
and the max interval of those words are in 10 words. So the record |
| 1039 |
that its content is ``I started to use Groonga. It's very fast!`` is matched. |
| 1040 |
The number of words between ``I`` and ``fast`` is 7. |
| 1041 |
|
| 1042 |
The second expression matches records that contain ``I`` and |
| 1043 |
``Really`` and the max interval of those words are in 10 words. So the |
| 1044 |
record that its content is ``I also started to use mroonga. It's also |
| 1045 |
very fast! Really fast!`` is not matched. The number of words between |
| 1046 |
``I`` and ``Really`` is 11. |
| 1047 |
|
| 1048 |
The third expression matches records that contain ``also`` and |
| 1049 |
``Really`` and the max interval of those words are in 10 words. So |
| 1050 |
the record that its content is ``I also st arted to use mroonga. It's |
| 1051 |
also very fast! Really fast!`` is matched. The number of words between |
| 1052 |
``also`` and ``Really`` is 10. |
| 1053 |
|
| 1054 |
.. versionadded:: 12.0.1 |
| 1055 |
The max intervals of each token. |
| 1056 |
|
| 1057 |
You can specify the max intervals of each token. The default is no |
| 1058 |
limit. It means that all intervals of each token are valid as long as |
| 1059 |
the max interval is satisfied. |
| 1060 |
|
| 1061 |
Here is an example that use ``2`` for the max interval of the first |
| 1062 |
interval and ``4`` for the max interval of the second interval:: |
| 1063 |
|
| 1064 |
content *N10,2|4 "a b c" |
| 1065 |
|
| 1066 |
``10`` is the max interval. |
| 1067 |
|
| 1068 |
``|`` is the separator of the max intervals of each token. |
| 1069 |
|
| 1070 |
This matches ``a x b x x x c``. But this doesn't match ``a x x b c``, |
| 1071 |
``a b x x x x c`` and so on because the former has ``3`` interval for |
| 1072 |
the first interval that is larger than ``2`` and the latter has ``5`` |
| 1073 |
interval for the second interval that is later than ``4``. |
| 1074 |
|
| 1075 |
Here is an example that specifies the max intervals of each token: |
| 1076 |
|
| 1077 |
.. groonga-command |
| 1078 |
.. include:: ../../example/reference/grn_expr/script_syntax/near_search_operator_max_element_intervals.log |
| 1079 |
.. select Entries --filter 'content *N11,5|3 "first welcome post"' |
| 1080 |
.. select Entries --filter 'content *N11,4|3 "first welcome post"' |
| 1081 |
|
| 1082 |
You can omit one or more intervals. Omitted intervals are treated as |
| 1083 |
``-1``. It means that ``*N11,5`` equals ``*N11,5|-1``. ``-1`` means |
| 1084 |
that no limit. |
| 1085 |
|
| 1086 |
Here is an example that omits an interval: |
| 1087 |
|
| 1088 |
.. groonga-command |
| 1089 |
.. include:: ../../example/reference/grn_expr/script_syntax/near_search_operator_max_element_intervals_omit.log |
| 1090 |
.. select Entries --filter 'content *N11,5 "first welcome post"' |
| 1091 |
.. select Entries --filter 'content *N11,5|-1 "first welcome post"' |
| 1092 |
|
| 1093 |
You can specify extra intervals. They are just ignored: |
| 1094 |
|
| 1095 |
.. groonga-command |
| 1096 |
.. include:: ../../example/reference/grn_expr/script_syntax/near_search_operator_max_element_intervals_extra.log |
| 1097 |
.. select Entries --filter 'content *N11,5|6|1|2|3 "first welcome post"' |
| 1098 |
.. select Entries --filter 'content *N11,5|6 "first welcome post"' |
| 1099 |
|
| 1100 |
.. _script-syntax-near-phrase-search-operator: |
| 1101 |
|
| 1102 |
Near phrase search operator |
| 1103 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 1104 |
|
| 1105 |
Its syntax is one of them:: |
| 1106 |
|
| 1107 |
column *NP "phrase1 phrase2 ..." |
| 1108 |
column *NP${MAX_INTERVAL} "phrase1 phrase2 ..." |
| 1109 |
column *NP${MAX_INTERVAL},${ADDITIONAL_LAST_INTERVAL} "phrase1 phrase2 ..." |
| 1110 |
column *NP${MAX_INTERVAL},${ADDITIONAL_LAST_INTERVAL},${MAX_PHRASE_INTERVAL_1}|${MAX_PHRASE_INTERVAL_2}|... "phrase1 phrase2 ..." |
| 1111 |
|
| 1112 |
Here are examples of the second form:: |
| 1113 |
|
| 1114 |
column *NP29 "phrase1 phrase2 ..." |
| 1115 |
column *NP-1 "phrase1 phrase2 ..." |
| 1116 |
|
| 1117 |
The first example means that ``29`` is used for the max interval. |
| 1118 |
|
| 1119 |
The second example means that ``-1`` is used for the max interval. |
| 1120 |
|
| 1121 |
The max interval is described later. |
| 1122 |
|
| 1123 |
Here are examples of the third form:: |
| 1124 |
|
| 1125 |
column *NP10,29 "phrase1 phrase2 ..." |
| 1126 |
column *NP10,-1 "phrase1 phrase2 ..." |
| 1127 |
|
| 1128 |
The first example means that ``29`` is used for the additional last |
| 1129 |
interval. |
| 1130 |
|
| 1131 |
The second example means that ``-1`` is used for the additional last |
| 1132 |
interval. |
| 1133 |
|
| 1134 |
The additional last interval is described later. |
| 1135 |
|
| 1136 |
.. versionadded:: 12.0.1 |
| 1137 |
The max intervals of each phrase. |
| 1138 |
|
| 1139 |
Here are examples of the forth form:: |
| 1140 |
|
| 1141 |
column *NP10,0,2|3 "phrase1 phrase2 phrase3" |
| 1142 |
column *NP10,0,2 "phrase1 phrase2 phrase3" |
| 1143 |
|
| 1144 |
The first example means that ``2`` is used for the max interval of the |
| 1145 |
first interval and ``3`` is used for the max interval of the second |
| 1146 |
interval. |
| 1147 |
|
| 1148 |
The second example means that ``2`` is used for the first max interval |
| 1149 |
of the first interval and ``-1`` is used for the max interval of the |
| 1150 |
second interval. Because the omitted max interval is treated as |
| 1151 |
``-1``. |
| 1152 |
|
| 1153 |
See :ref:`script-syntax-near-phrase-search-operator` for the max |
| 1154 |
intervals of each phrase. |
| 1155 |
|
| 1156 |
The operator does near phrase search with phrases ``phrase1 phrase2 |
| 1157 |
...``. Near phrase search searches records that contain the phrases |
| 1158 |
and the phrases are appeared in the specified order and the max |
| 1159 |
interval. |
| 1160 |
|
| 1161 |
The max interval is ``10`` by default. The unit of the max interval is |
| 1162 |
the number of characters in N-gram family tokenizers and the number of |
| 1163 |
words in morphological analysis family tokenizers. |
| 1164 |
|
| 1165 |
However, ``TokenBigram`` doesn't split ASCII only word into tokens. |
| 1166 |
Because ``TokenBigram`` uses white-space-separate like tokenize method |
| 1167 |
for ASCII characters in this case. |
| 1168 |
|
| 1169 |
So the unit for ASCII words with ``TokenBigram`` is the number of |
| 1170 |
words even if ``TokenBigram`` is a N-gram family tokenizer. |
| 1171 |
|
| 1172 |
Note that an index column for full text search must be defined for |
| 1173 |
``column``. |
| 1174 |
|
| 1175 |
TODO: Use index that has ``TokenNgram("unify_alphabet", false)`` |
| 1176 |
tokenizer to show difference with near search with English text. |
| 1177 |
|
| 1178 |
Here is a simple example: |
| 1179 |
|
| 1180 |
.. groonga-command |
| 1181 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_near_phrase_search_operator.log |
| 1182 |
.. select Entries --filter 'content *NP "I fast"' --output_columns content |
| 1183 |
.. select Entries --filter 'content *NP "I Really"' --output_columns content |
| 1184 |
.. select Entries --filter 'content *NP "also Really"' --output_columns content |
| 1185 |
|
| 1186 |
The first expression matches records that contain ``I`` and ``fast`` |
| 1187 |
and the max interval of those words are in 10 words. So the record |
| 1188 |
that its content is ``I also started to use mroonga. It's also very |
| 1189 |
fast! ...`` is matched. The number of words between ``I`` and ``fast`` |
| 1190 |
is just 10. |
| 1191 |
|
| 1192 |
The second expression matches records that contain ``I`` and |
| 1193 |
``Really`` and the max interval of those words are in 10 words. So the |
| 1194 |
record that its content is ``I also started to use mroonga. It's also |
| 1195 |
very fast! Really fast!`` is not matched. The number of words between |
| 1196 |
``I`` and ``Really`` is 14. |
| 1197 |
|
| 1198 |
The third expression matches records that contain ``also`` and |
| 1199 |
``Really`` and the max interval of those words are in 10 words. So |
| 1200 |
the record that its content is ``I also st arted to use mroonga. It's |
| 1201 |
also very fast! Really fast!`` is matched. The number of words between |
| 1202 |
``also`` and ``Really`` is 10. |
| 1203 |
|
| 1204 |
Here is an example to use the custom max interval: |
| 1205 |
|
| 1206 |
.. groonga-command |
| 1207 |
.. include:: ../../example/reference/grn_expr/script_syntax/near_phrase_search_operator_max_interval.log |
| 1208 |
.. select Entries --filter 'content *NP14 "I Really"' --output_columns content |
| 1209 |
.. select Entries --filter 'content *NP-1 "I Really"' --output_columns content |
| 1210 |
|
| 1211 |
The first expression matches ``I also started to use |
| 1212 |
mroonga. It's also very fast! Really fast!`` because the number of |
| 1213 |
words between ``I`` and ``Really`` is 14. |
| 1214 |
|
| 1215 |
The second expression also matches ``I also started to use |
| 1216 |
mroonga. It's also very fast! Really fast!`` because ``-1`` means that |
| 1217 |
there is no limitation the number of words between ``I`` and |
| 1218 |
``Really``. |
| 1219 |
|
| 1220 |
You can use additional interval only for the last phrase. It means |
| 1221 |
that you can accept more distance only between the second to last |
| 1222 |
phrase and the last phrase. This is useful for implementing a near |
| 1223 |
phrase search in the same sentence. If you specify ``.`` (sentence end |
| 1224 |
phrase) as the last phrase and specify ``-1`` as the additional last |
| 1225 |
interval, the other specified phrases must be appeared before |
| 1226 |
``.``. You must append ``$`` to the last phrase like ``.$``. |
| 1227 |
|
| 1228 |
Here is an example that uses ``-1`` as the additional last interval of |
| 1229 |
the given phrases:: |
| 1230 |
|
| 1231 |
column *NP10,-1 "a b .$" |
| 1232 |
|
| 1233 |
Here is an example to customize the additional last interval of the |
| 1234 |
given phrases: |
| 1235 |
|
| 1236 |
.. groonga-command |
| 1237 |
.. include:: ../../example/reference/grn_expr/script_syntax/near_phrase_search_operator_additional_last_interval_negative.log |
| 1238 |
.. select Entries --filter 'content *NP1,-1 "I started .$"' --output_columns content |
| 1239 |
|
| 1240 |
You can also use positive number for the additional last interval. If |
| 1241 |
you specify positive number as the additional last interval, all of |
| 1242 |
the following conditions must be satisfied: |
| 1243 |
|
| 1244 |
1. The interval between the first phrase and the second to last |
| 1245 |
phrase is less than or equals to ``the max interval``. |
| 1246 |
|
| 1247 |
2. The interval between the first phrase and the last phrase is less |
| 1248 |
than or equals to ``the max interval`` + ``the additional last |
| 1249 |
interval``. |
| 1250 |
|
| 1251 |
If you specify negative number as the additional last interval, the |
| 1252 |
second condition isn't required. Appearing the last phrase is just |
| 1253 |
needed. |
| 1254 |
|
| 1255 |
Here is an example to use positive number as the additional last interval: |
| 1256 |
|
| 1257 |
.. groonga-command |
| 1258 |
.. include:: ../../example/reference/grn_expr/script_syntax/near_phrase_search_operator_additional_last_interval_positive.log |
| 1259 |
.. select Entries --filter 'content *NP1,4 "I started .$"' --output_columns content |
| 1260 |
|
| 1261 |
.. _script-syntax-near-phrase-product-search-operator: |
| 1262 |
|
| 1263 |
Near phrase product search operator |
| 1264 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 1265 |
|
| 1266 |
.. versionadded:: 11.1.1 |
| 1267 |
|
| 1268 |
Its syntax is one of them:: |
| 1269 |
|
| 1270 |
column *NPP "(phrase1-1 phrase1-2 ...) (phrase2-1 phrase2-2 ...) ..." |
| 1271 |
column *NPP${MAX_INTERVAL} "(phrase1-1 phrase1-2 ...) (phrase2-1 phrase2-2 ...) ..." |
| 1272 |
column *NPP${MAX_INTERVAL},${ADDITIONAL_LAST_INTERVAL} "(phrase1-1 phrase1-2 ...) (phrase2-1 phrase2-2 ...) ..." |
| 1273 |
column *NPP${MAX_INTERVAL},${ADDITIONAL_LAST_INTERVAL},${MAX_PHRASE_INTERVAL_1}|${MAX_PHRASE_INTERVAL_2}|... "(phrase1-1 phrase1-2 ...) (phrase2-1 phrase2-2 ...) ..." |
| 1274 |
|
| 1275 |
Here are examples of the second form:: |
| 1276 |
|
| 1277 |
column *NPP29 "(phrase1-1 phrase1-2 ...) (phrase2-1 phrase2-2 ...) ..." |
| 1278 |
column *NPP-1 "(phrase1-1 phrase1-2 ...) (phrase2-1 phrase2-2 ...) ..." |
| 1279 |
|
| 1280 |
The first example means that ``29`` is used for the max interval. |
| 1281 |
|
| 1282 |
The second example means that ``-1`` is used for the max interval. |
| 1283 |
|
| 1284 |
Here are examples of the third form:: |
| 1285 |
|
| 1286 |
column *NPP10,29 "(phrase1-1 phrase1-2 ...) (phrase2-1 phrase2-2 ...) ..." |
| 1287 |
column *NPP10,-1 "(phrase1-1 phrase1-2 ...) (phrase2-1 phrase2-2 ...) ..." |
| 1288 |
|
| 1289 |
The first example means that ``29`` is used for the additional last |
| 1290 |
interval. |
| 1291 |
|
| 1292 |
The second example means that ``-1`` is used for the additional last |
| 1293 |
interval. |
| 1294 |
|
| 1295 |
.. versionadded:: 12.0.1 |
| 1296 |
The max intervals of each phrase. |
| 1297 |
|
| 1298 |
Here are examples of the forth form:: |
| 1299 |
|
| 1300 |
column *NPP10,0,2|3 "(phrase1-1 phrase1-2 ...) (phrase2-1 phrase2-2 ...) (phrase3-1 phrase3-2 ...)" |
| 1301 |
column *NPP10,0,2 "(phrase1-1 phrase1-2 ...) (phrase2-1 phrase2-2 ...) (phrase3-1 phrase3-2 ...)" |
| 1302 |
|
| 1303 |
The first example means that ``2`` is used for the max interval of the |
| 1304 |
first interval and ``3`` is used for the max interval of the second |
| 1305 |
interval. |
| 1306 |
|
| 1307 |
The second example means that ``2`` is used for the first max interval |
| 1308 |
of the first interval and ``-1`` is used for the max interval of the |
| 1309 |
second interval. Because the omitted max interval is treated as |
| 1310 |
``-1``. |
| 1311 |
|
| 1312 |
See :ref:`script-syntax-near-phrase-search-operator` for the max |
| 1313 |
intervals of each phrase. |
| 1314 |
|
| 1315 |
This operator does multiple |
| 1316 |
:ref:`script-syntax-near-phrase-search-operator`. Phrases for each |
| 1317 |
:ref:`script-syntax-near-phrase-search-operator` are computed as |
| 1318 |
product of ``{phrase1_1, phrase1_2, ...}``, ``{phrase2_1, phrase2_2, |
| 1319 |
...}`` and ``...``. For example, ``column *NPP "(a b c) (d e)"`` uses |
| 1320 |
the following phrases for near phrase searches: |
| 1321 |
|
| 1322 |
* ``a d`` |
| 1323 |
* ``a e`` |
| 1324 |
* ``b d`` |
| 1325 |
* ``b e`` |
| 1326 |
* ``c d`` |
| 1327 |
* ``c e`` |
| 1328 |
|
| 1329 |
Here is a simple example: |
| 1330 |
|
| 1331 |
.. groonga-command |
| 1332 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_near_phrase_product_search_operator.log |
| 1333 |
.. select Entries \ |
| 1334 |
.. --filter 'content *NPP "(I It) (migrated fast)"' \ |
| 1335 |
.. --output_columns content |
| 1336 |
|
| 1337 |
You can use the all features of |
| 1338 |
:ref:`script-syntax-near-phrase-search-operator` such as the max |
| 1339 |
interval, ``$`` for the last phrase and the additional last interval. |
| 1340 |
|
| 1341 |
.. groonga-command |
| 1342 |
.. include:: ../../example/reference/grn_expr/script_syntax/near_phrase_product_search_operator_options.log |
| 1343 |
.. select Entries \ |
| 1344 |
.. --filter 'content *NPP2,-1 "(I It) (migrated fast) (.$)"' \ |
| 1345 |
.. --output_columns content |
| 1346 |
|
| 1347 |
This is more effective than multiple |
| 1348 |
:ref:`script-syntax-near-phrase-search-operator` . |
| 1349 |
|
| 1350 |
.. _script-syntax-ordered-near-phrase-search-operator: |
| 1351 |
|
| 1352 |
Ordered near phrase search operator |
| 1353 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 1354 |
|
| 1355 |
.. versionadded:: 11.0.9 |
| 1356 |
|
| 1357 |
Its syntax is one of them:: |
| 1358 |
|
| 1359 |
column *ONP "phrase1 phrase2 ..." |
| 1360 |
column *ONP${MAX_INTERVAL} "phrase1 phrase2 ..." |
| 1361 |
column *ONP${MAX_INTERVAL},${ADDITIONAL_LAST_INTERVAL} "phrase1 phrase2 ..." |
| 1362 |
column *ONP${MAX_INTERVAL},${ADDITIONAL_LAST_INTERVAL},${MAX_PHRASE_INTERVAL_1}|${MAX_PHRASE_INTERVAL_2}|... "phrase1 phrase2 ..." |
| 1363 |
|
| 1364 |
Here are examples of the second form:: |
| 1365 |
|
| 1366 |
column *ONP29 "phrase1 phrase2 ..." |
| 1367 |
column *ONP-1 "phrase1 phrase2 ..." |
| 1368 |
|
| 1369 |
The first example means that ``29`` is used for the max interval. |
| 1370 |
|
| 1371 |
The second example means that ``-1`` is used for the max interval. |
| 1372 |
|
| 1373 |
Here are examples of the third form:: |
| 1374 |
|
| 1375 |
column *ONP10,29 "phrase1 phrase2 ..." |
| 1376 |
column *ONP10,-1 "phrase1 phrase2 ..." |
| 1377 |
|
| 1378 |
The first example means that ``29`` is used for the additional last |
| 1379 |
interval. |
| 1380 |
|
| 1381 |
The second example means that ``-1`` is used for the additional last |
| 1382 |
interval. |
| 1383 |
|
| 1384 |
.. versionadded:: 12.0.1 |
| 1385 |
The max intervals of each phrase. |
| 1386 |
|
| 1387 |
Here are examples of the forth form:: |
| 1388 |
|
| 1389 |
column *ONP10,0,2|3 "phrase1 phrase2 phrase3" |
| 1390 |
column *ONP10,0,2 "phrase1 phrase2 phrase3" |
| 1391 |
|
| 1392 |
The first example means that ``2`` is used for the max interval of the |
| 1393 |
first interval and ``3`` is used for the max interval of the second |
| 1394 |
interval. |
| 1395 |
|
| 1396 |
The second example means that ``2`` is used for the first max interval |
| 1397 |
of the first interval and ``-1`` is used for the max interval of the |
| 1398 |
second interval. Because the omitted max interval is treated as |
| 1399 |
``-1``. |
| 1400 |
|
| 1401 |
See :ref:`script-syntax-near-phrase-search-operator` for the max |
| 1402 |
intervals of each phrase. |
| 1403 |
|
| 1404 |
This operator does ordered near phrase search with ``phrase1``, |
| 1405 |
``phrase2`` and ``...``. Ordered near phrase search is similar to |
| 1406 |
:ref:`script-syntax-near-phrase-search-operator` but ordered near |
| 1407 |
phrase search checks phrases order. For example, ``column *ONP |
| 1408 |
"groonga mroonga pgroonga"`` matches ``groonga mroonga rroonga |
| 1409 |
pgroonga`` but doesn't match ``groonga rroonga pgroonga |
| 1410 |
mroonga``. Because the latter uses different order. |
| 1411 |
|
| 1412 |
Here is a simple example: |
| 1413 |
|
| 1414 |
.. groonga-command |
| 1415 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_ordered_near_phrase_search_operator.log |
| 1416 |
.. select Entries \ |
| 1417 |
.. --filter 'content *ONP "I Groonga"' \ |
| 1418 |
.. --output_columns content |
| 1419 |
.. select Entries \ |
| 1420 |
.. --filter 'content *ONP "Groonga I"' \ |
| 1421 |
.. --output_columns content |
| 1422 |
|
| 1423 |
You can use the all features of |
| 1424 |
:ref:`script-syntax-near-phrase-search-operator` such as the max |
| 1425 |
interval and the additional last interval. But you don't need to |
| 1426 |
specify ``$`` for the last phrase because the last phrase in query is |
| 1427 |
the last phrase. |
| 1428 |
|
| 1429 |
.. _script-syntax-ordered-near-phrase-product-search-operator: |
| 1430 |
|
| 1431 |
Ordered near phrase product search operator |
| 1432 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 1433 |
|
| 1434 |
.. versionadded:: 11.1.1 |
| 1435 |
|
| 1436 |
Its syntax is one of them:: |
| 1437 |
|
| 1438 |
column *ONPP "(phrase1-1 phrase1-2 ...) (phrase2-1 phrase2-2 ...) ..." |
| 1439 |
column *ONPP${MAX_INTERVAL} "(phrase1-1 phrase1-2 ...) (phrase2-1 phrase2-2 ...) ..." |
| 1440 |
column *ONPP${MAX_INTERVAL},${ADDITIONAL_LAST_INTERVAL} "(phrase1-1 phrase1-2 ...) (phrase2-1 phrase2-2 ...) ..." |
| 1441 |
column *ONPP${MAX_INTERVAL},${ADDITIONAL_LAST_INTERVAL},${MAX_PHRASE_INTERVAL_1}|${MAX_PHRASE_INTERVAL_2}|... "(phrase1-1 phrase1-2 ...) (phrase2-1 phrase2-2 ...) ..." |
| 1442 |
|
| 1443 |
Here are examples of the second form:: |
| 1444 |
|
| 1445 |
column *ONPP29 "(phrase1-1 phrase1-2 ...) (phrase2-1 phrase2-2 ...) ..." |
| 1446 |
column *ONPP-1 "(phrase1-1 phrase1-2 ...) (phrase2-1 phrase2-2 ...) ..." |
| 1447 |
|
| 1448 |
The first example means that ``29`` is used for the max interval. |
| 1449 |
|
| 1450 |
The second example means that ``-1`` is used for the max interval. |
| 1451 |
|
| 1452 |
Here are examples of the third form:: |
| 1453 |
|
| 1454 |
column *ONPP10,29 "(phrase1-1 phrase1-2 ...) (phrase2-1 phrase2-2 ...) ..." |
| 1455 |
column *ONPP10,-1 "(phrase1-1 phrase1-2 ...) (phrase2-1 phrase2-2 ...) ..." |
| 1456 |
|
| 1457 |
The first example means that ``29`` is used for the additional last |
| 1458 |
interval. |
| 1459 |
|
| 1460 |
The second example means that ``-1`` is used for the additional last |
| 1461 |
interval. |
| 1462 |
|
| 1463 |
.. versionadded:: 12.0.1 |
| 1464 |
The max intervals of each phrase. |
| 1465 |
|
| 1466 |
Here are examples of the forth form:: |
| 1467 |
|
| 1468 |
column *ONPP10,0,2|3 "(phrase1-1 phrase1-2 ...) (phrase2-1 phrase2-2 ...) (phrase3-1 phrase3-2 ...)" |
| 1469 |
column *ONPP10,0,2 "(phrase1-1 phrase1-2 ...) (phrase2-1 phrase2-2 ...) (phrase3-1 phrase3-2 ...)" |
| 1470 |
|
| 1471 |
The first example means that ``2`` is used for the max interval of the |
| 1472 |
first interval and ``3`` is used for the max interval of the second |
| 1473 |
interval. |
| 1474 |
|
| 1475 |
The second example means that ``2`` is used for the first max interval |
| 1476 |
of the first interval and ``-1`` is used for the max interval of the |
| 1477 |
second interval. Because the omitted max interval is treated as |
| 1478 |
``-1``. |
| 1479 |
|
| 1480 |
See :ref:`script-syntax-near-phrase-search-operator` for the max |
| 1481 |
intervals of each phrase. |
| 1482 |
|
| 1483 |
This operator does ordered near phrase product search. Ordered near |
| 1484 |
phrase product search is similar to |
| 1485 |
:ref:`script-syntax-near-phrase-product-search-operator` but ordered |
| 1486 |
near phrase product search checks phrases order like |
| 1487 |
:ref:`query-syntax-ordered-near-phrase-search-condition`. For example, |
| 1488 |
``column *ONPP "(a b c) (d e)"`` matches ``a 1 d`` but doesn't match |
| 1489 |
``d 1 a``. Because the latter uses different order. |
| 1490 |
|
| 1491 |
Here is a simple example: |
| 1492 |
|
| 1493 |
.. groonga-command |
| 1494 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_ordered_near_phrase_product_search_operator.log |
| 1495 |
.. select Entries \ |
| 1496 |
.. --filter 'content *ONPP "(I It) (migrated fast) (.)"' \ |
| 1497 |
.. --output_columns content |
| 1498 |
|
| 1499 |
You can use the all features of |
| 1500 |
:ref:`script-syntax-near-phrase-search-operator` such as the max |
| 1501 |
interval and the additional last interval. But you don't need to |
| 1502 |
specify ``$`` for the last phrase because the last phrase in query is |
| 1503 |
the last phrase. |
| 1504 |
|
| 1505 |
.. _script-syntax-similar-search-operator: |
| 1506 |
|
| 1507 |
Similar search operator |
| 1508 |
^^^^^^^^^^^^^^^^^^^^^^^ |
| 1509 |
|
| 1510 |
Its syntax is ``column *S "document"``. |
| 1511 |
|
| 1512 |
The operator does similar search with document ``document``. Similar |
| 1513 |
search searches records that have similar content to |
| 1514 |
``document``. |
| 1515 |
|
| 1516 |
Note that an index column for full text search must be defined for |
| 1517 |
``column``. |
| 1518 |
|
| 1519 |
Here is a simple example: |
| 1520 |
|
| 1521 |
.. groonga-command |
| 1522 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_similar_search_operator.log |
| 1523 |
.. select Entries --filter 'content *S "I migrated all Solr system!"' --output_columns content |
| 1524 |
|
| 1525 |
The expression matches records that have similar content to ``I |
| 1526 |
migrated all Solr system!``. In this case, records that have ``I |
| 1527 |
migrated all XXX system!`` content are matched. |
| 1528 |
|
| 1529 |
You should use ``TokenMecab`` tokenizer for similar search against Japanese documents. |
| 1530 |
Because ``TokenMecab`` will tokenize target documents to almost words, it improves similar search precision. |
| 1531 |
|
| 1532 |
.. _script-syntax-term-extract-operator: |
| 1533 |
|
| 1534 |
Term extract operator |
| 1535 |
^^^^^^^^^^^^^^^^^^^^^ |
| 1536 |
|
| 1537 |
Its syntax is ``_key *T "document"``. |
| 1538 |
|
| 1539 |
The operator extracts terms from ``document``. Terms must be |
| 1540 |
registered as keys of the table of ``_key``. |
| 1541 |
|
| 1542 |
Note that the table must be patricia trie (``TABLE_PAT_KEY``) or |
| 1543 |
double array trie (``TABLE_DAT_KEY``). You can't use hash table |
| 1544 |
(``TABLE_HASH_KEY``) and array (``TABLE_NO_KEY``) because they don't |
| 1545 |
support longest common prefix search. Longest common prefix search is |
| 1546 |
used to implement the operator. |
| 1547 |
|
| 1548 |
Here is a simple example: |
| 1549 |
|
| 1550 |
.. groonga-command |
| 1551 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_term_extract_operator.log |
| 1552 |
.. table_create Words TABLE_PAT_KEY ShortText --normalizer NormalizerAuto |
| 1553 |
.. load --table Words |
| 1554 |
.. [ |
| 1555 |
.. {"_key": "groonga"}, |
| 1556 |
.. {"_key": "mroonga"}, |
| 1557 |
.. {"_key": "Senna"}, |
| 1558 |
.. {"_key": "Tritonn"} |
| 1559 |
.. ] |
| 1560 |
.. select Words --filter '_key *T "Groonga is the successor project to Senna."' --output_columns _key |
| 1561 |
|
| 1562 |
The expression extracts terms that included in document ``Groonga is |
| 1563 |
the successor project to Senna.``. In this case, ``NormalizerAuto`` |
| 1564 |
normalizer is specified to ``Words``. So ``Groonga`` can be extracted |
| 1565 |
even if it is loaded as ``groonga`` into ``Words``. All of extracted |
| 1566 |
terms are also normalized. |
| 1567 |
|
| 1568 |
.. _script-syntax-regular-expression-operator: |
| 1569 |
|
| 1570 |
Regular expression operator |
| 1571 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 1572 |
|
| 1573 |
.. versionadded:: 5.0.1 |
| 1574 |
|
| 1575 |
Its syntax is ``column @~ "pattern"``. |
| 1576 |
|
| 1577 |
The operator searches records by the regular expression |
| 1578 |
``pattern``. If a record's ``column`` value is matched to ``pattern``, |
| 1579 |
the record is matched. |
| 1580 |
|
| 1581 |
``pattern`` must be valid regular expression syntax. See |
| 1582 |
:doc:`/reference/regular_expression` about regular expression syntax |
| 1583 |
details. |
| 1584 |
|
| 1585 |
The following example uses ``.roonga`` as pattern. It matches |
| 1586 |
``Groonga``, ``Mroonga`` and so on. |
| 1587 |
|
| 1588 |
.. groonga-command |
| 1589 |
.. include:: ../../example/reference/grn_expr/script_syntax/simple_regular_expression_operator.log |
| 1590 |
.. select Entries --filter 'content @~ ".roonga"' |
| 1591 |
|
| 1592 |
In most cases, regular expression is evaluated sequentially. So it may |
| 1593 |
be slow against many records. |
| 1594 |
|
| 1595 |
In some cases, Groonga evaluates regular expression by index. It's |
| 1596 |
very fast. See :doc:`/reference/regular_expression` for details. |