| 1 | /* |
| 2 | Copyright (C) 2026 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_proc.h"cxx . . $ `<file>/lib/grn_proc.h`/ |
| 20 | #include "../grn_ctx.h"cxx . . $ `<file>/lib/grn_ctx.h`/ |
| 21 | #include "../grn_extractor.h"cxx . . $ `<file>/lib/grn_extractor.h`/ |
| 22 | |
| 23 | #include <groonga/plugin.h>cxx . . $ `<file>/include/groonga/plugin.h`/ |
| 24 | |
| 25 | static grn_objcxx . . $ grn_obj# * |
| 26 | command_extractcxx . . $ command_extract(fd082858389c8bb0).(grn_ctxcxx . . $ grn_ctx# *ctx, |
| 27 | int nargs, |
| 28 | grn_objcxx . . $ grn_obj# **args, |
| 29 | grn_user_datacxx . . $ grn_user_data# *user_data) |
| 30 | { |
| 31 | const char *context_tag = "[extract]"; |
| 32 | |
| 33 | grn_raw_stringcxx . . $ grn_raw_string# extractors_raw; |
| 34 | extractors_raw.valuecxx . . $ $anonymous_type_7f733dd816802915_0#value. = |
| 35 | grn_plugin_proc_get_var_stringcxx . . $ grn_plugin_proc_get_var_string(b6763965d55cfbc).(ctx, |
| 36 | user_data, |
| 37 | "extractors", |
| 38 | -1, |
| 39 | &(extractors_raw.lengthcxx . . $ $anonymous_type_7f733dd816802915_0#length.)); |
| 40 | grn_objcxx . . $ grn_obj# *value = grn_plugin_proc_get_varcxx . . $ grn_plugin_proc_get_var(3074f8d72b0d40ab).(ctx, user_data, "value", -1); |
| 41 | |
| 42 | if (extractors_raw.lengthcxx . . $ $anonymous_type_7f733dd816802915_0#length. == 0) { |
| 43 | GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx, |
| 44 | GRN_INVALID_ARGUMENT, |
| 45 | "%s extractor names are missing", |
| 46 | context_tag); |
| 47 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 48 | } |
| 49 | |
| 50 | { |
| 51 | grn_objcxx . . $ grn_obj# *lexicon = grn_proc_lexicon_opencxx . . $ grn_proc_lexicon_open(44e18c98336dc3bd).(ctx, |
| 52 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, |
| 53 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, |
| 54 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, |
| 55 | &extractors_raw, |
| 56 | context_tag); |
| 57 | if (!lexicon) { |
| 58 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 59 | } |
| 60 | |
| 61 | int n_elements = 1; |
| 62 | grn_ctx_output_map_opencxx . . $ grn_ctx_output_map_open(f0f392d632556531).(ctx, "RESULT", n_elements); |
| 63 | { |
| 64 | grn_objcxx . . $ grn_obj# *extracted_value = grn_table_extractcxx . . $ grn_table_extract(88456f97fe0d41a).(ctx, lexicon, value); |
| 65 | grn_ctx_output_cstrcxx . . $ grn_ctx_output_cstr(777524e3d10dd7b4).(ctx, "extracted"); |
| 66 | if (extracted_value) { |
| 67 | grn_ctx_output_objcxx . . $ grn_ctx_output_obj(eded88d24d5f23db).(ctx, extracted_value, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 68 | if (extracted_value != value) { |
| 69 | GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, extracted_value); |
| 70 | } |
| 71 | } else { |
| 72 | grn_ctx_output_nullcxx . . $ grn_ctx_output_null(b578cd6e53d5fe91).(ctx); |
| 73 | } |
| 74 | } |
| 75 | grn_ctx_output_map_closecxx . . $ grn_ctx_output_map_close(b578cd6e53d5fe91).(ctx); |
| 76 | |
| 77 | grn_obj_unlinkcxx . . $ grn_obj_unlink(4865d068a46d0f83).(ctx, lexicon); |
| 78 | } |
| 79 | |
| 80 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 81 | } |
| 82 | |
| 83 | void |
| 84 | grn_proc_init_extractcxx . . $ grn_proc_init_extract(b578cd6e53d5fe91).(grn_ctxcxx . . $ grn_ctx# *ctx) |
| 85 | { |
| 86 | grn_expr_varcxx . . $ grn_expr_var# vars[2]; |
| 87 | grn_plugin_expr_var_initcxx . . $ grn_plugin_expr_var_init(680ef4125f11597f).(ctx, &(vars[0]), "extractors", -1); |
| 88 | grn_plugin_expr_var_initcxx . . $ grn_plugin_expr_var_init(680ef4125f11597f).(ctx, &(vars[1]), "value", -1); |
| 89 | grn_plugin_command_createcxx . . $ grn_plugin_command_create(2dfd920bb40f3149).(ctx, "extract", -1, command_extractcxx . . $ command_extract(fd082858389c8bb0)., 2, vars); |
| 90 | } |