| 1 | /* |
| 2 | Copyright (C) 2018 Brazil |
| 3 | Copyright (C) 2019-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 | #include "grn.h" |
| 21 | #include "grn_accessor.h" |
| 22 | #include "grn_db.h" |
| 23 | #include "grn_ii.h" |
| 24 | #include "grn_report.h" |
| 25 | #include "grn_posting.h" |
| 26 | |
| 27 | #include <stdio.h> |
| 28 | |
| 29 | grn_accessor * |
| 30 | grn_accessor_new(grn_ctx *ctx) |
| 31 | { |
| 32 | grn_accessor *res = GRN_CALLOC(sizeof(grn_accessor)); |
| 33 | if (!res) { |
| 34 | return NULL; |
| 35 | } |
| 36 | |
| 37 | res->header.type = GRN_ACCESSOR; |
| 38 | res->header.impl_flags = GRN_OBJ_ALLOCATED; |
| 39 | res->header.flags = 0; |
| 40 | res->header.domain = GRN_ID_NIL; |
| 41 | res->range = GRN_ID_NIL; |
| 42 | res->action = GRN_ACCESSOR_VOID; |
| 43 | res->offset = 0; |
| 44 | res->obj = NULL; |
| 45 | res->next = NULL; |
| 46 | res->reference_count = 1; |
| 47 | grn_log_reference_count("%p: accessor: %p: %u\n", |
| 48 | ctx, |
| 49 | res, |
| 50 | res->reference_count); |
| 51 | return res; |
| 52 | } |
| 53 | |
| 54 | grn_obj * |
| 55 | grn_accessor_copy(grn_ctx *ctx, grn_obj *accessor) |
| 56 | { |
| 57 | grn_accessor *new_accessor = grn_accessor_new(ctx); |
| 58 | grn_accessor *a = (grn_accessor *)accessor; |
| 59 | grn_accessor *new_a = new_accessor; |
| 60 | for (; a; a = a->next) { |
| 61 | new_a->action = a->action; |
| 62 | new_a->obj = a->obj; |
| 63 | if (new_a->obj) { |
| 64 | grn_obj_refer(ctx, new_a->obj); |
| 65 | } |
| 66 | if (a->next) { |
| 67 | new_a->next = grn_accessor_new(ctx); |
| 68 | new_a = new_a->next; |
| 69 | } |
| 70 | } |
| 71 | return (grn_obj *)new_accessor; |
| 72 | } |
| 73 | |
| 74 | grn_accessor_action |
| 75 | grn_accessor_get_action(grn_ctx *ctx, grn_obj *accessor) |
| 76 | { |
| 77 | grn_accessor *a = (grn_accessor *)accessor; |
| 78 | return a->action; |
| 79 | } |
| 80 | |
| 81 | grn_obj * |
| 82 | grn_accessor_get_obj(grn_ctx *ctx, grn_obj *accessor) |
| 83 | { |
| 84 | grn_accessor *a = (grn_accessor *)accessor; |
| 85 | return a->obj; |
| 86 | } |
| 87 | |
| 88 | grn_obj * |
| 89 | grn_accessor_get_next(grn_ctx *ctx, grn_obj *accessor) |
| 90 | { |
| 91 | grn_accessor *a = (grn_accessor *)accessor; |
| 92 | return (grn_obj *)(a->next); |
| 93 | } |
| 94 | |
| 95 | static grn_rc |
| 96 | grn_accessor_resolve_one_index_column(grn_ctx *ctx, |
| 97 | grn_accessor *accessor, |
| 98 | grn_obj *current_res, |
| 99 | grn_obj **next_res) |
| 100 | { |
| 101 | grn_rc rc = GRN_SUCCESS; |
| 102 | grn_obj *column = NULL; |
| 103 | grn_id next_res_domain_id = GRN_ID_NIL; |
| 104 | |
| 105 | { |
| 106 | grn_obj *index; |
| 107 | grn_obj source_ids; |
| 108 | size_t i, n_ids; |
| 109 | |
| 110 | index = accessor->obj; |
| 111 | next_res_domain_id = index->header.domain; |
| 112 | |
| 113 | GRN_RECORD_INIT(&source_ids, GRN_OBJ_VECTOR, GRN_DB_VOID); |
| 114 | grn_obj_get_info(ctx, index, GRN_INFO_SOURCE, &source_ids); |
| 115 | n_ids = GRN_RECORD_VECTOR_SIZE(&source_ids); |
| 116 | for (i = 0; i < n_ids; i++) { |
| 117 | grn_id source_id; |
| 118 | grn_obj *source; |
| 119 | |
| 120 | source_id = GRN_RECORD_VALUE_AT(&source_ids, i); |
| 121 | source = grn_ctx_at(ctx, source_id); |
| 122 | if (DB_OBJ(source)->range == next_res_domain_id) { |
| 123 | column = source; |
| 124 | break; |
| 125 | } |
| 126 | grn_obj_unlink(ctx, source); |
| 127 | } |
| 128 | |
| 129 | if (!column) { |
| 130 | return GRN_INVALID_ARGUMENT; |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | { |
| 135 | grn_rc rc; |
| 136 | grn_obj *next_res_domain = grn_ctx_at(ctx, next_res_domain_id); |
| 137 | *next_res = grn_table_create(ctx, |
| 138 | NULL, |
| 139 | 0, |
| 140 | NULL, |
| 141 | GRN_OBJ_TABLE_HASH_KEY | GRN_OBJ_WITH_SUBREC, |
| 142 | next_res_domain, |
| 143 | NULL); |
| 144 | rc = ctx->rc; |
| 145 | grn_obj_unlink(ctx, next_res_domain); |
| 146 | if (!*next_res) { |
| 147 | return rc; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | { |
| 152 | grn_obj_flags column_value_flags = 0; |
| 153 | grn_obj column_value; |
| 154 | grn_posting_internal add_posting = {0}; |
| 155 | |
| 156 | if (column->header.type == GRN_COLUMN_VAR_SIZE) { |
| 157 | column_value_flags |= GRN_OBJ_VECTOR; |
| 158 | } |
| 159 | GRN_VALUE_FIX_SIZE_INIT(&column_value, |
| 160 | column_value_flags, |
| 161 | next_res_domain_id); |
| 162 | |
| 163 | add_posting.sid = 0; |
| 164 | add_posting.pos = 0; |
| 165 | add_posting.weight_float = 0; |
| 166 | |
| 167 | GRN_HASH_EACH_BEGIN(ctx, (grn_hash *)current_res, cursor, id) |
| 168 | { |
| 169 | void *key; |
| 170 | void *value; |
| 171 | grn_hash_cursor_get_key_value(ctx, cursor, &key, NULL, &value); |
| 172 | |
| 173 | grn_id *tid = key; |
| 174 | grn_rset_recinfo *recinfo = value; |
| 175 | |
| 176 | add_posting.weight_float = (float)(recinfo->score); |
| 177 | |
| 178 | GRN_BULK_REWIND(&column_value); |
| 179 | grn_obj_get_value(ctx, column, *tid, &column_value); |
| 180 | |
| 181 | size_t n_elements = GRN_BULK_VSIZE(&column_value) / sizeof(grn_id); |
| 182 | for (size_t i = 0; i < n_elements; i++) { |
| 183 | add_posting.rid = GRN_RECORD_VALUE_AT(&column_value, i); |
| 184 | rc = grn_ii_posting_add_float(ctx, |
| 185 | (grn_posting *)(&add_posting), |
| 186 | (grn_hash *)*next_res, |
| 187 | GRN_OP_OR); |
| 188 | if (rc != GRN_SUCCESS) { |
| 189 | break; |
| 190 | } |
| 191 | } |
| 192 | if (rc != GRN_SUCCESS) { |
| 193 | break; |
| 194 | } |
| 195 | } |
| 196 | GRN_HASH_EACH_END(ctx, cursor); |
| 197 | |
| 198 | GRN_OBJ_FIN(ctx, &column_value); |
| 199 | } |
| 200 | |
| 201 | if (rc != GRN_SUCCESS) { |
| 202 | grn_obj_unlink(ctx, *next_res); |
| 203 | } |
| 204 | |
| 205 | return rc; |
| 206 | } |
| 207 | |
| 208 | static grn_rc |
| 209 | grn_accessor_resolve_one_table(grn_ctx *ctx, |
| 210 | grn_accessor *accessor, |
| 211 | grn_obj *current_res, |
| 212 | grn_obj **next_res) |
| 213 | { |
| 214 | grn_rc rc = GRN_SUCCESS; |
| 215 | grn_obj *table; |
| 216 | |
| 217 | table = accessor->obj; |
| 218 | *next_res = grn_table_create(ctx, |
| 219 | NULL, |
| 220 | 0, |
| 221 | NULL, |
| 222 | GRN_OBJ_TABLE_HASH_KEY | GRN_OBJ_WITH_SUBREC, |
| 223 | table, |
| 224 | NULL); |
| 225 | if (!*next_res) { |
| 226 | return ctx->rc; |
| 227 | } |
| 228 | |
| 229 | grn_report_table(ctx, "[accessor][resolve]", "", table); |
| 230 | |
| 231 | { |
| 232 | grn_posting_internal posting = {0}; |
| 233 | |
| 234 | GRN_HASH_EACH_BEGIN(ctx, (grn_hash *)current_res, cursor, id) |
| 235 | { |
| 236 | void *key; |
| 237 | void *value; |
| 238 | grn_id *record_id; |
| 239 | grn_rset_recinfo *recinfo; |
| 240 | grn_id next_record_id; |
| 241 | |
| 242 | grn_hash_cursor_get_key_value(ctx, cursor, &key, NULL, &value); |
| 243 | record_id = key; |
| 244 | recinfo = value; |
| 245 | next_record_id = grn_table_get(ctx, table, record_id, sizeof(grn_id)); |
| 246 | if (next_record_id == GRN_ID_NIL) { |
| 247 | continue; |
| 248 | } |
| 249 | |
| 250 | posting.rid = next_record_id; |
| 251 | posting.weight_float = (float)(recinfo->score); |
| 252 | rc = grn_ii_posting_add_float(ctx, |
| 253 | (grn_posting *)(&posting), |
| 254 | (grn_hash *)*next_res, |
| 255 | GRN_OP_OR); |
| 256 | if (rc != GRN_SUCCESS) { |
| 257 | break; |
| 258 | } |
| 259 | } |
| 260 | GRN_HASH_EACH_END(ctx, cursor); |
| 261 | } |
| 262 | |
| 263 | if (rc != GRN_SUCCESS) { |
| 264 | grn_obj_unlink(ctx, *next_res); |
| 265 | } |
| 266 | |
| 267 | return rc; |
| 268 | } |
| 269 | |
| 270 | static grn_rc |
| 271 | grn_accessor_resolve_one_data_column_sequential(grn_ctx *ctx, |
| 272 | grn_accessor *accessor, |
| 273 | grn_obj *current_res, |
| 274 | grn_obj **next_res) |
| 275 | { |
| 276 | grn_obj *column = accessor->obj; |
| 277 | grn_report_column(ctx, "[accessor][resolve][data-column]", "", column); |
| 278 | |
| 279 | grn_id next_res_domain_id = column->header.domain; |
| 280 | grn_obj *next_res_domain = grn_ctx_at(ctx, next_res_domain_id); |
| 281 | *next_res = grn_table_create(ctx, |
| 282 | NULL, |
| 283 | 0, |
| 284 | NULL, |
| 285 | GRN_OBJ_TABLE_HASH_KEY | GRN_OBJ_WITH_SUBREC, |
| 286 | next_res_domain, |
| 287 | NULL); |
| 288 | if (!*next_res) { |
| 289 | return ctx->rc; |
| 290 | } |
| 291 | |
| 292 | { |
| 293 | grn_obj value; |
| 294 | GRN_VOID_INIT(&value); |
| 295 | GRN_TABLE_EACH_BEGIN(ctx, next_res_domain, cursor, id) |
| 296 | { |
| 297 | GRN_BULK_REWIND(&value); |
| 298 | grn_obj_get_value(ctx, column, id, &value); |
| 299 | bool found = false; |
| 300 | switch (value.header.type) { |
| 301 | case GRN_BULK: |
| 302 | found = |
| 303 | (grn_table_get(ctx, |
| 304 | current_res, |
| 305 | GRN_BULK_HEAD(&value), |
| 306 | (unsigned int)GRN_BULK_VSIZE(&value)) != GRN_ID_NIL); |
| 307 | |
| 308 | break; |
| 309 | case GRN_UVECTOR: |
| 310 | { |
| 311 | size_t i, n_elements; |
| 312 | n_elements = GRN_BULK_VSIZE(&value) / sizeof(grn_id); |
| 313 | for (i = 0; i < n_elements; i++) { |
| 314 | grn_id id = GRN_RECORD_VALUE_AT(&value, i); |
| 315 | found = (grn_table_get(ctx, current_res, &id, sizeof(grn_id)) != |
| 316 | GRN_ID_NIL); |
| 317 | if (found) { |
| 318 | break; |
| 319 | } |
| 320 | } |
| 321 | } |
| 322 | break; |
| 323 | default: |
| 324 | break; |
| 325 | } |
| 326 | if (found) { |
| 327 | grn_posting_internal posting = {0}; |
| 328 | posting.rid = id; |
| 329 | grn_ii_posting_add_float(ctx, |
| 330 | (grn_posting *)(&posting), |
| 331 | (grn_hash *)*next_res, |
| 332 | GRN_OP_OR); |
| 333 | } |
| 334 | } |
| 335 | GRN_TABLE_EACH_END(ctx, cursor); |
| 336 | GRN_OBJ_FIN(ctx, &value); |
| 337 | } |
| 338 | |
| 339 | return ctx->rc; |
| 340 | } |
| 341 | |
| 342 | static grn_rc |
| 343 | grn_accessor_resolve_one_data_column_index(grn_ctx *ctx, |
| 344 | grn_index_datum *index_datum, |
| 345 | grn_obj *current_res, |
| 346 | grn_obj **next_res) |
| 347 | { |
| 348 | if (index_datum->index->header.domain != current_res->header.domain) { |
| 349 | char index_name[GRN_TABLE_MAX_KEY_SIZE]; |
| 350 | int index_name_size; |
| 351 | grn_obj *expected; |
| 352 | char expected_name[GRN_TABLE_MAX_KEY_SIZE]; |
| 353 | int expected_name_size; |
| 354 | |
| 355 | index_name_size = |
| 356 | grn_obj_name(ctx, index_datum->index, index_name, GRN_TABLE_MAX_KEY_SIZE); |
| 357 | expected = grn_ctx_at(ctx, current_res->header.domain); |
| 358 | expected_name_size = |
| 359 | grn_obj_name(ctx, expected, expected_name, GRN_TABLE_MAX_KEY_SIZE); |
| 360 | ERR(GRN_INVALID_ARGUMENT, |
| 361 | "[accessor][resolve][data-column] lexicon mismatch index: " |
| 362 | "<%.*s> " |
| 363 | "expected:<%.*s>", |
| 364 | index_name_size, |
| 365 | index_name, |
| 366 | expected_name_size, |
| 367 | expected_name); |
| 368 | return ctx->rc; |
| 369 | } |
| 370 | |
| 371 | grn_report_index(ctx, |
| 372 | "[accessor][resolve][data-column]", |
| 373 | "", |
| 374 | index_datum->index); |
| 375 | { |
| 376 | grn_rc rc; |
| 377 | grn_id next_res_domain_id = DB_OBJ(index_datum->index)->range; |
| 378 | grn_obj *next_res_domain = grn_ctx_at(ctx, next_res_domain_id); |
| 379 | *next_res = grn_table_create(ctx, |
| 380 | NULL, |
| 381 | 0, |
| 382 | NULL, |
| 383 | GRN_OBJ_TABLE_HASH_KEY | GRN_OBJ_WITH_SUBREC, |
| 384 | next_res_domain, |
| 385 | NULL); |
| 386 | rc = ctx->rc; |
| 387 | grn_obj_unlink(ctx, next_res_domain); |
| 388 | if (!*next_res) { |
| 389 | return rc; |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | { |
| 394 | grn_rc rc = GRN_SUCCESS; |
| 395 | grn_obj *index_column = index_datum->index; |
| 396 | grn_obj *index_cursor = |
| 397 | grn_index_cursor_open(ctx, NULL, index_column, GRN_ID_NIL, GRN_ID_MAX, 0); |
| 398 | if (!index_cursor) { |
| 399 | grn_obj_unlink(ctx, *next_res); |
| 400 | return ctx->rc; |
| 401 | } |
| 402 | if (index_datum->section > 0) { |
| 403 | rc = grn_index_cursor_set_section_id(ctx, |
| 404 | index_cursor, |
| 405 | index_datum->section); |
| 406 | } |
| 407 | if (rc != GRN_SUCCESS) { |
| 408 | grn_obj_close(ctx, index_cursor); |
| 409 | grn_obj_unlink(ctx, *next_res); |
| 410 | return ctx->rc; |
| 411 | } |
| 412 | |
| 413 | GRN_HASH_EACH_BEGIN(ctx, (grn_hash *)current_res, cursor, id) |
| 414 | { |
| 415 | void *key; |
| 416 | void *value; |
| 417 | grn_hash_cursor_get_key_value(ctx, cursor, &key, NULL, &value); |
| 418 | |
| 419 | grn_id *term_id = key; |
| 420 | grn_rset_recinfo *recinfo = value; |
| 421 | |
| 422 | rc = grn_index_cursor_set_term_id(ctx, index_cursor, *term_id); |
| 423 | if (rc == GRN_SUCCESS) { |
| 424 | rc = grn_result_set_add_index_cursor(ctx, |
| 425 | (grn_hash *)(*next_res), |
| 426 | index_cursor, |
| 427 | recinfo->score, |
| 428 | 1, |
| 429 | GRN_OP_OR); |
| 430 | } |
| 431 | |
| 432 | if (rc != GRN_SUCCESS) { |
| 433 | break; |
| 434 | } |
| 435 | } |
| 436 | GRN_HASH_EACH_END(ctx, cursor); |
| 437 | grn_obj_close(ctx, index_cursor); |
| 438 | |
| 439 | if (rc != GRN_SUCCESS) { |
| 440 | grn_obj_unlink(ctx, *next_res); |
| 441 | } |
| 442 | |
| 443 | return rc; |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | static grn_rc |
| 448 | grn_accessor_resolve_one_data_column(grn_ctx *ctx, |
| 449 | grn_accessor *accessor, |
| 450 | grn_obj *current_res, |
| 451 | grn_obj **next_res) |
| 452 | { |
| 453 | grn_rc rc = GRN_SUCCESS; |
| 454 | grn_index_datum index_datum; |
| 455 | unsigned int n_index_data; |
| 456 | |
| 457 | n_index_data = |
| 458 | grn_column_get_all_index_data(ctx, accessor->obj, &index_datum, 1); |
| 459 | if (n_index_data == 0) { |
| 460 | rc = grn_accessor_resolve_one_data_column_sequential(ctx, |
| 461 | accessor, |
| 462 | current_res, |
| 463 | next_res); |
| 464 | } else { |
| 465 | rc = grn_accessor_resolve_one_data_column_index(ctx, |
| 466 | &index_datum, |
| 467 | current_res, |
| 468 | next_res); |
| 469 | grn_obj_unref(ctx, index_datum.index); |
| 470 | } |
| 471 | |
| 472 | return rc; |
| 473 | } |
| 474 | |
| 475 | grn_rc |
| 476 | grn_accessor_resolve(grn_ctx *ctx, |
| 477 | grn_obj *accessor, |
| 478 | int depth, |
| 479 | grn_obj *base_res, |
| 480 | grn_obj *res, |
| 481 | grn_operator op) |
| 482 | { |
| 483 | grn_rc rc = GRN_SUCCESS; |
| 484 | grn_accessor *a; |
| 485 | grn_obj accessor_stack; |
| 486 | int i, n_accessors; |
| 487 | grn_obj *current_res = base_res; |
| 488 | |
| 489 | GRN_PTR_INIT(&accessor_stack, GRN_OBJ_VECTOR, GRN_ID_NIL); |
| 490 | n_accessors = 0; |
| 491 | for (a = (grn_accessor *)accessor; a; a = a->next) { |
| 492 | if (depth == n_accessors) { |
| 493 | break; |
| 494 | } |
| 495 | GRN_PTR_PUT(ctx, &accessor_stack, a); |
| 496 | n_accessors++; |
| 497 | } |
| 498 | |
| 499 | for (i = n_accessors; i > 0; i--) { |
| 500 | grn_obj *next_res = NULL; |
| 501 | |
| 502 | a = (grn_accessor *)GRN_PTR_VALUE_AT(&accessor_stack, i - 1); |
| 503 | if (a->obj->header.type == GRN_COLUMN_INDEX) { |
| 504 | rc = |
| 505 | grn_accessor_resolve_one_index_column(ctx, a, current_res, &next_res); |
| 506 | } else if (grn_obj_is_table(ctx, a->obj)) { |
| 507 | rc = grn_accessor_resolve_one_table(ctx, a, current_res, &next_res); |
| 508 | } else { |
| 509 | rc = grn_accessor_resolve_one_data_column(ctx, a, current_res, &next_res); |
| 510 | } |
| 511 | |
| 512 | if (current_res != base_res) { |
| 513 | grn_obj_unlink(ctx, current_res); |
| 514 | } |
| 515 | |
| 516 | if (rc != GRN_SUCCESS) { |
| 517 | break; |
| 518 | } |
| 519 | |
| 520 | current_res = next_res; |
| 521 | } |
| 522 | |
| 523 | if (rc == GRN_SUCCESS && current_res != base_res) { |
| 524 | GRN_HASH_EACH_BEGIN(ctx, (grn_hash *)current_res, cursor, id) |
| 525 | { |
| 526 | void *key; |
| 527 | void *value; |
| 528 | grn_id *record_id; |
| 529 | grn_rset_recinfo *recinfo; |
| 530 | grn_posting_internal posting = {0}; |
| 531 | |
| 532 | grn_hash_cursor_get_key_value(ctx, cursor, &key, NULL, &value); |
| 533 | record_id = key; |
| 534 | recinfo = value; |
| 535 | posting.rid = *record_id; |
| 536 | posting.sid = 1; |
| 537 | posting.pos = 0; |
| 538 | posting.weight_float = (float)(recinfo->score); |
| 539 | grn_ii_posting_add_float(ctx, |
| 540 | (grn_posting *)(&posting), |
| 541 | (grn_hash *)res, |
| 542 | op); |
| 543 | if (ctx->rc != GRN_SUCCESS) { |
| 544 | break; |
| 545 | } |
| 546 | } |
| 547 | GRN_HASH_EACH_END(ctx, cursor); |
| 548 | grn_obj_unlink(ctx, current_res); |
| 549 | grn_ii_resolve_sel_and(ctx, (grn_hash *)res, op); |
| 550 | } else { |
| 551 | if (rc == GRN_SUCCESS) { |
| 552 | rc = GRN_INVALID_ARGUMENT; |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | GRN_OBJ_FIN(ctx, &accessor_stack); |
| 557 | |
| 558 | rc = grn_ctx_rc_propagate(ctx, rc); |
| 559 | return rc; |
| 560 | } |
| 561 | |
| 562 | grn_id |
| 563 | grn_accessor_resolve_id(grn_ctx *ctx, grn_obj *accessor, grn_id id) |
| 564 | { |
| 565 | GRN_API_ENTER; |
| 566 | |
| 567 | grn_accessor *a; |
| 568 | for (a = (grn_accessor *)accessor; a->next; a = a->next) { |
| 569 | switch (a->action) { |
| 570 | case GRN_ACCESSOR_GET_KEY: |
| 571 | { |
| 572 | grn_id next_id; |
| 573 | int key_size = |
| 574 | grn_table_get_key(ctx, a->obj, id, &next_id, sizeof(grn_id)); |
| 575 | if (key_size != sizeof(grn_id)) { |
| 576 | GRN_API_RETURN(id); |
| 577 | } |
| 578 | id = next_id; |
| 579 | } |
| 580 | break; |
| 581 | case GRN_ACCESSOR_GET_VALUE: |
| 582 | { |
| 583 | grn_obj value; |
| 584 | GRN_VOID_INIT(&value); |
| 585 | grn_obj_get_value(ctx, a->obj, id, &value); |
| 586 | if (GRN_BULK_VSIZE(&value) < sizeof(grn_id)) { |
| 587 | GRN_OBJ_FIN(ctx, &value); |
| 588 | GRN_API_RETURN(id); |
| 589 | } |
| 590 | id = GRN_RECORD_VALUE(&value); |
| 591 | GRN_OBJ_FIN(ctx, &value); |
| 592 | } |
| 593 | break; |
| 594 | default: |
| 595 | GRN_API_RETURN(id); |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | GRN_API_RETURN(id); |
| 600 | } |
| 601 | |
| 602 | grn_rc |
| 603 | grn_accessor_execute(grn_ctx *ctx, |
| 604 | grn_obj *accessor, |
| 605 | grn_accessor_execute_func execute, |
| 606 | void *execute_data, |
| 607 | grn_operator execute_op, |
| 608 | grn_obj *res, |
| 609 | grn_operator logical_op) |
| 610 | { |
| 611 | GRN_API_ENTER; |
| 612 | |
| 613 | if (!grn_obj_is_accessor(ctx, accessor)) { |
| 614 | grn_obj inspected; |
| 615 | GRN_TEXT_INIT(&inspected, 0); |
| 616 | grn_inspect(ctx, &inspected, accessor); |
| 617 | ERR(GRN_INVALID_ARGUMENT, |
| 618 | "[accessor][execute] must be accessor: %.*s", |
| 619 | (int)GRN_TEXT_LEN(&inspected), |
| 620 | GRN_TEXT_VALUE(&inspected)); |
| 621 | GRN_OBJ_FIN(ctx, &inspected); |
| 622 | GRN_API_RETURN(ctx->rc); |
| 623 | } |
| 624 | |
| 625 | int depth = 0; |
| 626 | grn_accessor *last_a = NULL; |
| 627 | grn_accessor *second_to_last_a = NULL; |
| 628 | { |
| 629 | grn_accessor *a; |
| 630 | for (last_a = a = (grn_accessor *)accessor; a->next; last_a = a = a->next) { |
| 631 | depth++; |
| 632 | second_to_last_a = a; |
| 633 | } |
| 634 | } |
| 635 | |
| 636 | grn_index_datum index_data; |
| 637 | unsigned int n_index_datum; |
| 638 | grn_obj *index; |
| 639 | grn_error_cancel(ctx); |
| 640 | n_index_datum = |
| 641 | grn_column_find_index_data(ctx, last_a->obj, execute_op, &index_data, 1); |
| 642 | if (n_index_datum == 0) { |
| 643 | if (ctx->rc != GRN_SUCCESS) { |
| 644 | GRN_API_RETURN(ctx->rc); |
| 645 | } |
| 646 | index = (grn_obj *)last_a; |
| 647 | } else { |
| 648 | index = index_data.index; |
| 649 | } |
| 650 | |
| 651 | grn_rc rc; |
| 652 | if (depth == 0) { |
| 653 | rc = execute(ctx, index, execute_op, res, logical_op, execute_data); |
| 654 | } else { |
| 655 | grn_obj *base_table = NULL; |
| 656 | bool base_table_need_unref = false; |
| 657 | if (grn_obj_is_table(ctx, last_a->obj)) { |
| 658 | base_table = last_a->obj; |
| 659 | } else { |
| 660 | base_table_need_unref = true; |
| 661 | base_table = grn_ctx_at(ctx, last_a->obj->header.domain); |
| 662 | } |
| 663 | |
| 664 | grn_obj *base_res = |
| 665 | grn_table_create(ctx, |
| 666 | NULL, |
| 667 | 0, |
| 668 | NULL, |
| 669 | GRN_OBJ_TABLE_HASH_KEY | GRN_OBJ_WITH_SUBREC, |
| 670 | base_table, |
| 671 | NULL); |
| 672 | if (base_res) { |
| 673 | grn_operator base_logical_op = GRN_OP_OR; |
| 674 | if (execute_op != GRN_OP_NOT_EQUAL && second_to_last_a && |
| 675 | grn_obj_is_result_set(ctx, second_to_last_a->obj) && |
| 676 | second_to_last_a->obj->header.domain == base_res->header.domain) { |
| 677 | GRN_LOG(ctx, |
| 678 | GRN_REPORT_INDEX_LOG_LEVEL, |
| 679 | "[accessor][execute][initial] <%u>", |
| 680 | grn_table_size(ctx, second_to_last_a->obj)); |
| 681 | GRN_TABLE_EACH_BEGIN(ctx, second_to_last_a->obj, cursor, id) |
| 682 | { |
| 683 | void *key; |
| 684 | int key_size = grn_table_cursor_get_key(ctx, cursor, &key); |
| 685 | grn_hash_add(ctx, |
| 686 | (grn_hash *)base_res, |
| 687 | key, |
| 688 | (unsigned int)key_size, |
| 689 | NULL, |
| 690 | NULL); |
| 691 | } |
| 692 | GRN_TABLE_EACH_END(ctx, cursor); |
| 693 | base_logical_op = GRN_OP_AND; |
| 694 | } |
| 695 | int original_flags = ctx->flags; |
| 696 | ctx->flags &= ~GRN_CTX_TEMPORARY_DISABLE_II_RESOLVE_SEL_AND; |
| 697 | rc = execute(ctx, |
| 698 | index, |
| 699 | execute_op, |
| 700 | base_res, |
| 701 | base_logical_op, |
| 702 | execute_data); |
| 703 | ctx->flags = original_flags; |
| 704 | if (rc == GRN_SUCCESS) { |
| 705 | rc = |
| 706 | grn_accessor_resolve(ctx, accessor, depth, base_res, res, logical_op); |
| 707 | } |
| 708 | grn_obj_close(ctx, base_res); |
| 709 | } else { |
| 710 | rc = ctx->rc; |
| 711 | if (rc == GRN_SUCCESS) { |
| 712 | rc = GRN_UNKNOWN_ERROR; |
| 713 | } |
| 714 | char errbuf[GRN_CTX_MSGSIZE]; |
| 715 | grn_strcpy(errbuf, GRN_CTX_MSGSIZE, ctx->errbuf); |
| 716 | ERR(rc, |
| 717 | "[accessor][execute] failed to create internal result set: %s", |
| 718 | errbuf); |
| 719 | } |
| 720 | if (base_table_need_unref) { |
| 721 | grn_obj_unref(ctx, base_table); |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | if (n_index_datum > 0) { |
| 726 | grn_obj_unref(ctx, index_data.index); |
| 727 | } |
| 728 | |
| 729 | rc = grn_ctx_rc_propagate(ctx, rc); |
| 730 | GRN_API_RETURN(rc); |
| 731 | } |
| 732 | |
| 733 | typedef struct { |
| 734 | grn_obj *accessor; |
| 735 | grn_obj *query; |
| 736 | grn_search_optarg *optarg; |
| 737 | grn_obj *index; |
| 738 | bool index_need_unref; |
| 739 | grn_operator operator_; |
| 740 | grn_obj query_casted; |
| 741 | const char *query_raw; |
| 742 | uint32_t query_raw_len; |
| 743 | uint32_t n_base_records; |
| 744 | uint32_t n_target_records; |
| 745 | uint32_t depth; |
| 746 | } grn_accessor_estimate_size_for_query_data; |
| 747 | |
| 748 | static void |
| 749 | grn_accessor_estimate_size_for_query_data_fin( |
| 750 | grn_ctx *ctx, grn_accessor_estimate_size_for_query_data *data) |
| 751 | { |
| 752 | if (data->index_need_unref) { |
| 753 | grn_obj_unref(ctx, data->index); |
| 754 | } |
| 755 | GRN_OBJ_FIN(ctx, &(data->query_casted)); |
| 756 | } |
| 757 | |
| 758 | static void |
| 759 | grn_accessor_estimate_size_for_query_cast_failed( |
| 760 | grn_ctx *ctx, grn_accessor_estimate_size_for_query_data *data) |
| 761 | { |
| 762 | grn_obj detail; |
| 763 | GRN_TEXT_INIT(&detail, 0); |
| 764 | GRN_TEXT_PUTS(ctx, &detail, "<"); |
| 765 | grn_inspect(ctx, &detail, data->query); |
| 766 | GRN_TEXT_PUTS(ctx, &detail, "> -> "); |
| 767 | grn_obj *domain = grn_ctx_at(ctx, data->query_casted.header.domain); |
| 768 | grn_inspect(ctx, &detail, domain); |
| 769 | grn_obj_unlink(ctx, domain); |
| 770 | GRN_TEXT_PUTS(ctx, &detail, ": "); |
| 771 | grn_inspect(ctx, &detail, data->accessor); |
| 772 | ERR(GRN_INVALID_ARGUMENT, |
| 773 | "[accessor][estimate-size][query][cast] " |
| 774 | "failed: %.*s", |
| 775 | (int)GRN_TEXT_LEN(&detail), |
| 776 | GRN_TEXT_VALUE(&detail)); |
| 777 | GRN_OBJ_FIN(ctx, &detail); |
| 778 | } |
| 779 | |
| 780 | static bool |
| 781 | grn_accessor_estimate_size_for_query_prepare( |
| 782 | grn_ctx *ctx, grn_accessor_estimate_size_for_query_data *data) |
| 783 | { |
| 784 | grn_accessor *a = (grn_accessor *)(data->accessor); |
| 785 | if (grn_obj_is_table(ctx, a->obj)) { |
| 786 | data->n_target_records = grn_table_size(ctx, a->obj); |
| 787 | } else { |
| 788 | grn_obj *target_table = grn_ctx_at(ctx, a->obj->header.domain); |
| 789 | data->n_target_records = grn_table_size(ctx, target_table); |
| 790 | grn_obj_unlink(ctx, target_table); |
| 791 | } |
| 792 | |
| 793 | if (data->n_target_records == 0) { |
| 794 | return false; |
| 795 | } |
| 796 | |
| 797 | for (; a->next; a = a->next) { |
| 798 | data->depth++; |
| 799 | } |
| 800 | |
| 801 | if (grn_obj_is_table(ctx, a->obj)) { |
| 802 | data->n_base_records = grn_table_size(ctx, a->obj); |
| 803 | } else { |
| 804 | grn_obj *base_table = grn_ctx_at(ctx, a->obj->header.domain); |
| 805 | data->n_base_records = grn_table_size(ctx, base_table); |
| 806 | grn_obj_unlink(ctx, base_table); |
| 807 | } |
| 808 | |
| 809 | if (data->optarg) { |
| 810 | if (data->optarg->mode == GRN_OP_EXACT) { |
| 811 | data->operator_ = GRN_OP_MATCH; |
| 812 | } else { |
| 813 | data->operator_ = data->optarg->mode; |
| 814 | } |
| 815 | } |
| 816 | grn_index_datum index_data; |
| 817 | unsigned int n_index_datum; |
| 818 | n_index_datum = |
| 819 | grn_column_find_index_data(ctx, a->obj, data->operator_, &index_data, 1); |
| 820 | if (n_index_datum == 0) { |
| 821 | if (!grn_obj_is_table(ctx, a->obj)) { |
| 822 | return false; |
| 823 | } |
| 824 | data->index = a->obj; |
| 825 | } else { |
| 826 | data->index = index_data.index; |
| 827 | data->index_need_unref = true; |
| 828 | } |
| 829 | |
| 830 | grn_obj *lexicon; |
| 831 | bool lexicon_need_unref = false; |
| 832 | if (grn_obj_is_table(ctx, data->index)) { |
| 833 | lexicon = data->index; |
| 834 | } else { |
| 835 | lexicon = grn_ctx_at(ctx, data->index->header.domain); |
| 836 | lexicon_need_unref = true; |
| 837 | } |
| 838 | |
| 839 | if (data->query->header.domain == lexicon->header.domain) { |
| 840 | data->query_raw = GRN_BULK_HEAD(data->query); |
| 841 | data->query_raw_len = (uint32_t)(GRN_BULK_VSIZE(data->query)); |
| 842 | } else { |
| 843 | grn_obj_reinit_for(ctx, &(data->query_casted), lexicon); |
| 844 | grn_rc rc = grn_obj_cast(ctx, data->query, &(data->query_casted), false); |
| 845 | if (rc == GRN_SUCCESS) { |
| 846 | data->query_raw = GRN_BULK_HEAD(&(data->query_casted)); |
| 847 | data->query_raw_len = (uint32_t)(GRN_BULK_VSIZE(&(data->query_casted))); |
| 848 | } else { |
| 849 | grn_accessor_estimate_size_for_query_cast_failed(ctx, data); |
| 850 | } |
| 851 | } |
| 852 | |
| 853 | if (lexicon_need_unref) { |
| 854 | grn_obj_unref(ctx, lexicon); |
| 855 | } |
| 856 | |
| 857 | return ctx->rc == GRN_SUCCESS; |
| 858 | } |
| 859 | |
| 860 | uint32_t |
| 861 | grn_accessor_estimate_size_for_query(grn_ctx *ctx, |
| 862 | grn_obj *accessor, |
| 863 | grn_obj *query, |
| 864 | grn_search_optarg *optarg) |
| 865 | { |
| 866 | GRN_API_ENTER; |
| 867 | |
| 868 | if (!grn_obj_is_accessor(ctx, accessor)) { |
| 869 | grn_obj inspected; |
| 870 | GRN_TEXT_INIT(&inspected, 0); |
| 871 | grn_inspect(ctx, &inspected, accessor); |
| 872 | ERR(GRN_INVALID_ARGUMENT, |
| 873 | "[accessor][estimate-size][query] must be accessor: %.*s", |
| 874 | (int)GRN_TEXT_LEN(&inspected), |
| 875 | GRN_TEXT_VALUE(&inspected)); |
| 876 | GRN_OBJ_FIN(ctx, &inspected); |
| 877 | GRN_API_RETURN(0); |
| 878 | } |
| 879 | |
| 880 | if (!query) { |
| 881 | GRN_API_RETURN(0); |
| 882 | } |
| 883 | |
| 884 | grn_accessor_estimate_size_for_query_data data; |
| 885 | data.accessor = accessor; |
| 886 | data.query = query; |
| 887 | data.optarg = optarg; |
| 888 | data.index = NULL; |
| 889 | data.index_need_unref = false; |
| 890 | data.operator_ = GRN_OP_MATCH; |
| 891 | GRN_VOID_INIT(&(data.query_casted)); |
| 892 | data.query_raw = NULL; |
| 893 | data.query_raw_len = 0; |
| 894 | data.n_target_records = 0; |
| 895 | data.depth = 0; |
| 896 | |
| 897 | if (!grn_accessor_estimate_size_for_query_prepare(ctx, &data)) { |
| 898 | grn_accessor_estimate_size_for_query_data_fin(ctx, &data); |
| 899 | GRN_API_RETURN(0); |
| 900 | } |
| 901 | |
| 902 | uint32_t estimated_size = 0; |
| 903 | if (data.n_base_records == 0) { |
| 904 | estimated_size = 0; |
| 905 | } else { |
| 906 | uint32_t base_estimated_size; |
| 907 | if (grn_obj_is_table(ctx, data.index)) { |
| 908 | if (data.operator_ == GRN_OP_EQUAL) { |
| 909 | if (grn_table_get(ctx, |
| 910 | data.index, |
| 911 | data.query_raw, |
| 912 | data.query_raw_len)) { |
| 913 | base_estimated_size = 1; |
| 914 | } else { |
| 915 | base_estimated_size = 0; |
| 916 | } |
| 917 | } else { |
| 918 | /* TODO */ |
| 919 | base_estimated_size = data.n_base_records; |
| 920 | } |
| 921 | } else { |
| 922 | base_estimated_size = |
| 923 | grn_ii_estimate_size_for_query(ctx, |
| 924 | (grn_ii *)(data.index), |
| 925 | data.query_raw, |
| 926 | data.query_raw_len, |
| 927 | optarg); |
| 928 | } |
| 929 | if (base_estimated_size >= data.n_base_records) { |
| 930 | estimated_size = data.n_target_records; |
| 931 | } else { |
| 932 | estimated_size = |
| 933 | (uint32_t)(data.n_target_records * |
| 934 | (base_estimated_size / (double)(data.n_base_records))); |
| 935 | } |
| 936 | } |
| 937 | |
| 938 | grn_accessor_estimate_size_for_query_data_fin(ctx, &data); |
| 939 | |
| 940 | GRN_API_RETURN(estimated_size); |
| 941 | } |
| 942 | |
| 943 | typedef enum { |
| 944 | GRN_ACCESSOR_TO_STRING_USE_CASE_NAME, |
| 945 | GRN_ACCESSOR_TO_STRING_USE_CASE_SCRIPT_SYNTAX, |
| 946 | } GRN_ACCESSOR_TO_STRING_USE_CASE; |
| 947 | |
| 948 | static grn_rc |
| 949 | grn_accessor_to_string(grn_ctx *ctx, |
| 950 | grn_obj *accessor, |
| 951 | grn_obj *buffer, |
| 952 | GRN_ACCESSOR_TO_STRING_USE_CASE use_case, |
| 953 | const char *tag) |
| 954 | { |
| 955 | grn_accessor *accessor_; |
| 956 | GRN_API_ENTER; |
| 957 | |
| 958 | bool need_context = true; |
| 959 | bool need_preceding_keys = true; |
| 960 | if (use_case == GRN_ACCESSOR_TO_STRING_USE_CASE_SCRIPT_SYNTAX) { |
| 961 | need_context = false; |
| 962 | need_preceding_keys = false; |
| 963 | } |
| 964 | |
| 965 | if (!grn_obj_is_accessor(ctx, accessor)) { |
| 966 | grn_obj inspected; |
| 967 | GRN_TEXT_INIT(&inspected, 0); |
| 968 | grn_inspect(ctx, &inspected, accessor); |
| 969 | ERR(GRN_INVALID_ARGUMENT, |
| 970 | "%s must be accessor: %.*s", |
| 971 | tag, |
| 972 | (int)GRN_TEXT_LEN(&inspected), |
| 973 | GRN_TEXT_VALUE(&inspected)); |
| 974 | GRN_OBJ_FIN(ctx, &inspected); |
| 975 | GRN_API_RETURN(ctx->rc); |
| 976 | } |
| 977 | |
| 978 | uint32_t n_components = 0; |
| 979 | for (accessor_ = (grn_accessor *)accessor; accessor_; |
| 980 | accessor_ = accessor_->next) { |
| 981 | bool need_continue = false; |
| 982 | bool show_obj_name = false; |
| 983 | bool show_obj_domain_name = false; |
| 984 | |
| 985 | if (n_components > 0) { |
| 986 | GRN_TEXT_PUTS(ctx, buffer, "."); |
| 987 | } |
| 988 | switch (accessor_->action) { |
| 989 | case GRN_ACCESSOR_GET_ID: |
| 990 | GRN_TEXT_PUT(ctx, buffer, GRN_COLUMN_NAME_ID, GRN_COLUMN_NAME_ID_LEN); |
| 991 | show_obj_name = true; |
| 992 | break; |
| 993 | case GRN_ACCESSOR_GET_KEY: |
| 994 | if (!need_preceding_keys && accessor_->next) { |
| 995 | need_continue = true; |
| 996 | } else { |
| 997 | GRN_TEXT_PUT(ctx, buffer, GRN_COLUMN_NAME_KEY, GRN_COLUMN_NAME_KEY_LEN); |
| 998 | show_obj_name = true; |
| 999 | } |
| 1000 | break; |
| 1001 | case GRN_ACCESSOR_GET_VALUE: |
| 1002 | GRN_TEXT_PUT(ctx, |
| 1003 | buffer, |
| 1004 | GRN_COLUMN_NAME_VALUE, |
| 1005 | GRN_COLUMN_NAME_VALUE_LEN); |
| 1006 | show_obj_name = true; |
| 1007 | break; |
| 1008 | case GRN_ACCESSOR_GET_SCORE: |
| 1009 | GRN_TEXT_PUT(ctx, |
| 1010 | buffer, |
| 1011 | GRN_COLUMN_NAME_SCORE, |
| 1012 | GRN_COLUMN_NAME_SCORE_LEN); |
| 1013 | break; |
| 1014 | case GRN_ACCESSOR_GET_NSUBRECS: |
| 1015 | GRN_TEXT_PUT(ctx, |
| 1016 | buffer, |
| 1017 | GRN_COLUMN_NAME_NSUBRECS, |
| 1018 | GRN_COLUMN_NAME_NSUBRECS_LEN); |
| 1019 | break; |
| 1020 | case GRN_ACCESSOR_GET_MAX: |
| 1021 | GRN_TEXT_PUT(ctx, buffer, GRN_COLUMN_NAME_MAX, GRN_COLUMN_NAME_MAX_LEN); |
| 1022 | break; |
| 1023 | case GRN_ACCESSOR_GET_MIN: |
| 1024 | GRN_TEXT_PUT(ctx, buffer, GRN_COLUMN_NAME_MIN, GRN_COLUMN_NAME_MIN_LEN); |
| 1025 | break; |
| 1026 | case GRN_ACCESSOR_GET_SUM: |
| 1027 | GRN_TEXT_PUT(ctx, buffer, GRN_COLUMN_NAME_SUM, GRN_COLUMN_NAME_SUM_LEN); |
| 1028 | break; |
| 1029 | case GRN_ACCESSOR_GET_AVG: |
| 1030 | GRN_TEXT_PUT(ctx, buffer, GRN_COLUMN_NAME_AVG, GRN_COLUMN_NAME_AVG_LEN); |
| 1031 | break; |
| 1032 | case GRN_ACCESSOR_GET_MEAN: |
| 1033 | GRN_TEXT_PUT(ctx, buffer, GRN_COLUMN_NAME_MEAN, GRN_COLUMN_NAME_MEAN_LEN); |
| 1034 | break; |
| 1035 | case GRN_ACCESSOR_GET_COLUMN_VALUE: |
| 1036 | grn_column_name_(ctx, accessor_->obj, buffer); |
| 1037 | show_obj_domain_name = true; |
| 1038 | break; |
| 1039 | case GRN_ACCESSOR_GET_DB_OBJ: |
| 1040 | grn_text_printf(ctx, buffer, "(_db)"); |
| 1041 | break; |
| 1042 | case GRN_ACCESSOR_LOOKUP: |
| 1043 | grn_text_printf(ctx, buffer, "(_lookup)"); |
| 1044 | break; |
| 1045 | case GRN_ACCESSOR_FUNCALL: |
| 1046 | grn_text_printf(ctx, buffer, "(_funcall)"); |
| 1047 | break; |
| 1048 | default: |
| 1049 | grn_text_printf(ctx, buffer, "(unknown:%u)", accessor_->action); |
| 1050 | break; |
| 1051 | } |
| 1052 | |
| 1053 | if (need_continue) { |
| 1054 | continue; |
| 1055 | } |
| 1056 | |
| 1057 | if (need_context && (show_obj_name || show_obj_domain_name)) { |
| 1058 | grn_obj *target = accessor_->obj; |
| 1059 | char target_name[GRN_TABLE_MAX_KEY_SIZE]; |
| 1060 | int target_name_size; |
| 1061 | |
| 1062 | if (show_obj_domain_name) { |
| 1063 | target = grn_ctx_at(ctx, target->header.domain); |
| 1064 | } |
| 1065 | |
| 1066 | target_name_size = |
| 1067 | grn_obj_name(ctx, target, target_name, GRN_TABLE_MAX_KEY_SIZE); |
| 1068 | GRN_TEXT_PUTS(ctx, buffer, "("); |
| 1069 | if (target_name_size == 0) { |
| 1070 | GRN_TEXT_PUTS(ctx, buffer, "anonymous"); |
| 1071 | } else { |
| 1072 | GRN_TEXT_PUT(ctx, buffer, target_name, target_name_size); |
| 1073 | } |
| 1074 | GRN_TEXT_PUTS(ctx, buffer, ")"); |
| 1075 | if (show_obj_domain_name && target) { |
| 1076 | grn_obj_unref(ctx, target); |
| 1077 | } |
| 1078 | } |
| 1079 | n_components++; |
| 1080 | } |
| 1081 | |
| 1082 | GRN_API_RETURN(GRN_SUCCESS); |
| 1083 | } |
| 1084 | |
| 1085 | grn_rc |
| 1086 | grn_accessor_name(grn_ctx *ctx, grn_obj *accessor, grn_obj *name) |
| 1087 | { |
| 1088 | GRN_API_ENTER; |
| 1089 | grn_rc rc = grn_accessor_to_string(ctx, |
| 1090 | accessor, |
| 1091 | name, |
| 1092 | GRN_ACCESSOR_TO_STRING_USE_CASE_NAME, |
| 1093 | "[accessor][name]"); |
| 1094 | GRN_API_RETURN(rc); |
| 1095 | } |
| 1096 | |
| 1097 | grn_rc |
| 1098 | grn_accessor_to_script_syntax(grn_ctx *ctx, grn_obj *accessor, grn_obj *buffer) |
| 1099 | { |
| 1100 | GRN_API_ENTER; |
| 1101 | grn_rc rc = |
| 1102 | grn_accessor_to_string(ctx, |
| 1103 | accessor, |
| 1104 | buffer, |
| 1105 | GRN_ACCESSOR_TO_STRING_USE_CASE_SCRIPT_SYNTAX, |
| 1106 | "[accessor][to-script-syntax]"); |
| 1107 | GRN_API_RETURN(rc); |
| 1108 | } |