| 1 | /* |
| 2 | Copyright(C) 2022 Sutou Kouhei <[email protected]> |
| 3 | |
| 4 | This library is free software; you can redistribute it and/or |
| 5 | modify it under the terms of the GNU Lesser General Public |
| 6 | License as published by the Free Software Foundation; either |
| 7 | version 2.1 of the License, or (at your option) any later version. |
| 8 | |
| 9 | This library is distributed in the hope that it will be useful, |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | Lesser General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU Lesser General Public |
| 15 | License along with this library; if not, write to the Free Software |
| 16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | */ |
| 18 | |
| 19 | #include "../grn_ctx.h"cxx . . $ `<file>/lib/grn_ctx.h`/ |
| 20 | #include "../grn_output.h"cxx . . $ `<file>/lib/grn_output.h`/ |
| 21 | #include "../grn_proc.h"cxx . . $ `<file>/lib/grn_proc.h`/ |
| 22 | |
| 23 | #include <groonga/plugin.h>cxx . . $ `<file>/include/groonga/plugin.h`/ |
| 24 | |
| 25 | static grn_rccxx . . $ grn_rc# |
| 26 | selector_escalatecxx . . $ selector_escalate(2267fc2522c8e143).(grn_ctxcxx . . $ grn_ctx# *ctx, |
| 27 | grn_objcxx . . $ grn_obj# *table, |
| 28 | grn_objcxx . . $ grn_obj# *index, |
| 29 | int n_args, |
| 30 | grn_objcxx . . $ grn_obj# **args, |
| 31 | grn_objcxx . . $ grn_obj# *result_set, |
| 32 | grn_operatorcxx . . $ grn_operator# op) |
| 33 | { |
| 34 | const char *tag = "[escalate]"; |
| 35 | |
| 36 | if (n_args < 2) { |
| 37 | ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT, |
| 38 | "%s wrong number of arguments (%d for 1..)", |
| 39 | tag, |
| 40 | n_args - 1); |
| 41 | return ctx->rccxx . . $ _grn_ctx#rc.; |
| 42 | } |
| 43 | |
| 44 | if (((n_args - 1) % 2) != 1) { |
| 45 | ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT, |
| 46 | "%s wrong number of arguments (%d for 1, 3, 5, ...)", |
| 47 | tag, |
| 48 | n_args - 1); |
| 49 | return ctx->rccxx . . $ _grn_ctx#rc.; |
| 50 | } |
| 51 | |
| 52 | grn_objcxx . . $ grn_obj# *sub_result_set = |
| 53 | grn_table_createcxx . . $ grn_table_create(51df5019e8d3bdc1).(ctx, |
| 54 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, 0, |
| 55 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, |
| 56 | GRN_OBJ_TABLE_HASH_KEYcxx . . $ `include/groonga/groonga.h:688:9`!|GRN_OBJ_WITH_SUBRECcxx . . $ `include/groonga/groonga.h:812:9`!, |
| 57 | table, |
| 58 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 59 | |
| 60 | int i; |
| 61 | for (i = 1; i < n_args; i += 2) { |
| 62 | grn_objcxx . . $ grn_obj# *condition_text = args[i]; |
| 63 | if (!grn_obj_is_text_family_bulkcxx . . $ grn_obj_is_text_family_bulk(a5760e5c319a06ee).(ctx, condition_text)) { |
| 64 | grn_objcxx . . $ grn_obj# inspected; |
| 65 | GRN_TEXT_INITcxx . . $ `include/groonga/groonga.h:2750:9`!(&inspected, 0); |
| 66 | grn_inspectcxx . . $ grn_inspect(88456f97fe0d41a).(ctx, &inspected, condition_text); |
| 67 | ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT, |
| 68 | "%s the %dth argument must be condition as string: %.*s", |
| 69 | tag, |
| 70 | (i - 1), |
| 71 | (int)GRN_TEXT_LENcxx . . $ `include/groonga/groonga.h:2786:9`!(&inspected), |
| 72 | GRN_TEXT_VALUEcxx . . $ `include/groonga/groonga.h:2785:9`!(&inspected)); |
| 73 | GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &inspected); |
| 74 | goto exit; |
| 75 | } |
| 76 | |
| 77 | grn_objcxx . . $ grn_obj# *dummy_variable; |
| 78 | grn_objcxx . . $ grn_obj# *condition; |
| 79 | GRN_EXPR_CREATE_FOR_QUERYcxx . . $ `include/groonga/expr.h:216:9`!(ctx, table, condition, dummy_variable); |
| 80 | if (!condition) { |
| 81 | goto exit; |
| 82 | } |
| 83 | |
| 84 | grn_expr_parsecxx . . $ grn_expr_parse(9934d963d400828).(ctx, |
| 85 | condition, |
| 86 | GRN_TEXT_VALUEcxx . . $ `include/groonga/groonga.h:2785:9`!(condition_text), |
| 87 | (unsigned int)GRN_TEXT_LENcxx . . $ `include/groonga/groonga.h:2786:9`!(condition_text), |
| 88 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, |
| 89 | GRN_OP_MATCHcxx . . $ GRN_OP_MATCH., |
| 90 | GRN_OP_ANDcxx . . $ GRN_OP_AND., |
| 91 | GRN_EXPR_SYNTAX_SCRIPTcxx . . $ `include/groonga/expr.h:29:9`!); |
| 92 | if (ctx->rccxx . . $ _grn_ctx#rc. != GRN_SUCCESScxx . . $ GRN_SUCCESS.) { |
| 93 | grn_obj_closecxx . . $ grn_obj_close(4865d068a46d0f83).(ctx, condition); |
| 94 | goto exit; |
| 95 | } |
| 96 | |
| 97 | grn_table_selectcxx . . $ grn_table_select(fec47fdf91015e61).(ctx, table, condition, sub_result_set, GRN_OP_ORcxx . . $ GRN_OP_OR.); |
| 98 | grn_obj_closecxx . . $ grn_obj_close(4865d068a46d0f83).(ctx, condition); |
| 99 | if (ctx->rccxx . . $ _grn_ctx#rc. != GRN_SUCCESScxx . . $ GRN_SUCCESS.) { |
| 100 | goto exit; |
| 101 | } |
| 102 | |
| 103 | if ((i + 1) == n_args) { |
| 104 | break; |
| 105 | } |
| 106 | |
| 107 | grn_objcxx . . $ grn_obj# *threashold = args[i + 1]; |
| 108 | if (!grn_obj_is_number_family_bulkcxx . . $ grn_obj_is_number_family_bulk(a5760e5c319a06ee).(ctx, threashold)) { |
| 109 | grn_objcxx . . $ grn_obj# inspected; |
| 110 | GRN_TEXT_INITcxx . . $ `include/groonga/groonga.h:2750:9`!(&inspected, 0); |
| 111 | grn_inspectcxx . . $ grn_inspect(88456f97fe0d41a).(ctx, &inspected, threashold); |
| 112 | ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT, |
| 113 | "%s the %dth argument must be threshold as number: %.*s", |
| 114 | tag, |
| 115 | (i - 1) + 1, |
| 116 | (int)GRN_TEXT_LENcxx . . $ `include/groonga/groonga.h:2786:9`!(&inspected), |
| 117 | GRN_TEXT_VALUEcxx . . $ `include/groonga/groonga.h:2785:9`!(&inspected)); |
| 118 | GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &inspected); |
| 119 | goto exit; |
| 120 | } |
| 121 | |
| 122 | grn_objcxx . . $ grn_obj# casted_threshold; |
| 123 | GRN_INT64_INITcxx . . $ `include/groonga/groonga.h:2856:9`!(&casted_threshold, 0); |
| 124 | grn_obj_castcxx . . $ grn_obj_cast(a6fd93da1614eccd).(ctx, threashold, &casted_threshold, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!); |
| 125 | int64_tcxx . . $ int64_t# raw_threshold = GRN_INT64_VALUEcxx . . $ `include/groonga/groonga.h:3104:9`!(&casted_threshold); |
| 126 | GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &casted_threshold); |
| 127 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! need_to_evaluate_condition = |
| 128 | (raw_threshold < 0 || |
| 129 | (int64_tcxx . . $ int64_t#)grn_table_sizecxx . . $ grn_table_size(8dd58acc9865e889).(ctx, sub_result_set) <= raw_threshold); |
| 130 | if (!need_to_evaluate_condition) { |
| 131 | break; |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | grn_table_setoperationcxx . . $ grn_table_setoperation(44f9f3eeace98db2).(ctx, |
| 136 | result_set, |
| 137 | sub_result_set, |
| 138 | result_set, |
| 139 | op); |
| 140 | |
| 141 | exit : |
| 142 | if (sub_result_set) { |
| 143 | grn_obj_closecxx . . $ grn_obj_close(4865d068a46d0f83).(ctx, sub_result_set); |
| 144 | } |
| 145 | |
| 146 | return ctx->rccxx . . $ _grn_ctx#rc.; |
| 147 | } |
| 148 | |
| 149 | void |
| 150 | grn_proc_init_escalatecxx . . $ grn_proc_init_escalate(b578cd6e53d5fe91).(grn_ctxcxx . . $ grn_ctx# *ctx) |
| 151 | { |
| 152 | grn_objcxx . . $ grn_obj# *selector_proc; |
| 153 | |
| 154 | selector_proc = grn_proc_createcxx . . $ grn_proc_create(195df001e5324f57).(ctx, |
| 155 | "escalate", -1, |
| 156 | GRN_PROC_FUNCTIONcxx . . $ GRN_PROC_FUNCTION., |
| 157 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, |
| 158 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, |
| 159 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, |
| 160 | 0, |
| 161 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 162 | grn_proc_set_selectorcxx . . $ grn_proc_set_selector(7ce76c9564b607b5).(ctx, selector_proc, selector_escalatecxx . . $ selector_escalate(2267fc2522c8e143).); |
| 163 | grn_proc_set_selector_operatorcxx . . $ grn_proc_set_selector_operator(bbc69e63741a8d0a).(ctx, selector_proc, GRN_OP_NOPcxx . . $ GRN_OP_NOP.); |
| 164 | } |