| 1 | /* |
| 2 | Copyright (C) 2017-2018 Brazil |
| 3 | Copyright (C) 2019-2024 Sutou Kouhei <[email protected]> |
| 4 | |
| 5 | This library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | This library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with this library; if not, write to the Free Software |
| 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #pragma once |
| 21 | |
| 22 | #include "grn_db.h" |
| 23 | |
| 24 | #ifdef __cplusplus |
| 25 | extern "C" { |
| 26 | #endif |
| 27 | |
| 28 | typedef struct { |
| 29 | grn_obj source_buffer; |
| 30 | grn_obj *source; |
| 31 | grn_column_cache *cache; |
| 32 | size_t n_required_args; |
| 33 | } grn_expr_executor_scorer_data; |
| 34 | |
| 35 | typedef struct _grn_expr_executor grn_expr_executor; |
| 36 | |
| 37 | typedef double (*grn_expr_executor_scorer_func)( |
| 38 | grn_ctx *ctx, |
| 39 | grn_expr_executor *executor, |
| 40 | grn_id id, |
| 41 | grn_obj *args, |
| 42 | grn_expr_executor_scorer_data *data); |
| 43 | |
| 44 | typedef struct { |
| 45 | uint32_t codes_start_offset; |
| 46 | uint32_t codes_end_offset; |
| 47 | grn_proc_ctx proc_ctx; |
| 48 | grn_obj **args; |
| 49 | int n_args; |
| 50 | grn_obj *buffers; |
| 51 | int n_buffers; |
| 52 | } grn_expr_executor_data_simple_proc; |
| 53 | |
| 54 | typedef union { |
| 55 | struct { |
| 56 | grn_obj *value; |
| 57 | } constant; |
| 58 | struct { |
| 59 | grn_obj *column; |
| 60 | grn_obj value_buffer; |
| 61 | } value; |
| 62 | struct { |
| 63 | grn_obj result_buffer; |
| 64 | void *regex; |
| 65 | grn_obj value_buffer; |
| 66 | grn_obj *normalizer; |
| 67 | } simple_regexp; |
| 68 | struct { |
| 69 | grn_obj result_buffer; |
| 70 | grn_obj *normalizer; |
| 71 | void *regex; |
| 72 | grn_obj *normalized_sub_text; |
| 73 | const char *normalized_sub_text_raw; |
| 74 | unsigned int normalized_sub_text_raw_length_in_bytes; |
| 75 | grn_obj value_buffer; |
| 76 | } simple_match; |
| 77 | struct { |
| 78 | grn_expr_executor_data_simple_proc data; |
| 79 | } simple_proc; |
| 80 | struct { |
| 81 | grn_obj result_buffer; |
| 82 | } simple_condition_constant; |
| 83 | struct { |
| 84 | grn_obj result_buffer; |
| 85 | grn_ra *ra; |
| 86 | grn_ra_cache ra_cache; |
| 87 | unsigned int ra_element_size; |
| 88 | grn_obj value_buffer; |
| 89 | grn_obj constant_buffer; |
| 90 | grn_operator_exec_func *exec; |
| 91 | } simple_condition_ra; |
| 92 | struct { |
| 93 | bool need_exec; |
| 94 | grn_obj result_buffer; |
| 95 | grn_obj value_buffer; |
| 96 | grn_obj constant_buffer; |
| 97 | grn_operator_exec_func *exec; |
| 98 | } simple_condition; |
| 99 | struct { |
| 100 | grn_obj *score_column; |
| 101 | grn_expr_executor_data_simple_proc data; |
| 102 | } simple_proc_scorer; |
| 103 | struct { |
| 104 | grn_obj *score_column; |
| 105 | grn_obj args; |
| 106 | grn_obj score_buffer; |
| 107 | grn_expr_executor_scorer_func *funcs; |
| 108 | grn_expr_executor_scorer_data *datas; |
| 109 | size_t n_funcs; |
| 110 | size_t n_allocated_funcs; |
| 111 | } scorer; |
| 112 | } grn_expr_executor_data; |
| 113 | |
| 114 | typedef grn_obj *(*grn_expr_executor_exec_func)(grn_ctx *ctx, |
| 115 | grn_expr_executor *executor, |
| 116 | grn_id id); |
| 117 | typedef void (*grn_expr_executor_fin_func)(grn_ctx *ctx, |
| 118 | grn_expr_executor *executor); |
| 119 | |
| 120 | struct _grn_expr_executor { |
| 121 | grn_obj *expr; |
| 122 | grn_obj *variable; |
| 123 | grn_obj replace_ids; |
| 124 | grn_obj replace_values; |
| 125 | grn_expr_executor_exec_func exec; |
| 126 | grn_expr_executor_fin_func fin; |
| 127 | grn_expr_executor_data data; |
| 128 | }; |
| 129 | |
| 130 | grn_rc |
| 131 | grn_expr_executor_init(grn_ctx *ctx, |
| 132 | grn_expr_executor *executor, |
| 133 | grn_obj *expr); |
| 134 | grn_rc |
| 135 | grn_expr_executor_fin(grn_ctx *ctx, grn_expr_executor *executor); |
| 136 | |
| 137 | grn_expr_executor * |
| 138 | grn_expr_executor_open(grn_ctx *ctx, grn_obj *expr); |
| 139 | grn_rc |
| 140 | grn_expr_executor_close(grn_ctx *ctx, grn_expr_executor *executor); |
| 141 | |
| 142 | /* Replace `GRN_OP_GET_VALUE` of `id` object's value with `value`. */ |
| 143 | grn_rc |
| 144 | grn_expr_executor_add_replace_value(grn_ctx *ctx, |
| 145 | grn_expr_executor *executor, |
| 146 | grn_id id, |
| 147 | grn_obj *value); |
| 148 | |
| 149 | grn_obj * |
| 150 | grn_expr_executor_exec(grn_ctx *ctx, grn_expr_executor *executor, grn_id id); |
| 151 | |
| 152 | grn_rc |
| 153 | grn_expr_executor_exec_batch(grn_ctx *ctx, |
| 154 | grn_expr_executor *executor, |
| 155 | grn_table_cursor *cursor); |
| 156 | |
| 157 | #ifdef __cplusplus |
| 158 | } |
| 159 | #endif |