| 1 | /* |
| 2 | Copyright (C) 2020-2024 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 | #pragma once |
| 20 | |
| 21 | #include "grn.h" |
| 22 | #include "grn_ctx_impl.h" |
| 23 | |
| 24 | #ifdef __cplusplus |
| 25 | extern "C" { |
| 26 | #endif |
| 27 | |
| 28 | struct _grn_selector_data { |
| 29 | grn_obj *selector; |
| 30 | grn_obj *expr; |
| 31 | grn_obj *table; |
| 32 | grn_obj *index; |
| 33 | size_t n_args; |
| 34 | grn_obj **args; |
| 35 | float weight_factor; |
| 36 | grn_obj *result_set; |
| 37 | grn_operator op; |
| 38 | grn_obj *score_table; |
| 39 | grn_obj *score_column; |
| 40 | grn_obj score; |
| 41 | grn_obj *tags_table; |
| 42 | grn_obj *tags_column; |
| 43 | grn_obj tags; |
| 44 | grn_obj default_tags; |
| 45 | bool can_swap_result_set; |
| 46 | }; |
| 47 | |
| 48 | grn_rc |
| 49 | grn_selector_run(grn_ctx *ctx, grn_selector_data *data); |
| 50 | |
| 51 | grn_rc |
| 52 | grn_selector_data_init(grn_ctx *ctx, |
| 53 | grn_selector_data *data, |
| 54 | grn_obj *selector, |
| 55 | grn_obj *expr, |
| 56 | grn_obj *table, |
| 57 | grn_obj *index, |
| 58 | size_t n_args, |
| 59 | grn_obj **args, |
| 60 | float weight_factor, |
| 61 | grn_obj *result_set, |
| 62 | grn_operator op); |
| 63 | grn_rc |
| 64 | grn_selector_data_fin(grn_ctx *ctx, grn_selector_data *data); |
| 65 | |
| 66 | grn_rc |
| 67 | grn_selector_data_set_can_swap_result_set(grn_ctx *ctx, |
| 68 | grn_selector_data *data, |
| 69 | bool can); |
| 70 | |
| 71 | grn_rc |
| 72 | grn_selector_data_set_default_tags(grn_ctx *ctx, |
| 73 | grn_selector_data *data, |
| 74 | grn_obj *tags); |
| 75 | |
| 76 | grn_rc |
| 77 | grn_selector_data_current_set_default_tag_raw_no_validation( |
| 78 | grn_ctx *ctx, const char *tag, uint32_t tag_length); |
| 79 | |
| 80 | static inline grn_rc |
| 81 | grn_selector_data_current_set_default_tag_raw(grn_ctx *ctx, |
| 82 | const char *tag, |
| 83 | uint32_t tag_length) |
| 84 | { |
| 85 | grn_selector_data *data = ctx->impl->current_selector_data; |
| 86 | if (!data) { |
| 87 | return ctx->rc; |
| 88 | } |
| 89 | |
| 90 | return grn_selector_data_current_set_default_tag_raw_no_validation( |
| 91 | ctx, |
| 92 | tag, |
| 93 | tag_length); |
| 94 | } |
| 95 | |
| 96 | grn_rc |
| 97 | grn_selector_data_current_add_score_no_validation(grn_ctx *ctx, |
| 98 | grn_obj *result_set, |
| 99 | grn_id result_set_record_id, |
| 100 | grn_id record_id, |
| 101 | double score); |
| 102 | |
| 103 | static inline grn_rc |
| 104 | grn_selector_data_current_add_score(grn_ctx *ctx, |
| 105 | grn_obj *result_set, |
| 106 | grn_id result_set_record_id, |
| 107 | grn_id record_id, |
| 108 | double score) |
| 109 | { |
| 110 | grn_selector_data *data = ctx->impl->current_selector_data; |
| 111 | if (!data) { |
| 112 | return ctx->rc; |
| 113 | } |
| 114 | |
| 115 | return grn_selector_data_current_add_score_no_validation(ctx, |
| 116 | result_set, |
| 117 | result_set_record_id, |
| 118 | record_id, |
| 119 | score); |
| 120 | } |
| 121 | |
| 122 | #ifdef __cplusplus |
| 123 | } |
| 124 | #endif |