| 1 |
.. -*- rst -*- |
| 2 |
|
| 3 |
.. groonga-command |
| 4 |
.. database: reference_grn_expr_query_syntax |
| 5 |
|
| 6 |
Query syntax |
| 7 |
============ |
| 8 |
|
| 9 |
Query syntax is a syntax to specify search condition for common Web |
| 10 |
search form. It is similar to the syntax of Google's search form. For |
| 11 |
example, ``word1 word2`` means that groonga searches records that |
| 12 |
contain both ``word1`` and ``word2``. ``word1 OR word2`` means that |
| 13 |
groonga searches records that contain either ``word1`` or ``word2``. |
| 14 |
|
| 15 |
Query syntax consists of :ref:`query-syntax-conditional-expression` , |
| 16 |
:ref:`query-syntax-combined-expression` and |
| 17 |
:ref:`query-syntax-assignment-expression`. Normally |
| 18 |
:ref:`query-syntax-assignment-expression` can be ignored. Because |
| 19 |
:ref:`query-syntax-assignment-expression` is disabled in the |
| 20 |
:ref:`select-query` option of :doc:`/reference/commands/select`. You |
| 21 |
can use it by specifying ``ALLOW_UPDATE`` to the |
| 22 |
:ref:`select-query-flags` option. |
| 23 |
|
| 24 |
:ref:`query-syntax-conditional-expression` specifies an |
| 25 |
condition. :ref:`query-syntax-combined-expression` consists of one or |
| 26 |
more :ref:`query-syntax-conditional-expression`, |
| 27 |
:ref:`query-syntax-combined-expression` or |
| 28 |
:ref:`query-syntax-assignment-expression`. :ref:`query-syntax-assignment-expression` |
| 29 |
can assigns a value to a column. |
| 30 |
|
| 31 |
Sample data |
| 32 |
----------- |
| 33 |
|
| 34 |
Here are a schema definition and sample data to show usage. |
| 35 |
|
| 36 |
.. groonga-command |
| 37 |
.. include:: ../../example/reference/grn_expr/query_syntax/setup.log |
| 38 |
.. table_create Entries TABLE_PAT_KEY ShortText |
| 39 |
.. column_create Entries content COLUMN_SCALAR Text |
| 40 |
.. column_create Entries n_likes COLUMN_SCALAR UInt32 |
| 41 |
.. table_create Terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto |
| 42 |
.. column_create Terms entries_key_index COLUMN_INDEX|WITH_POSITION Entries _key |
| 43 |
.. column_create Terms entries_content_index COLUMN_INDEX|WITH_POSITION Entries content |
| 44 |
.. load --table Entries |
| 45 |
.. [ |
| 46 |
.. {"_key": "The first post!", |
| 47 |
.. "content": "Welcome! This is my first post!", |
| 48 |
.. "n_likes": 5}, |
| 49 |
.. {"_key": "Groonga", |
| 50 |
.. "content": "I started to use Groonga. It's very fast!", |
| 51 |
.. "n_likes": 10}, |
| 52 |
.. {"_key": "Mroonga", |
| 53 |
.. "content": "I also started to use Mroonga. It's also very fast! Really fast!", |
| 54 |
.. "n_likes": 15}, |
| 55 |
.. {"_key": "Good-bye Senna", |
| 56 |
.. "content": "I migrated all Senna system!", |
| 57 |
.. "n_likes": 3}, |
| 58 |
.. {"_key": "Good-bye Tritonn", |
| 59 |
.. "content": "I also migrated all Tritonn system!", |
| 60 |
.. "n_likes": 3} |
| 61 |
.. ] |
| 62 |
|
| 63 |
There is a table, ``Entries``, for blog entries. An entry has title, |
| 64 |
content and the number of likes for the entry. Title is key of |
| 65 |
``Entries``. Content is value of ``Entries.content`` column. The |
| 66 |
number of likes is value of ``Entries.n_likes`` column. |
| 67 |
|
| 68 |
``Entries._key`` column and ``Entries.content`` column are indexed |
| 69 |
using ``TokenBigram`` tokenizer. So both ``Entries._key`` and |
| 70 |
``Entries.content`` are fulltext search ready. |
| 71 |
|
| 72 |
OK. The schema and data for examples are ready. |
| 73 |
|
| 74 |
Escape |
| 75 |
------ |
| 76 |
|
| 77 |
There are special characters in query syntax. To use a special |
| 78 |
character as itself, it should be escaped by prepending ``\``. For |
| 79 |
example, ``"`` is a special character. It is escaped as ``\"``. |
| 80 |
|
| 81 |
Here is a special character list: |
| 82 |
|
| 83 |
* ``[space]`` (escaped as ``[backslash][space]``) (You should |
| 84 |
substitute ``[space]`` with a white space character that is 0x20 |
| 85 |
in ASCII and ``[backslash]`` with ``\\``.) |
| 86 |
* ``"`` (escaped as ``\"``) |
| 87 |
* ``(`` (escaped as ``\(``) |
| 88 |
* ``)`` (escaped as ``\)``) |
| 89 |
* ``\`` (escaped as ``\\``) |
| 90 |
|
| 91 |
You can use quote instead of escape special characters except ``\`` |
| 92 |
(backslash). You need to use backslash for escaping backslash like |
| 93 |
``\\`` in quote. |
| 94 |
|
| 95 |
Quote syntax is ``"..."``. You need escape ``"`` as |
| 96 |
``\"`` in ``"..."`` quote syntax. For example, ``You say "Hello Alice!"`` can be |
| 97 |
quoted ``"You say \"Hello Alice!\""``. |
| 98 |
|
| 99 |
In addition ``'...'`` isn't available in query syntax. |
| 100 |
|
| 101 |
.. note:: |
| 102 |
|
| 103 |
There is an important point which you have to care. The ``\`` |
| 104 |
(backslash) character is interpreted by command line shell. So if |
| 105 |
you want to search ``(`` itself for example, you need to escape |
| 106 |
twice (``\\(``) in command line shell. The command line shell |
| 107 |
interprets ``\\(`` as ``\(``, then pass such a literal to |
| 108 |
Groonga. Groonga regards ``\(`` as ``(``, then search ``(`` itself |
| 109 |
from database. If you can't do intended search by Groonga, confirm |
| 110 |
whether special character is escaped properly. |
| 111 |
|
| 112 |
.. _query-syntax-conditional-expression: |
| 113 |
|
| 114 |
Conditional expression |
| 115 |
---------------------- |
| 116 |
|
| 117 |
Here is available conditional expression list. |
| 118 |
|
| 119 |
.. _query-syntax-full-text-search-condition: |
| 120 |
|
| 121 |
Full text search condition |
| 122 |
^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 123 |
|
| 124 |
Its syntax is ``keyword``. |
| 125 |
|
| 126 |
``Full text search condition`` specifies a full text search condition |
| 127 |
against the default match columns. Match columns are full text search |
| 128 |
target columns. |
| 129 |
|
| 130 |
You should specify the default match columns for full text |
| 131 |
search. They can be specified by ``--match_columns`` option of |
| 132 |
:doc:`/reference/commands/select`. If you don't specify the default match |
| 133 |
columns, this conditional expression fails. |
| 134 |
|
| 135 |
This conditional expression does full text search with |
| 136 |
``keyword``. ``keyword`` should not contain any spaces. If ``keyword`` |
| 137 |
contains a space such as ``search keyword``, it means two full text |
| 138 |
search conditions; ``search`` and ``keyword``. If you want to |
| 139 |
specifies a keyword that contains one or more spaces, you can use |
| 140 |
``phrase search condition`` that is described below. |
| 141 |
|
| 142 |
Here is a simple example: |
| 143 |
|
| 144 |
.. groonga-command |
| 145 |
.. include:: ../../example/reference/grn_expr/query_syntax/simple_full_text_search.log |
| 146 |
.. select Entries --match_columns content --query fast |
| 147 |
|
| 148 |
The expression matches records that contain a word ``fast`` in |
| 149 |
``content`` column value. |
| 150 |
|
| 151 |
``content`` column is the default match column. |
| 152 |
|
| 153 |
.. _query-syntax-phrase-search-condition: |
| 154 |
|
| 155 |
Phrase search condition |
| 156 |
^^^^^^^^^^^^^^^^^^^^^^^ |
| 157 |
|
| 158 |
Its syntax is ``"search keyword"``. |
| 159 |
|
| 160 |
``Phrase search condition`` specifies a phrase search condition |
| 161 |
against the default match columns. |
| 162 |
|
| 163 |
You should specify the default match columns for full text |
| 164 |
search. They can be specified by ``--match_columns`` option of |
| 165 |
:doc:`/reference/commands/select`. If you don't specify the default match |
| 166 |
columns, this conditional expression fails. |
| 167 |
|
| 168 |
This conditional expression does phrase search with ``search |
| 169 |
keyword``. Phrase search searches records that contain ``search`` and |
| 170 |
``keyword`` and those terms are appeared in the same order and |
| 171 |
adjacent. Thus, ``Put a search keyword in the form`` is matched but |
| 172 |
``Search by the keyword`` and ``There is a keyword. Search by it!`` |
| 173 |
aren't matched. |
| 174 |
|
| 175 |
Here is a simple example: |
| 176 |
|
| 177 |
.. groonga-command |
| 178 |
.. include:: ../../example/reference/grn_expr/query_syntax/simple_phrase_search.log |
| 179 |
.. select Entries --match_columns content --query '"I started"' |
| 180 |
|
| 181 |
The expression matches records that contain a phrase ``I started`` in |
| 182 |
``content`` column value. ``I also started`` isn't matched because |
| 183 |
``I`` and ``started`` aren't adjacent. |
| 184 |
|
| 185 |
``content`` column is the default match column. |
| 186 |
|
| 187 |
.. _query-syntax-full-text-search-condition-with-explicit-match-column: |
| 188 |
|
| 189 |
Full text search condition (with explicit match column) |
| 190 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 191 |
|
| 192 |
Its syntax is ``column:@keyword``. |
| 193 |
|
| 194 |
It's similar to ``full text search condition`` but it doesn't require |
| 195 |
the default match columns. You need to specify match column for the |
| 196 |
full text search condition by ``column:`` instead of |
| 197 |
``--match_columns`` option of :doc:`/reference/commands/select`. |
| 198 |
|
| 199 |
This conditional expression is useful when you want to use two or more |
| 200 |
full text search against different columns. The default match columns |
| 201 |
specified by ``--match_columns`` option can't be specified multiple |
| 202 |
times. You need to specify the second match column by this conditional |
| 203 |
expression. |
| 204 |
|
| 205 |
The different between ``full text search condition`` and ``full text |
| 206 |
search condition (with explicit match column)`` is whether advanced |
| 207 |
match columns are supported or not. ``Full text search condition`` |
| 208 |
supports advanced match columns but ``full text search condition (with |
| 209 |
explicit match column)`` isn't supported. Advanced match columns has |
| 210 |
the following features: |
| 211 |
|
| 212 |
* Weight is supported. |
| 213 |
* Using multiple columns are supported. |
| 214 |
* Using index column as a match column is supported. |
| 215 |
|
| 216 |
See description of ``--match_columns`` option of |
| 217 |
:doc:`/reference/commands/select` about them. |
| 218 |
|
| 219 |
Here is a simple example: |
| 220 |
|
| 221 |
.. groonga-command |
| 222 |
.. include:: ../../example/reference/grn_expr/query_syntax/simple_full_text_search_with_explicit_match_column.log |
| 223 |
.. select Entries --query content:@fast |
| 224 |
|
| 225 |
The expression matches records that contain a word ``fast`` in |
| 226 |
``content`` column value. |
| 227 |
|
| 228 |
Phrase search condition (with explicit match column) |
| 229 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 230 |
|
| 231 |
Its syntax is ``column:@"search keyword"``. |
| 232 |
|
| 233 |
It's similar to ``phrase search condition`` but it doesn't require the |
| 234 |
default match columns. You need to specify match column for the phrase |
| 235 |
search condition by ``column:`` instead of ``--match_columns`` option |
| 236 |
of :doc:`/reference/commands/select`. |
| 237 |
|
| 238 |
The different between ``phrase search condition`` and ``phrase search |
| 239 |
condition (with explicit match column)`` is similar to between ``full |
| 240 |
text search condition`` and ``full text search condition (with |
| 241 |
explicit match column)``. ``Phrase search condition`` supports |
| 242 |
advanced match columns but ``phrase search condition (with explicit |
| 243 |
match column)`` isn't supported. See description of ``full text search |
| 244 |
condition (with explicit match column)`` about advanced match columns. |
| 245 |
|
| 246 |
Here is a simple example: |
| 247 |
|
| 248 |
.. groonga-command |
| 249 |
.. include:: ../../example/reference/grn_expr/query_syntax/simple_phrase_search_with_explicit_match_column.log |
| 250 |
.. select Entries --query 'content:@"I started"' |
| 251 |
|
| 252 |
The expression matches records that contain a phrase ``I started`` in |
| 253 |
``content`` column value. ``I also started`` isn't matched because |
| 254 |
``I`` and ``started`` aren't adjacent. |
| 255 |
|
| 256 |
.. _query-syntax-prefix-search-condition: |
| 257 |
|
| 258 |
Prefix search condition |
| 259 |
^^^^^^^^^^^^^^^^^^^^^^^ |
| 260 |
|
| 261 |
Its syntax is ``column:^value`` or ``value*``. |
| 262 |
|
| 263 |
This conditional expression does prefix search with ``value``. Prefix |
| 264 |
search searches records that contain a word that starts with ``value``. |
| 265 |
|
| 266 |
You can use fast prefix search against a column. The column must be |
| 267 |
indexed and index table must be patricia trie table |
| 268 |
(``TABLE_PAT_KEY``) or double array trie table |
| 269 |
(``TABLE_DAT_KEY``). You can also use fast prefix search against |
| 270 |
``_key`` pseudo column of patricia trie table or double array trie |
| 271 |
table. You don't need to index ``_key``. |
| 272 |
|
| 273 |
Prefix search can be used with other table types but it causes all |
| 274 |
records scan. It's not problem for small records but it spends more |
| 275 |
time for large records. |
| 276 |
|
| 277 |
It doesn't require the default match columns such as ``full text |
| 278 |
search condition`` and ``phrase search condition``. |
| 279 |
|
| 280 |
Here is a simple example: |
| 281 |
|
| 282 |
.. groonga-command |
| 283 |
.. include:: ../../example/reference/grn_expr/query_syntax/simple_prefix_search.log |
| 284 |
.. select Entries --query '_key:^Goo' |
| 285 |
|
| 286 |
The expression matches records that contain a word that starts with |
| 287 |
``Goo`` in ``_key`` pseudo column value. ``Good-bye Senna`` and |
| 288 |
``Good-bye Tritonn`` are matched with the expression. |
| 289 |
|
| 290 |
.. _query-syntax-suffix-search-condition: |
| 291 |
|
| 292 |
Suffix search condition |
| 293 |
^^^^^^^^^^^^^^^^^^^^^^^ |
| 294 |
|
| 295 |
Its syntax is ``column:$value``. |
| 296 |
|
| 297 |
This conditional expression does suffix search with ``value``. Suffix |
| 298 |
search searches records that contain a word that ends with ``value``. |
| 299 |
|
| 300 |
You can use fast suffix search against a column. The column must be |
| 301 |
indexed and index table must be patricia trie table |
| 302 |
(``TABLE_PAT_KEY``) with ``KEY_WITH_SIS`` flag. You can also use fast |
| 303 |
suffix search against ``_key`` pseudo column of patricia trie table |
| 304 |
(``TABLE_PAT_KEY``) with ``KEY_WITH_SIS`` flag. You don't need to |
| 305 |
index ``_key``. We recommended that you use index column based fast |
| 306 |
suffix search instead of ``_key`` based fast suffix search. ``_key`` |
| 307 |
based fast suffix search returns automatically registered |
| 308 |
substrings. (TODO: write document about suffix search and link to it |
| 309 |
from here.) |
| 310 |
|
| 311 |
.. note:: |
| 312 |
|
| 313 |
Fast suffix search can be used only for non-ASCII characters such |
| 314 |
as hiragana in Japanese. You cannot use fast suffix search for |
| 315 |
ASCII character. |
| 316 |
|
| 317 |
Suffix search can be used with other table types or patricia trie |
| 318 |
table without ``KEY_WITH_SIS`` flag but it causes all records |
| 319 |
scan. It's not problem for small records but it spends more time for |
| 320 |
large records. |
| 321 |
|
| 322 |
It doesn't require the default match columns such as ``full text |
| 323 |
search condition`` and ``phrase search condition``. |
| 324 |
|
| 325 |
Here is a simple example. It uses fast suffix search for hiragana in |
| 326 |
Japanese that is one of non-ASCII characters. |
| 327 |
|
| 328 |
.. groonga-command |
| 329 |
.. include:: ../../example/reference/grn_expr/query_syntax/simple_suffix_search.log |
| 330 |
.. table_create Titles TABLE_NO_KEY |
| 331 |
.. column_create Titles content COLUMN_SCALAR ShortText |
| 332 |
.. table_create SuffixSearchTerms TABLE_PAT_KEY|KEY_WITH_SIS ShortText |
| 333 |
.. column_create SuffixSearchTerms index COLUMN_INDEX Titles content |
| 334 |
.. load --table Titles |
| 335 |
.. [ |
| 336 |
.. {"content": "ぐるんが"}, |
| 337 |
.. {"content": "むるんが"}, |
| 338 |
.. {"content": "せな"}, |
| 339 |
.. {"content": "とりとん"} |
| 340 |
.. ] |
| 341 |
.. select Titles --query 'content:$んが' |
| 342 |
|
| 343 |
The expression matches records that have value that ends with ``んが`` |
| 344 |
in ``content`` column value. ``ぐるんが`` and ``むるんが`` are matched |
| 345 |
with the expression. |
| 346 |
|
| 347 |
.. _query-syntax-near-search-condition: |
| 348 |
|
| 349 |
Near search condition |
| 350 |
^^^^^^^^^^^^^^^^^^^^^ |
| 351 |
|
| 352 |
Its syntax is ``*N"token1 token2 ..."``. |
| 353 |
|
| 354 |
This conditional expression does near search with ``token1``, |
| 355 |
``token2`` and ``...``. Near search searches records that contain the |
| 356 |
all specified tokens and there are at most 10 tokens between them. For |
| 357 |
example, ``*N"a b c"`` matches ``a 1 2 3 4 5 b 6 7 8 9 10 c`` but |
| 358 |
doesn't match ``a 1 2 3 4 5 b 6 7 8 9 10 11 c``: |
| 359 |
|
| 360 |
.. groonga-command |
| 361 |
.. include:: ../../example/reference/grn_expr/query_syntax/near_search_search.log |
| 362 |
.. table_create NearTokens TABLE_NO_KEY |
| 363 |
.. column_create NearTokens content COLUMN_SCALAR ShortText |
| 364 |
.. table_create NearTokenTerms TABLE_PAT_KEY ShortText \ |
| 365 |
.. --default_tokenizer TokenNgram \ |
| 366 |
.. --normalizer NormalizerNFKC130 |
| 367 |
.. column_create NearTokenTerms index COLUMN_INDEX|WITH_POSITION \ |
| 368 |
.. NearTokens content |
| 369 |
.. load --table NearTokens |
| 370 |
.. [ |
| 371 |
.. {"content": "a 1 2 3 4 5 b 6 7 8 9 10 c"}, |
| 372 |
.. {"content": "a 1 2 3 4 5 b 6 7 8 9 10 11 c"}, |
| 373 |
.. {"content": "a 1 2 3 4 5 b 6 7 8 9 10 11 12 c"} |
| 374 |
.. ] |
| 375 |
.. select NearTokens --match_columns content --query '*N"a b c"' |
| 376 |
|
| 377 |
Note that you must specify ``WITH_POSITION`` to an index column that |
| 378 |
is used for near search. If you don't specify ``WITH_POSITION``, near |
| 379 |
search can't count distance correctly. |
| 380 |
|
| 381 |
You can customize the max interval of the given tokens (``10`` by |
| 382 |
default) by specifying a number after ``*N``. Here is an example that |
| 383 |
uses ``2`` as the max interval of the given tokens:: |
| 384 |
|
| 385 |
*N2"..." |
| 386 |
|
| 387 |
Here is an example to customize the max interval of the given tokens: |
| 388 |
|
| 389 |
.. groonga-command |
| 390 |
.. include:: ../../example/reference/grn_expr/query_syntax/near_search_max_interval.log |
| 391 |
.. select NearTokens --match_columns content --query '*N11"a b c"' |
| 392 |
|
| 393 |
To be precious, you can specify a word instead of a token for near |
| 394 |
search. Because the passed text is tokenized before near search. A |
| 395 |
word consists of one or more tokens. If you specify a word, it may not |
| 396 |
work as you expected. For example, ``*N"a1b2c3d"`` matches both ``a 1 |
| 397 |
b 2 c 3 d`` and ``a b c d 1 2 3``: |
| 398 |
|
| 399 |
.. groonga-command |
| 400 |
.. include:: ../../example/reference/grn_expr/query_syntax/near_search_word.log |
| 401 |
.. load --table NearTokens |
| 402 |
.. [ |
| 403 |
.. {"content": "a 1 b 2 c 3 d"}, |
| 404 |
.. {"content": "a b c d 1 2 3"} |
| 405 |
.. ] |
| 406 |
.. select NearTokens --match_columns content --query '*N"a1b2c3d"' |
| 407 |
|
| 408 |
Because ``*N"a1b2c3d"`` equals to ``*N"a 1 b 2 c 3 d"``. |
| 409 |
|
| 410 |
If you want to specify words, |
| 411 |
:ref:`query-syntax-near-phrase-search-condition` is what you want. |
| 412 |
|
| 413 |
.. versionadded:: 12.0.1 |
| 414 |
The max intervals of each token. |
| 415 |
|
| 416 |
You can specify the max intervals of each token. The default is no |
| 417 |
limit. It means that all intervals of each token are valid as long as |
| 418 |
the max interval is satisfied. |
| 419 |
|
| 420 |
Here is an example that use ``2`` for the max interval of the first |
| 421 |
interval and ``4`` for the max interval of the second interval:: |
| 422 |
|
| 423 |
*N10,2|4"a b c" |
| 424 |
|
| 425 |
``10`` is the max interval. |
| 426 |
|
| 427 |
``|`` is the separator of the max intervals of each token. |
| 428 |
|
| 429 |
This matches ``a x b x x x c``. But this doesn't match ``a x x b c``, |
| 430 |
``a b x x x x c`` and so on because the former has ``3`` interval for |
| 431 |
the first interval that is larger than ``2`` and the latter has ``5`` |
| 432 |
interval for the second interval that is later than ``4``. |
| 433 |
|
| 434 |
Here is an example that specifies the max intervals of each token: |
| 435 |
|
| 436 |
.. groonga-command |
| 437 |
.. include:: ../../example/reference/grn_expr/query_syntax/near_search_max_element_intervals.log |
| 438 |
.. select NearTokens --match_columns content --query '*N11,5|5"a b c"' |
| 439 |
.. select NearTokens --match_columns content --query '*N11,5|6"a b c"' |
| 440 |
|
| 441 |
You can omit one or more intervals. Omitted intervals are treated as |
| 442 |
``-1``. It means that ``*N11,5`` equals ``*N11,5|-1``. ``-1`` means |
| 443 |
that no limit. |
| 444 |
|
| 445 |
Here is an example that omits an interval: |
| 446 |
|
| 447 |
.. groonga-command |
| 448 |
.. include:: ../../example/reference/grn_expr/query_syntax/near_search_max_element_intervals_omit.log |
| 449 |
.. select NearTokens --match_columns content --query '*N11,5"a b c"' |
| 450 |
.. select NearTokens --match_columns content --query '*N11,5|-1"a b c"' |
| 451 |
|
| 452 |
You can specify extra intervals. They are just ignored: |
| 453 |
|
| 454 |
.. groonga-command |
| 455 |
.. include:: ../../example/reference/grn_expr/query_syntax/near_search_max_element_intervals_extra.log |
| 456 |
.. select NearTokens --match_columns content --query '*N11,5|5|1|1|1"a b c"' |
| 457 |
.. select NearTokens --match_columns content --query '*N11,5|5"a b c"' |
| 458 |
|
| 459 |
.. _query-syntax-near-phrase-search-condition: |
| 460 |
|
| 461 |
Near phrase search condition |
| 462 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 463 |
|
| 464 |
Its syntax is ``*NP"phrase1 phrase2 ..."``. |
| 465 |
|
| 466 |
This conditional expression does near phrase search with ``phrase1``, |
| 467 |
``phrase2`` and ``...``. Near phrase search searches records that |
| 468 |
contain the all specified phrases and there are at most 10 tokens |
| 469 |
between them. For example, ``*NP"a1b2c3d"`` matches ``a 1 b 2 c 3 d`` |
| 470 |
but doesn't match ``a b c d 1 2 3``. Because the latter uses different |
| 471 |
order: |
| 472 |
|
| 473 |
.. groonga-command |
| 474 |
.. include:: ../../example/reference/grn_expr/query_syntax/near_phrase_search_search.log |
| 475 |
.. select NearTokens --match_columns content --query '*NP"a1b2c3d"' |
| 476 |
|
| 477 |
You can use a phrase that includes spaces by quoting such as |
| 478 |
``*NP"\"groonga mroonga\" pgroonga"``. Note that you need to escape |
| 479 |
``\"`` in command syntax such as ``*NP"\\\"groonga mroonga\\\" |
| 480 |
pgroonga"``. This query matches ``groonga mroonga pgroonga`` but |
| 481 |
doesn't match ``groonga pgroonga mroonga`` because ``mroonga`` isn't |
| 482 |
right after ``groonga``: |
| 483 |
|
| 484 |
.. groonga-command |
| 485 |
.. include:: ../../example/reference/grn_expr/query_syntax/near_search_word.log |
| 486 |
.. load --table NearTokens |
| 487 |
.. [ |
| 488 |
.. {"content": "groonga mroonga rroonga pgroonga"}, |
| 489 |
.. {"content": "groonga rroonga pgroonga mroonga"} |
| 490 |
.. ] |
| 491 |
.. select NearTokens \ |
| 492 |
.. --match_columns content \ |
| 493 |
.. --query '*NP"\\\"groonga mroonga\\\" pgroonga"' |
| 494 |
|
| 495 |
You can customize the max interval of the given phrases (``10`` by |
| 496 |
default) by specifying a number after ``*NP``. Here is an example that |
| 497 |
uses ``2`` as the max interval of the given phrases:: |
| 498 |
|
| 499 |
*NP2"..." |
| 500 |
|
| 501 |
Here is an example to customize the max interval of the given phrases: |
| 502 |
|
| 503 |
.. groonga-command |
| 504 |
.. include:: ../../example/reference/grn_expr/query_syntax/near_phrase_search_max_interval.log |
| 505 |
.. select NearTokens --match_columns content --query '*NP1"groonga pgroonga"' |
| 506 |
|
| 507 |
You can use additional interval only for the last phrase. It means |
| 508 |
that you can accept more distance only between the second to last |
| 509 |
phrase and the last phrase. This is useful for implementing a near |
| 510 |
phrase search in the same sentence. If you specify ``.`` (sentence end |
| 511 |
phrase) as the last phrase and specify ``-1`` as the additional last |
| 512 |
interval, the other specified phrases must be appeared before |
| 513 |
``.``. You must append ``$`` to the last phrase like ``.$``. |
| 514 |
|
| 515 |
Here is an example that uses ``-1`` as the additional last interval of |
| 516 |
the given phrases:: |
| 517 |
|
| 518 |
*NP10,-1"a b .$" |
| 519 |
|
| 520 |
Here is an example to customize the additional last interval of the |
| 521 |
given phrases: |
| 522 |
|
| 523 |
.. groonga-command |
| 524 |
.. include:: ../../example/reference/grn_expr/query_syntax/near_phrase_search_additional_last_interval_negative.log |
| 525 |
.. load --table NearTokens |
| 526 |
.. [ |
| 527 |
.. {"content": "x 1 y 2 3 4 . x 1 2 y 3 z 4 5 6 7 ."}, |
| 528 |
.. {"content": "x 1 2 y 3 4 . x 1 2 y 3 z 4 5 6 7 ."}, |
| 529 |
.. {"content": "x 1 2 3 y 4 . x 1 y 2 z 3 4 5 6 7 ."}, |
| 530 |
.. ] |
| 531 |
.. select NearTokens --match_columns content --query '*NP2,-1"x y .$"' |
| 532 |
|
| 533 |
You can also use positive number for the additional last interval. If |
| 534 |
you specify positive number as the additional last interval, all of |
| 535 |
the following conditions must be satisfied: |
| 536 |
|
| 537 |
1. The interval between the first phrase and the second to last |
| 538 |
phrase is less than or equals to ``the max interval``. |
| 539 |
|
| 540 |
2. The interval between the first phrase and the last phrase is less |
| 541 |
than or equals to ``the max interval`` + ``the additional last |
| 542 |
interval``. |
| 543 |
|
| 544 |
If you specify negative number as the additional last interval, the |
| 545 |
second condition isn't required. Appearing the last phrase is just |
| 546 |
needed. |
| 547 |
|
| 548 |
Here is an example to use positive number as the additional last interval: |
| 549 |
|
| 550 |
.. groonga-command |
| 551 |
.. include:: ../../example/reference/grn_expr/query_syntax/near_phrase_search_additional_last_interval_positive.log |
| 552 |
.. select NearTokens --match_columns content --query '*NP2,4"x y .$"' |
| 553 |
|
| 554 |
.. versionadded:: 12.0.1 |
| 555 |
The max intervals of each phrase. |
| 556 |
|
| 557 |
You can also specify the max intervals of each phrase like |
| 558 |
:ref:`query-syntax-near-search-condition`. |
| 559 |
|
| 560 |
Here is an example: |
| 561 |
|
| 562 |
.. groonga-command |
| 563 |
.. include:: ../../example/reference/grn_expr/query_syntax/near_phrase_search_max_element_intervals.log |
| 564 |
.. select NearTokens --match_columns content --query '*NP11,0,5|5"a b c"' |
| 565 |
.. select NearTokens --match_columns content --query '*NP11,0,5|6"a b c"' |
| 566 |
|
| 567 |
.. _query-syntax-near-phrase-product-search-condition: |
| 568 |
|
| 569 |
Near phrase product search condition |
| 570 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 571 |
|
| 572 |
.. versionadded:: 11.1.1 |
| 573 |
|
| 574 |
Its syntax is ``*NPP"(phrase1_1 phrase1_2 ...) (phrase2_1 phrase2_2 |
| 575 |
...) ..."``. |
| 576 |
|
| 577 |
This conditional expression does multiple |
| 578 |
:ref:`query-syntax-near-phrase-search-condition`. Phrases for each |
| 579 |
:ref:`query-syntax-near-phrase-search-condition` are computed as |
| 580 |
product of ``{phrase1_1, phrase1_2, ...}``, ``{phrase2_1, phrase2_2, |
| 581 |
...}`` and ``...``. For example, ``*NPP"(a b c) (d e)"`` uses the |
| 582 |
following phrases for near phrase searches: |
| 583 |
|
| 584 |
* ``a d`` |
| 585 |
* ``a e`` |
| 586 |
* ``b d`` |
| 587 |
* ``b e`` |
| 588 |
* ``c d`` |
| 589 |
* ``c e`` |
| 590 |
|
| 591 |
Here is a simple example: |
| 592 |
|
| 593 |
.. groonga-command |
| 594 |
.. include:: ../../example/reference/grn_expr/query_syntax/near_phrase_product_search_simple.log |
| 595 |
.. select NearTokens --match_columns content --query '*NPP"(a x) (b y)"' |
| 596 |
|
| 597 |
You can use the all features of |
| 598 |
:ref:`query-syntax-near-phrase-search-condition` such as the max |
| 599 |
interval, ``$`` for the last phrase and the additional last |
| 600 |
interval. |
| 601 |
|
| 602 |
.. groonga-command |
| 603 |
.. include:: ../../example/reference/grn_expr/query_syntax/near_phrase_product_search_options.log |
| 604 |
.. select NearTokens --match_columns content --query '*NPP2,-1"(a x) (b c y) (d$ .$)"' |
| 605 |
|
| 606 |
.. versionadded:: 12.0.1 |
| 607 |
The max intervals of each phrase. |
| 608 |
|
| 609 |
You can also specify the max intervals of each phrase like |
| 610 |
:ref:`query-syntax-near-search-condition`. |
| 611 |
|
| 612 |
Here is an example: |
| 613 |
|
| 614 |
.. groonga-command |
| 615 |
.. include:: ../../example/reference/grn_expr/query_syntax/near_phrase_product_search_max_element_intervals.log |
| 616 |
.. select NearTokens --match_columns content --query '*NPP11,0,5|5"(a x) (b y) (c z)"' |
| 617 |
.. select NearTokens --match_columns content --query '*NPP11,0,5|6"(a x) (b y) (c z)"' |
| 618 |
|
| 619 |
This is more effective than multiple |
| 620 |
:ref:`query-syntax-near-phrase-search-condition` . |
| 621 |
|
| 622 |
.. _query-syntax-ordered-near-phrase-search-condition: |
| 623 |
|
| 624 |
Ordered near phrase search condition |
| 625 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 626 |
|
| 627 |
.. versionadded:: 11.0.9 |
| 628 |
|
| 629 |
It's syntax is ``*ONP"phrase1 phrase2 ..."`` |
| 630 |
|
| 631 |
This conditional expression does ordered near phrase search with |
| 632 |
``phrase1``, ``phrase2`` and ``...``. Ordered near phrase search is |
| 633 |
similar to :ref:`query-syntax-near-phrase-search-condition` but |
| 634 |
ordered near phrase search checks phrases order. For example, |
| 635 |
``*ONP"groonga mroonga pgroonga"`` matches ``groonga mroonga rroonga |
| 636 |
pgroonga`` but doesn't match ``groonga rroonga pgroonga |
| 637 |
mroonga``. Because the latter uses different order: |
| 638 |
|
| 639 |
.. groonga-command |
| 640 |
.. include:: ../../example/reference/grn_expr/query_syntax/ordered_near_phrase_search_search.log |
| 641 |
.. select NearTokens \ |
| 642 |
.. --match_columns content \ |
| 643 |
.. --query '*ONP"groonga mroonga pgroonga"' |
| 644 |
|
| 645 |
You can use the all features of |
| 646 |
:ref:`query-syntax-near-phrase-search-condition` such as the max |
| 647 |
interval and the additional last interval. But you don't need to |
| 648 |
specify ``$`` for the last phrase because the last phrase in query is |
| 649 |
the last phrase. |
| 650 |
|
| 651 |
.. versionadded:: 12.0.1 |
| 652 |
The max intervals of each phrase. |
| 653 |
|
| 654 |
You can also specify the max intervals of each phrase like |
| 655 |
:ref:`query-syntax-near-search-condition`. |
| 656 |
|
| 657 |
.. _query-syntax-ordered-near-phrase-product-search-condition: |
| 658 |
|
| 659 |
Ordered near phrase product search condition |
| 660 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 661 |
|
| 662 |
.. versionadded:: 11.1.1 |
| 663 |
|
| 664 |
Its syntax is ``*ONPP"(phrase1_1 phrase1_2 ...) (phrase2_1 phrase2_2 |
| 665 |
...) ..."``. |
| 666 |
|
| 667 |
This conditional expression does ordered near phrase product |
| 668 |
search. Ordered near phrase product search is similar to |
| 669 |
:ref:`query-syntax-near-phrase-product-search-condition` but ordered |
| 670 |
near phrase product search checks phrases order like |
| 671 |
:ref:`query-syntax-ordered-near-phrase-search-condition`. For example, |
| 672 |
``*ONPP"(a b c) (d e)"`` matches ``a 1 d`` but doesn't match ``d 1 |
| 673 |
a``. Because the latter uses different order. |
| 674 |
|
| 675 |
Here is a simple example: |
| 676 |
|
| 677 |
.. groonga-command |
| 678 |
.. include:: ../../example/reference/grn_expr/query_syntax/ordered_near_phrase_product_search_simple.log |
| 679 |
.. select NearTokens \ |
| 680 |
.. --match_columns content \ |
| 681 |
.. --query '*ONPP"(a x) (b y)"' |
| 682 |
|
| 683 |
You can use the all features of |
| 684 |
:ref:`query-syntax-near-phrase-search-condition` such as the max |
| 685 |
interval and the additional last interval. But you don't need to |
| 686 |
specify ``$`` for the last phrase because the last phrase in query is |
| 687 |
the last phrase. |
| 688 |
|
| 689 |
.. versionadded:: 12.0.1 |
| 690 |
The max intervals of each phrase. |
| 691 |
|
| 692 |
You can also specify the max intervals of each phrase like |
| 693 |
:ref:`query-syntax-near-search-condition`. |
| 694 |
|
| 695 |
.. _query-syntax-similar-search-condition: |
| 696 |
|
| 697 |
Similar search condition |
| 698 |
^^^^^^^^^^^^^^^^^^^^^^^^ |
| 699 |
|
| 700 |
TODO |
| 701 |
|
| 702 |
.. _query-syntax-equal-condition: |
| 703 |
|
| 704 |
Equal condition |
| 705 |
^^^^^^^^^^^^^^^ |
| 706 |
|
| 707 |
Its syntax is ``column:value``. |
| 708 |
|
| 709 |
It matches records that ``column`` value is equal to ``value``. |
| 710 |
|
| 711 |
It doesn't require the default match columns such as ``full text |
| 712 |
search condition`` and ``phrase search condition``. |
| 713 |
|
| 714 |
Here is a simple example: |
| 715 |
|
| 716 |
.. groonga-command |
| 717 |
.. include:: ../../example/reference/grn_expr/query_syntax/simple_equal.log |
| 718 |
.. select Entries --query _key:Groonga |
| 719 |
|
| 720 |
The expression matches records that ``_key`` column value is |
| 721 |
equal to ``Groonga``. |
| 722 |
|
| 723 |
.. _query-syntax-not-equal-condition: |
| 724 |
|
| 725 |
Not equal condition |
| 726 |
^^^^^^^^^^^^^^^^^^^ |
| 727 |
|
| 728 |
Its syntax is ``column:!value``. |
| 729 |
|
| 730 |
It matches records that ``column`` value isn't equal to ``value``. |
| 731 |
|
| 732 |
It doesn't require the default match columns such as ``full text |
| 733 |
search condition`` and ``phrase search condition``. |
| 734 |
|
| 735 |
Here is a simple example: |
| 736 |
|
| 737 |
.. groonga-command |
| 738 |
.. include:: ../../example/reference/grn_expr/query_syntax/simple_not_equal.log |
| 739 |
.. select Entries --query _key:!Groonga |
| 740 |
|
| 741 |
The expression matches records that ``_key`` column value is not equal |
| 742 |
to ``Groonga``. |
| 743 |
|
| 744 |
.. _query-syntax-less-than-condition: |
| 745 |
|
| 746 |
Less than condition |
| 747 |
^^^^^^^^^^^^^^^^^^^ |
| 748 |
|
| 749 |
Its syntax is ``column:<value``. |
| 750 |
|
| 751 |
It matches records that ``column`` value is less than ``value``. |
| 752 |
|
| 753 |
If ``column`` type is numerical type such as ``Int32``, ``column`` |
| 754 |
value and ``value`` are compared as number. If ``column`` type is text |
| 755 |
type such as ``ShortText``, ``column`` value and ``value`` are |
| 756 |
compared as bit sequence. |
| 757 |
|
| 758 |
It doesn't require the default match columns such as ``full text |
| 759 |
search condition`` and ``phrase search condition``. |
| 760 |
|
| 761 |
Here is a simple example: |
| 762 |
|
| 763 |
.. groonga-command |
| 764 |
.. include:: ../../example/reference/grn_expr/query_syntax/simple_less_than.log |
| 765 |
.. select Entries --query n_likes:<10 |
| 766 |
|
| 767 |
The expression matches records that ``n_likes`` column value is less |
| 768 |
than ``10``. |
| 769 |
|
| 770 |
.. _query-syntax-greater-than-condition: |
| 771 |
|
| 772 |
Greater than condition |
| 773 |
^^^^^^^^^^^^^^^^^^^^^^ |
| 774 |
|
| 775 |
Its syntax is ``column:>value``. |
| 776 |
|
| 777 |
It matches records that ``column`` value is greater than ``value``. |
| 778 |
|
| 779 |
If ``column`` type is numerical type such as ``Int32``, ``column`` |
| 780 |
value and ``value`` are compared as number. If ``column`` type is text |
| 781 |
type such as ``ShortText``, ``column`` value and ``value`` are |
| 782 |
compared as bit sequence. |
| 783 |
|
| 784 |
It doesn't require the default match columns such as ``full text |
| 785 |
search condition`` and ``phrase search condition``. |
| 786 |
|
| 787 |
Here is a simple example: |
| 788 |
|
| 789 |
.. groonga-command |
| 790 |
.. include:: ../../example/reference/grn_expr/query_syntax/simple_greater_than.log |
| 791 |
.. select Entries --query n_likes:>10 |
| 792 |
|
| 793 |
The expression matches records that ``n_likes`` column value is greater |
| 794 |
than ``10``. |
| 795 |
|
| 796 |
.. _query-syntax-less-than-or-equal-condition: |
| 797 |
|
| 798 |
Less than or equal to condition |
| 799 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 800 |
|
| 801 |
Its syntax is ``column:<=value``. |
| 802 |
|
| 803 |
It matches records that ``column`` value is less than or equal to |
| 804 |
``value``. |
| 805 |
|
| 806 |
If ``column`` type is numerical type such as ``Int32``, ``column`` |
| 807 |
value and ``value`` are compared as number. If ``column`` type is text |
| 808 |
type such as ``ShortText``, ``column`` value and ``value`` are |
| 809 |
compared as bit sequence. |
| 810 |
|
| 811 |
It doesn't require the default match columns such as ``full text |
| 812 |
search condition`` and ``phrase search condition``. |
| 813 |
|
| 814 |
Here is a simple example: |
| 815 |
|
| 816 |
.. groonga-command |
| 817 |
.. include:: ../../example/reference/grn_expr/query_syntax/simple_less_than_or_equal_to.log |
| 818 |
.. select Entries --query n_likes:<=10 |
| 819 |
|
| 820 |
The expression matches records that ``n_likes`` column value is less |
| 821 |
than or equal to ``10``. |
| 822 |
|
| 823 |
.. _query-syntax-greater-than-or-equal-condition: |
| 824 |
|
| 825 |
Greater than or equal to condition |
| 826 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 827 |
|
| 828 |
Its syntax is ``column:>=value``. |
| 829 |
|
| 830 |
It matches records that ``column`` value is greater than or equal to |
| 831 |
``value``. |
| 832 |
|
| 833 |
If ``column`` type is numerical type such as ``Int32``, ``column`` |
| 834 |
value and ``value`` are compared as number. If ``column`` type is text |
| 835 |
type such as ``ShortText``, ``column`` value and ``value`` are |
| 836 |
compared as bit sequence. |
| 837 |
|
| 838 |
It doesn't require the default match columns such as ``full text |
| 839 |
search condition`` and ``phrase search condition``. |
| 840 |
|
| 841 |
Here is a simple example: |
| 842 |
|
| 843 |
.. groonga-command |
| 844 |
.. include:: ../../example/reference/grn_expr/query_syntax/simple_greater_than_or_equal_to.log |
| 845 |
.. select Entries --query n_likes:>=10 |
| 846 |
|
| 847 |
The expression matches records that ``n_likes`` column value is |
| 848 |
greater than or equal to ``10``. |
| 849 |
|
| 850 |
.. _query-syntax-regular-expression-condition: |
| 851 |
|
| 852 |
Regular expression condition |
| 853 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 854 |
|
| 855 |
.. versionadded:: 5.0.1 |
| 856 |
|
| 857 |
Its syntax is ``column:~pattern``. |
| 858 |
|
| 859 |
It matches records that ``column`` value is matched to |
| 860 |
``pattern``. ``pattern`` must be valid |
| 861 |
:doc:`/reference/regular_expression`. |
| 862 |
|
| 863 |
The following example uses ``.roonga`` as pattern. It matches |
| 864 |
``Groonga``, ``Mroonga`` and so on. |
| 865 |
|
| 866 |
.. groonga-command |
| 867 |
.. include:: ../../example/reference/grn_expr/query_syntax/simple_regular_expression.log |
| 868 |
.. select Entries --query content:~.roonga |
| 869 |
|
| 870 |
In most cases, regular expression is evaluated sequentially. So it may |
| 871 |
be slow against many records. |
| 872 |
|
| 873 |
In some cases, Groonga evaluates regular expression by index. It's |
| 874 |
very fast. See :doc:`/reference/regular_expression` for details. |
| 875 |
|
| 876 |
.. _query-syntax-combined-expression: |
| 877 |
|
| 878 |
Combined expression |
| 879 |
------------------- |
| 880 |
|
| 881 |
Here is available combined expression list. |
| 882 |
|
| 883 |
.. _query-syntax-logical-or: |
| 884 |
|
| 885 |
Logical OR |
| 886 |
^^^^^^^^^^ |
| 887 |
|
| 888 |
Its syntax is ``a OR b``. |
| 889 |
|
| 890 |
``a`` and ``b`` are conditional expressions, conbinded expressions or |
| 891 |
assignment expressions. |
| 892 |
|
| 893 |
If at least one of ``a`` and ``b`` are matched, ``a OR b`` is matched. |
| 894 |
|
| 895 |
Here is a simple example: |
| 896 |
|
| 897 |
.. groonga-command |
| 898 |
.. include:: ../../example/reference/grn_expr/query_syntax/simple_logical_or.log |
| 899 |
.. select Entries --query 'n_likes:>10 OR content:@senna' |
| 900 |
|
| 901 |
The expression matches records that ``n_likes`` column value is |
| 902 |
greater than ``10`` or contain a word ``senna`` in ``content`` column |
| 903 |
value. |
| 904 |
|
| 905 |
.. _query-syntax-logical-and: |
| 906 |
|
| 907 |
Logical AND |
| 908 |
^^^^^^^^^^^ |
| 909 |
|
| 910 |
Its syntax is ``a + b`` or just ``a b``. |
| 911 |
|
| 912 |
``a`` and ``b`` are conditional expressions, conbinded expressions or |
| 913 |
assignment expressions. |
| 914 |
|
| 915 |
If both ``a`` and ``b`` are matched, ``a + b`` is matched. |
| 916 |
|
| 917 |
You can specify ``+`` the first expression such as ``+a``. The ``+`` |
| 918 |
is just ignored. |
| 919 |
|
| 920 |
Here is a simple example: |
| 921 |
|
| 922 |
.. groonga-command |
| 923 |
.. include:: ../../example/reference/grn_expr/query_syntax/simple_logical_and.log |
| 924 |
.. select Entries --query 'n_likes:>=10 + content:@groonga' |
| 925 |
|
| 926 |
The expression matches records that ``n_likes`` column value is |
| 927 |
greater than or equal to ``10`` and contain a word ``groonga`` in |
| 928 |
``content`` column value. |
| 929 |
|
| 930 |
.. _query-syntax-logical-and-not: |
| 931 |
|
| 932 |
Logical AND NOT |
| 933 |
^^^^^^^^^^^^^^^ |
| 934 |
|
| 935 |
Its syntax is ``a - b``. |
| 936 |
|
| 937 |
``a`` and ``b`` are conditional expressions, conbinded expressions or |
| 938 |
assignment expressions. |
| 939 |
|
| 940 |
If ``a`` is matched and ``b`` is not matched, ``a - b`` is matched. |
| 941 |
|
| 942 |
You can not specify ``-`` the first expression such as ``-a``. It's |
| 943 |
syntax error. |
| 944 |
|
| 945 |
Here is a simple example: |
| 946 |
|
| 947 |
.. groonga-command |
| 948 |
.. include:: ../../example/reference/grn_expr/query_syntax/simple_logical_not.log |
| 949 |
.. select Entries --query 'n_likes:>=10 - content:@groonga' |
| 950 |
|
| 951 |
The expression matches records that ``n_likes`` column value is |
| 952 |
greater than or equal to ``10`` and don't contain a word ``groonga`` in |
| 953 |
``content`` column value. |
| 954 |
|
| 955 |
Grouping |
| 956 |
^^^^^^^^ |
| 957 |
|
| 958 |
Its syntax is ``(...)``. ``...`` is space separated expression list. |
| 959 |
|
| 960 |
``(...)`` groups one ore more expressions and they can be |
| 961 |
processed as an expression. ``a b OR c`` means that ``a`` and ``b`` |
| 962 |
are matched or ``c`` is matched. ``a (b OR c)`` means that ``a`` and |
| 963 |
one of ``b`` and ``c`` are matched. |
| 964 |
|
| 965 |
Here is a simple example: |
| 966 |
|
| 967 |
.. groonga-command |
| 968 |
.. include:: ../../example/reference/grn_expr/query_syntax/simple_grouping.log |
| 969 |
.. select Entries --query 'n_likes:<5 content:@senna OR content:@fast' |
| 970 |
.. select Entries --query 'n_likes:<5 (content:@senna OR content:@fast)' |
| 971 |
|
| 972 |
The first expression doesn't use grouping. It matches records that |
| 973 |
``n_likes:<5`` and ``content:@senna`` are matched or |
| 974 |
``content:@fast`` is matched. |
| 975 |
|
| 976 |
The second expression uses grouping. It matches records that |
| 977 |
``n_likes:<5`` and one of ``content:@senna`` or ``content:@fast`` |
| 978 |
are matched. |
| 979 |
|
| 980 |
.. _query-syntax-assignment-expression: |
| 981 |
|
| 982 |
Assignment expression |
| 983 |
--------------------- |
| 984 |
|
| 985 |
This section is for advanced users. Because assignment expression is |
| 986 |
disabled in ``--query`` option of :doc:`/reference/commands/select` by |
| 987 |
default. You need to specify ``ALLOW_COLUMN|ALLOW_UPDATE`` as |
| 988 |
``--query_flags`` option value to enable assignment expression. |
| 989 |
|
| 990 |
Assignment expression in query syntax has some limitations. So you |
| 991 |
should use :doc:`/reference/grn_expr/script_syntax` instead of query syntax for |
| 992 |
assignment. |
| 993 |
|
| 994 |
There is only one syntax for assignment expression. It's ``column:=value``. |
| 995 |
|
| 996 |
``value`` is assigned to ``column``. ``value`` is always processed as |
| 997 |
string in query syntax. ``value`` is casted to the type of ``column`` |
| 998 |
automatically. It causes some limitations. For example, you cannot use |
| 999 |
boolean literal such as ``true`` and ``false`` for ``Bool`` type |
| 1000 |
column. You need to use empty string for ``false`` but query syntax |
| 1001 |
doesn't support ``column:=`` syntax. |
| 1002 |
|
| 1003 |
See :doc:`/reference/cast` about cast. |