| 1 | /* |
| 2 | Copyright (C) 2018 Brazil |
| 3 | Copyright (C) 2018-2025 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_ctx.h" |
| 23 | |
| 24 | #define grn_tokenizer_query grn_tokenizer_query_deprecated |
| 25 | #include <groonga/tokenizer_query_deprecated.h> |
| 26 | #undef grn_tokenizer_query |
| 27 | |
| 28 | #ifdef __cplusplus |
| 29 | extern "C" { |
| 30 | #endif |
| 31 | |
| 32 | typedef struct _grn_tokenizer_query { |
| 33 | /* Start _grn_tokenizer_query_deprecated compatible layout. */ |
| 34 | grn_obj *normalized_query; |
| 35 | char *data; |
| 36 | const char *ptr; |
| 37 | uint32_t size; |
| 38 | grn_encoding encoding; |
| 39 | uint32_t flags; |
| 40 | bool have_tokenized_delimiter; |
| 41 | /* Deprecated since 4.0.8. Use tokenize_mode instead. */ |
| 42 | grn_token_mode token_mode; |
| 43 | grn_tokenize_mode tokenize_mode; |
| 44 | /* End _grn_tokenizer_query_deprecated compatible layout. */ |
| 45 | |
| 46 | grn_obj *lexicon; |
| 47 | unsigned int token_filter_index; |
| 48 | grn_obj *source_column; |
| 49 | grn_id source_id; |
| 50 | grn_obj *index_column; |
| 51 | uint32_t normalize_flags; |
| 52 | bool need_normalize; |
| 53 | bool need_delimiter_check; |
| 54 | |
| 55 | grn_obj *options; |
| 56 | |
| 57 | grn_id domain; |
| 58 | } grn_tokenizer_query; |
| 59 | |
| 60 | grn_rc |
| 61 | grn_tokenizer_query_init(grn_ctx *ctx, grn_tokenizer_query *query); |
| 62 | void |
| 63 | grn_tokenizer_query_fin(grn_ctx *ctx, grn_tokenizer_query *query); |
| 64 | grn_rc |
| 65 | grn_tokenizer_query_set_raw_string(grn_ctx *ctx, |
| 66 | grn_tokenizer_query *query, |
| 67 | const char *string, |
| 68 | size_t string_length); |
| 69 | grn_rc |
| 70 | grn_tokenizer_query_set_data(grn_ctx *ctx, |
| 71 | grn_tokenizer_query *query, |
| 72 | const char *data, |
| 73 | size_t size, |
| 74 | grn_id domain); |
| 75 | grn_rc |
| 76 | grn_tokenizer_query_set_flags(grn_ctx *ctx, |
| 77 | grn_tokenizer_query *query, |
| 78 | uint32_t flags); |
| 79 | grn_rc |
| 80 | grn_tokenizer_query_set_mode(grn_ctx *ctx, |
| 81 | grn_tokenizer_query *query, |
| 82 | grn_tokenize_mode mode); |
| 83 | grn_rc |
| 84 | grn_tokenizer_query_set_lexicon(grn_ctx *ctx, |
| 85 | grn_tokenizer_query *query, |
| 86 | grn_obj *lexicon); |
| 87 | grn_rc |
| 88 | grn_tokenizer_query_set_token_filter_index(grn_ctx *ctx, |
| 89 | grn_tokenizer_query *query, |
| 90 | unsigned int index); |
| 91 | grn_rc |
| 92 | grn_tokenizer_query_set_source_column(grn_ctx *ctx, |
| 93 | grn_tokenizer_query *query, |
| 94 | grn_obj *column); |
| 95 | grn_rc |
| 96 | grn_tokenizer_query_set_source_id(grn_ctx *ctx, |
| 97 | grn_tokenizer_query *query, |
| 98 | grn_id id); |
| 99 | grn_rc |
| 100 | grn_tokenizer_query_set_index_column(grn_ctx *ctx, |
| 101 | grn_tokenizer_query *query, |
| 102 | grn_obj *column); |
| 103 | grn_rc |
| 104 | grn_tokenizer_query_set_options(grn_ctx *ctx, |
| 105 | grn_tokenizer_query *query, |
| 106 | grn_obj *options); |
| 107 | |
| 108 | #ifdef __cplusplus |
| 109 | } |
| 110 | #endif |
| 111 | |
| 112 | #include <groonga/tokenizer.h> |
| 113 | |
| 114 | #ifdef __cplusplus |
| 115 | extern "C" { |
| 116 | #endif |
| 117 | |
| 118 | bool |
| 119 | grn_tokenizer_have_build_func(grn_ctx *ctx, grn_obj *tokenizer); |
| 120 | |
| 121 | typedef grn_rc |
| 122 | grn_tokenizer_build_processed_n_records_func(grn_ctx *ctx, |
| 123 | grn_tokenizer_build_data *data, |
| 124 | uint32_t n_records, |
| 125 | void *user_data); |
| 126 | typedef grn_rc |
| 127 | grn_tokenizer_build_start_vectorize_func(grn_ctx *ctx, |
| 128 | grn_tokenizer_build_data *data, |
| 129 | uint32_t n_total_records, |
| 130 | void *user_data); |
| 131 | typedef grn_rc |
| 132 | grn_tokenizer_build_start_cluster_func(grn_ctx *ctx, |
| 133 | grn_tokenizer_build_data *data, |
| 134 | uint32_t n_total_records, |
| 135 | void *user_data); |
| 136 | typedef grn_rc |
| 137 | grn_tokenizer_build_start_load_func(grn_ctx *ctx, |
| 138 | grn_tokenizer_build_data *data, |
| 139 | uint32_t n_total_records, |
| 140 | void *user_data); |
| 141 | typedef grn_rc |
| 142 | grn_tokenizer_build_start_record_func(grn_ctx *ctx, |
| 143 | grn_tokenizer_build_data *data, |
| 144 | grn_id rid, |
| 145 | void *user_data); |
| 146 | typedef grn_rc |
| 147 | grn_tokenizer_build_start_section_func(grn_ctx *ctx, |
| 148 | grn_tokenizer_build_data *data, |
| 149 | uint32_t sid, |
| 150 | void *user_data); |
| 151 | typedef grn_rc |
| 152 | grn_tokenizer_build_append_tokens_func(grn_ctx *ctx, |
| 153 | grn_tokenizer_build_data *data, |
| 154 | grn_obj *tokens, |
| 155 | void *user_data); |
| 156 | typedef grn_rc |
| 157 | grn_tokenizer_build_finish_section_func(grn_ctx *ctx, |
| 158 | grn_tokenizer_build_data *data, |
| 159 | void *user_data); |
| 160 | typedef grn_rc |
| 161 | grn_tokenizer_build_finish_record_func(grn_ctx *ctx, |
| 162 | grn_tokenizer_build_data *data, |
| 163 | void *user_data); |
| 164 | |
| 165 | struct grn_tokenizer_build_data { |
| 166 | grn_obj *source_table; |
| 167 | grn_obj *source_columns; |
| 168 | grn_obj *lexicon; |
| 169 | grn_obj *index_column; |
| 170 | grn_tokenizer_build_processed_n_records_func *processed_n_records_func; |
| 171 | grn_tokenizer_build_start_vectorize_func *start_vectorize_func; |
| 172 | grn_tokenizer_build_start_cluster_func *start_cluster_func; |
| 173 | grn_tokenizer_build_start_load_func *start_load_func; |
| 174 | grn_tokenizer_build_start_record_func *start_record_func; |
| 175 | grn_tokenizer_build_start_section_func *start_section_func; |
| 176 | grn_tokenizer_build_append_tokens_func *append_tokens_func; |
| 177 | grn_tokenizer_build_finish_section_func *finish_section_func; |
| 178 | grn_tokenizer_build_finish_record_func *finish_record_func; |
| 179 | void *user_data; |
| 180 | }; |
| 181 | |
| 182 | grn_rc |
| 183 | grn_tokenizer_build(grn_ctx *ctx, |
| 184 | grn_obj *tokenizer, |
| 185 | grn_tokenizer_build_data *data); |
| 186 | |
| 187 | #ifdef __cplusplus |
| 188 | } |
| 189 | #endif |