| 1 |
.. -*- rst -*- |
| 2 |
|
| 3 |
.. groonga-command |
| 4 |
.. database: functions_query_parallel_or |
| 5 |
|
| 6 |
``query_parallel_or`` |
| 7 |
===================== |
| 8 |
|
| 9 |
.. versionadded:: 11.0.1 |
| 10 |
|
| 11 |
Summary |
| 12 |
------- |
| 13 |
|
| 14 |
``query_parallel_or`` is similar to :doc:`query` but |
| 15 |
``query_parallel_or`` processes query that has multiple ``OR`` |
| 16 |
conditions in parallel. |
| 17 |
|
| 18 |
Syntax |
| 19 |
------ |
| 20 |
|
| 21 |
``query_parallel_or`` requires two or more parameters - |
| 22 |
``match_columns`` and ``query_string`` s. |
| 23 |
|
| 24 |
The ``options`` parameter is optional. |
| 25 |
|
| 26 |
:: |
| 27 |
|
| 28 |
query(match_columns, query_string0, query_string1, ..., query_stringN) |
| 29 |
query(match_columns, query_string0, query_string1, ..., query_stringN, options) |
| 30 |
|
| 31 |
You must specify at least one ``query_string``. |
| 32 |
|
| 33 |
``options`` uses the following format. All of key-value pairs are |
| 34 |
optional:: |
| 35 |
|
| 36 |
{ |
| 37 |
"expander": query_expander, |
| 38 |
"default_mode": default_mode, |
| 39 |
"default_operator": default_operator, |
| 40 |
"flags": flags |
| 41 |
} |
| 42 |
|
| 43 |
Usage |
| 44 |
----- |
| 45 |
|
| 46 |
Here are a schema definition and sample data to show usage. |
| 47 |
|
| 48 |
Sample schema: |
| 49 |
|
| 50 |
.. groonga-command |
| 51 |
.. include:: ../../example/reference/functions/query_parallel_or/usage_setup_schema.log |
| 52 |
.. table_create Documents TABLE_NO_KEY |
| 53 |
.. column_create Documents content COLUMN_SCALAR Text |
| 54 |
.. table_create Terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto |
| 55 |
.. column_create Terms documents_content_index COLUMN_INDEX|WITH_POSITION Documents content |
| 56 |
.. table_create Users TABLE_NO_KEY |
| 57 |
.. column_create Users name COLUMN_SCALAR ShortText |
| 58 |
.. column_create Users memo COLUMN_SCALAR ShortText |
| 59 |
.. table_create Lexicon TABLE_HASH_KEY ShortText \ |
| 60 |
.. --default_tokenizer 'TokenNgram("unify_alphabet", false)' \ |
| 61 |
.. --normalizer NormalizerNFKC130 |
| 62 |
.. column_create Lexicon users_name COLUMN_INDEX|WITH_POSITION Users name |
| 63 |
.. column_create Lexicon users_memo COLUMN_INDEX|WITH_POSITION Users memo |
| 64 |
|
| 65 |
Sample data: |
| 66 |
|
| 67 |
.. groonga-command |
| 68 |
.. include:: ../../example/reference/functions/query_parallel_or/usage_setup_data.log |
| 69 |
.. load --table Users |
| 70 |
.. [ |
| 71 |
.. {"name": "Alice", "memo": "Groonga user"}, |
| 72 |
.. {"name": "Alisa", "memo": "Mroonga user"}, |
| 73 |
.. {"name": "Bob", "memo": "Rroonga user"}, |
| 74 |
.. {"name": "Tom", "memo": "Nroonga user"}, |
| 75 |
.. {"name": "Tobby", "memo": "Groonga and Mroonga user. Mroonga is ..."} |
| 76 |
.. ] |
| 77 |
|
| 78 |
Here is an example to execute full text searches in parallel by |
| 79 |
``query_parallel_or`` function: |
| 80 |
|
| 81 |
.. groonga-command |
| 82 |
.. include:: ../../example/reference/functions/query_parallel_or/usage_basic.log |
| 83 |
.. select Users \ |
| 84 |
.. --output_columns name,memo,_score \ |
| 85 |
.. --filter 'query_parallel_or("name * 10 || memo", "alice", "Groonga")' |
| 86 |
|
| 87 |
This ``select`` command needs to execute the following full text |
| 88 |
searches: |
| 89 |
|
| 90 |
* ``"alice"`` against ``name`` |
| 91 |
* ``"alice"`` against ``memo`` |
| 92 |
* ``"Groonga"`` against ``name`` |
| 93 |
* ``"Groonga"`` against ``memo`` |
| 94 |
|
| 95 |
And all result sets of them are needed to be combined by ``OR``. |
| 96 |
|
| 97 |
``query`` function executes them in a sequential |
| 98 |
order. ``query_parallel_or`` function executes them in |
| 99 |
parallel. Result sets of both of them are same. |
| 100 |
|
| 101 |
Parameters |
| 102 |
---------- |
| 103 |
|
| 104 |
Required parameters |
| 105 |
^^^^^^^^^^^^^^^^^^^ |
| 106 |
|
| 107 |
There are two required parameters, ``match_columns`` and |
| 108 |
``query_string``. |
| 109 |
|
| 110 |
.. _query-parallel-or-match-columns: |
| 111 |
|
| 112 |
``match_columns`` |
| 113 |
""""""""""""""""" |
| 114 |
|
| 115 |
Specifies the default target columns for full text search by |
| 116 |
``query_string`` parameters. It is the same role as |
| 117 |
:ref:`select-match-columns` parameter in ``select``. |
| 118 |
|
| 119 |
Each pair of target column and query string is processed in |
| 120 |
parallel. For example, ``query_parallel_or("C1 || C2 || C3", "Q1", |
| 121 |
"Q2")`` has the following pairs: |
| 122 |
|
| 123 |
* ``C1 @ "Q1"`` |
| 124 |
* ``C2 @ "Q1"`` |
| 125 |
* ``C3 @ "Q1"`` |
| 126 |
* ``C1 @ "Q2"`` |
| 127 |
* ``C2 @ "Q2"`` |
| 128 |
* ``C3 @ "Q2"`` |
| 129 |
|
| 130 |
Each pair is processed in parallel. Degree of parallelism is depends |
| 131 |
on your system. The default max number of threads is ``N_CPU_THREADS / |
| 132 |
3``. |
| 133 |
|
| 134 |
``query_string`` |
| 135 |
"""""""""""""""" |
| 136 |
|
| 137 |
Specifies the search condition in |
| 138 |
:doc:`/reference/grn_expr/query_syntax`. It is the same role as |
| 139 |
``query`` parameter in ``select``. |
| 140 |
|
| 141 |
See :ref:`select-match-columns` about ``query`` parameter in |
| 142 |
``select``. |
| 143 |
|
| 144 |
You can specify multiple ``query_string`` s to execute full text |
| 145 |
searches in parallel. See also :ref:`query-parallel-or-match-columns` |
| 146 |
how to parallelize. |
| 147 |
|
| 148 |
Optional parameter |
| 149 |
^^^^^^^^^^^^^^^^^^ |
| 150 |
|
| 151 |
There are some optional parameters. |
| 152 |
|
| 153 |
``query_expander`` |
| 154 |
"""""""""""""""""" |
| 155 |
|
| 156 |
See :ref:`query-query-expander` for details. |
| 157 |
|
| 158 |
``default_mode`` |
| 159 |
"""""""""""""""" |
| 160 |
|
| 161 |
See :ref:`query-default-mode` for details. |
| 162 |
|
| 163 |
``default_operator`` |
| 164 |
"""""""""""""""""""" |
| 165 |
|
| 166 |
See :ref:`query-default-operator` for details. |
| 167 |
|
| 168 |
``flags`` |
| 169 |
""""""""" |
| 170 |
|
| 171 |
See :ref:`query-flags` for details. |
| 172 |
|
| 173 |
Return value |
| 174 |
------------ |
| 175 |
|
| 176 |
This function returns whether a record is matched or not as boolean. |
| 177 |
|
| 178 |
This function is also worked as a selector. It means that this |
| 179 |
function can be executable effectively. |
| 180 |
|
| 181 |
See also |
| 182 |
-------- |
| 183 |
|
| 184 |
* :doc:`/reference/commands/select` |
| 185 |
* :doc:`query` |