Debian Codegraph @

doc/source/reference/functions/escalate.rst

raw
1 .. -*- rst -*-
2
3 .. groonga-command
4 .. database: functions_escalate
5
6 ``escalate``
7 ============
8
9 .. versionadded:: 12.0.8
10
11 Summary
12 -------
13
14 .. note::
15
16 This function is experimental.
17
18 This `escalate` function is similar to the existing match escalation mechanism but is more close to common approach.
19
20 Match escalation is auto loose search.
21 If the number of matched records is equal or less than the threshold specified by ``match_escalation_threshold``, loose search is done automatically. It's match escalation.
22
23 Please refer to :doc:`/spec/search` about the search strategy escalation.
24
25 ``match_escalation_threshold`` is ``select``'s argument. In addition, the default value of ``match_escalation_threshold`` is `0`.
26 Please refer to :doc:`/reference/commands/select` about ``match_escalation_threshold``.
27
28 The existing match escalation mechanism is just for one full text search by inverted index.
29 Therefore, for example, if we can't get record in a search with a index that execute search strictly, we need to search with a index that execute search loosely once again.
30 Those processes take more.
31
32 However, ``escalate`` is for multiple full text search by inverted index.
33 Therefore, we can execute a search with a index that execute search strictly and a search with a index that execute search loosely in one query.
34 We can reduce overhead by using ``escalate``.
35
36 Syntax
37 ------
38
39 ``escalate`` requires one or more parameters.
40
41 .. code-block::
42
43 escalate(CONDITION_1,
44 THRESHOLD_2, CONDITION_2,
45 ...,
46 THRESHOLD_N, CONDITION_N)
47
48 ``CONDITION_N`` and ``THRESHOLD_N`` are pair.
49 However, ``CONDITION_1`` doesn't have a threshold as pair. Because this condition is always executed.
50
51 Usage
52 -----
53
54 Here are a schema definition and sample data to show usage.
55
56 Sample schema:
57
58 .. groonga-command
59 .. include:: ../../example/reference/functions/escalate/usage_setup_schema.log
60 .. table_create Users TABLE_HASH_KEY ShortText
61 .. column_create Users age COLUMN_SCALAR Int32
62 .. table_create Ages TABLE_HASH_KEY Int32
63 .. column_create Ages user_age COLUMN_INDEX Users age
64
65 Sample data:
66
67 .. groonga-command
68 .. include:: ../../example/reference/functions/escalate/usage_setup_data.log
69 .. load --table Users
70 .. [
71 .. {"_key": "Alice", "age": 12},
72 .. {"_key": "Bob", "age": 13},
73 .. {"_key": "Calros", "age": 15},
74 .. {"_key": "Dave", "age": 16},
75 .. {"_key": "Eric", "age": 20},
76 .. {"_key": "Frank", "age": 21}
77 .. ]
78
79 Here is a simple example.
80
81 .. groonga-command
82 .. include:: ../../example/reference/functions/escalate/usage_age.log
83 .. select Users --filter "escalate('age >= 65', 0, 'age >= 60', 0, 'age >= 50', 0, 'age >= 40', 0, 'age >= 30', 0, 'age >= 20')"
84
85 Parameters
86 ----------
87
88 ``CONDITION_1``
89 ~~~~~~~~~~~~~~~
90
91 ``CONDITION_1`` is required.
92
93 A condition that we specify ``CONDITION_1`` is always executed.
94 Therefore, ``CONDITION_1`` doesn't have a threshold as pair.
95
96 Normally, we specify the condition that we can the most narrow down search results.
97
98 ``CONDITION_1`` is a string that uses script syntax such as "number_column > 29".
99
100 ``CONDITION_N``
101 ~~~~~~~~~~~~~~~
102
103 ``CONDITION_N`` is optional.
104
105 If the number of searched results with the one before condition in threshold or less, ``escalate`` evaluate ``CONDITION_N``.
106
107 ``CONDITION_N`` is a string that uses script syntax such as "number_column > 29".
108
109 ``THRESHOLD_N``
110 ~~~~~~~~~~~~~~~
111
112 ``THRESHOLD_N`` is optional. However, when ``CONDITION_N`` exists ``THRESHOLD_N`` is required. (However, ``CONDITION_1`` doesn't have a threshold as pair.)
113
114 If the number of results that we search with ``CONDITION_N-1`` in ``THRESHOLD_N`` or less, ``escalate`` evaluate ``CONDITION_N``.
115 If the number of results that we search with ``CONDITION_N-1`` in more than ``THRESHOLD_N``, ``escalate`` doesn't evaluate ``CONDITION_N``.
116
117 ``THRESHOLD_N`` is an integer not less than ``0`` such as ``0`` and ``29``.
118
119 Return value
120 ------------
121
122 ``escalate`` returns whether a record is matched or not as boolean.
123