Skip to main content
`Ctrl`+`K`

# 7.15.22. `query_parallel_or`

Added in version 11.0.1.

## 7.15.22.1. Summary

`query_parallel_or` is similar to query but `query_parallel_or` processes query that has multiple `OR` conditions in parallel.

## 7.15.22.2. Syntax

`query_parallel_or` requires two or more parameters - `match_columns` and `query_string` s.

The `options` parameter is optional.

    query(match_columns, query_string0, query_string1, ..., query_stringN)
    query(match_columns, query_string0, query_string1, ..., query_stringN, options)

You must specify at least one `query_string`.

`options` uses the following format. All of key-value pairs are optional:

    {
      "expander": query_expander,
      "default_mode": default_mode,
      "default_operator": default_operator,
      "flags": flags
    }

## 7.15.22.3. Usage

Here are a schema definition and sample data to show usage.

Sample schema:

Execution example:

    table_create Documents TABLE_NO_KEY
    # [[0,1337566253.89858,0.000355720520019531],true]
    column_create Documents content COLUMN_SCALAR Text
    # [[0,1337566253.89858,0.000355720520019531],true]
    table_create Terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram  --normalizer NormalizerAuto
    # [[0,1337566253.89858,0.000355720520019531],true]
    column_create Terms documents_content_index COLUMN_INDEX|WITH_POSITION Documents content
    # [[0,1337566253.89858,0.000355720520019531],true]
    table_create Users TABLE_NO_KEY
    # [[0,1337566253.89858,0.000355720520019531],true]
    column_create Users name COLUMN_SCALAR ShortText
    # [[0,1337566253.89858,0.000355720520019531],true]
    column_create Users memo COLUMN_SCALAR ShortText
    # [[0,1337566253.89858,0.000355720520019531],true]
    table_create Lexicon TABLE_HASH_KEY ShortText \
      --default_tokenizer 'TokenNgram("unify_alphabet", false)' \
      --normalizer NormalizerNFKC130
    # [[0,1337566253.89858,0.000355720520019531],true]
    column_create Lexicon users_name COLUMN_INDEX|WITH_POSITION Users name
    # [[0,1337566253.89858,0.000355720520019531],true]
    column_create Lexicon users_memo COLUMN_INDEX|WITH_POSITION Users memo
    # [[0,1337566253.89858,0.000355720520019531],true]

Sample data:

Execution example:

    load --table Users
    [
    {"name": "Alice", "memo": "Groonga user"},
    {"name": "Alisa", "memo": "Mroonga user"},
    {"name": "Bob",   "memo": "Rroonga user"},
    {"name": "Tom",   "memo": "Nroonga user"},
    {"name": "Tobby", "memo": "Groonga and Mroonga user. Mroonga is ..."}
    ]
    # [[0,1337566253.89858,0.000355720520019531],5]

Here is an example to execute full text searches in parallel by `query_parallel_or` function:

Execution example:

    select Users \
      --output_columns name,memo,_score \
      --filter 'query_parallel_or("name * 10 || memo", "alice", "Groonga")'
    # [
    #   [
    #     0,
    #     1337566253.89858,
    #     0.000355720520019531
    #   ],
    #   [
    #     [
    #       [
    #         2
    #       ],
    #       [
    #         [
    #           "name",
    #           "ShortText"
    #         ],
    #         [
    #           "memo",
    #           "ShortText"
    #         ],
    #         [
    #           "_score",
    #           "Int32"
    #         ]
    #       ],
    #       [
    #         "Alice",
    #         "Groonga user",
    #         11
    #       ],
    #       [
    #         "Tobby",
    #         "Groonga and Mroonga user. Mroonga is ...",
    #         1
    #       ]
    #     ]
    #   ]
    # ]

This `select` command needs to execute the following full text searches:

> - `"alice"` against `name`

> - `"alice"` against `memo`

> - `"Groonga"` against `name`

> - `"Groonga"` against `memo`

And all result sets of them are needed to be combined by `OR`.

`query` function executes them in a sequential order. `query_parallel_or` function executes them in parallel. Result sets of both of them are same.

## 7.15.22.4. Parameters

### 7.15.22.4.1. Required parameters

There are two required parameters, `match_columns` and `query_string`.

#### 7.15.22.4.1.1. `match_columns`

Specifies the default target columns for full text search by `query_string` parameters. It is the same role as match_columns parameter in `select`.

Each pair of target column and query string is processed in parallel. For example, `query_parallel_or("C1 || C2 || C3", "Q1", "Q2")` has the following pairs:

> - `C1 @ "Q1"`

> - `C2 @ "Q1"`

> - `C3 @ "Q1"`

> - `C1 @ "Q2"`

> - `C2 @ "Q2"`

> - `C3 @ "Q2"`

Each pair is processed in parallel. Degree of parallelism is depends on your system. The default max number of threads is `N_CPU_THREADS / 3`.

#### 7.15.22.4.1.2. `query_string`

Specifies the search condition in Query syntax. It is the same role as `query` parameter in `select`.

See match_columns about `query` parameter in `select`.

You can specify multiple `query_string` s to execute full text searches in parallel. See also match_columns how to parallelize.

### 7.15.22.4.2. Optional parameter

There are some optional parameters.

#### 7.15.22.4.2.1. `query_expander`

See query_expander for details.

#### 7.15.22.4.2.2. `default_mode`

See default_mode for details.

#### 7.15.22.4.2.3. `default_operator`

See default_operator for details.

#### 7.15.22.4.2.4. `flags`

See flags for details.

## 7.15.22.5. Return value

This function returns whether a record is matched or not as boolean.

This function is also worked as a selector. It means that this function can be executable effectively.

## 7.15.22.6. See also

- select

- query