1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958
|
/*
Copyright (C) 2017-2018 Brazil
Copyright (C) 2018-2022 Sutou Kouhei <kou@clear-code.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "grn.h"
#include "grn_ctx.h"
#include "grn_dat.h"
#include "grn_hash.h"
#include "grn_pat.h"
#include <stdio.h>
static const char *OPTION_NAME_DEFAULT_TOKENIZER = "default_tokenizer";
static const char *OPTION_NAME_NORMALIZER = "normalizer";
static const char *OPTION_NAME_TOKEN_FILTER = "token_filter";
void
grn_table_module_init(grn_ctx *ctx,
grn_table_module *module,
grn_id module_id)
{
if (module_id == GRN_ID_NIL) {
module->proc = NULL;
} else {
module->proc = grn_ctx_at(ctx, module_id);
}
module->options = NULL;
module->options_revision = GRN_OPTION_REVISION_NONE;
module->options_close_func = NULL;
CRITICAL_SECTION_INIT(module->lock);
}
static void
grn_table_module_fin_options(grn_ctx *ctx,
grn_table_module *module)
{
if (module->options && module->options_close_func) {
module->options_close_func(ctx, module->options);
module->options = NULL;
module->options_revision = GRN_OPTION_REVISION_NONE;
module->options_close_func = NULL;
}
}
void
grn_table_module_fin(grn_ctx *ctx,
grn_table_module *module)
{
grn_table_module_fin_options(ctx, module);
CRITICAL_SECTION_FIN(module->lock);
}
void
grn_table_module_set_proc(grn_ctx *ctx,
grn_table_module *module,
grn_obj *proc)
{
CRITICAL_SECTION_ENTER(module->lock);
grn_table_module_fin_options(ctx, module);
module->proc = proc;
CRITICAL_SECTION_LEAVE(module->lock);
}
static void
grn_table_module_set_options_without_lock(grn_ctx *ctx,
grn_table_module *module,
void *options,
grn_option_revision revision,
grn_close_func close_func)
{
grn_table_module_fin_options(ctx, module);
module->options = options;
module->options_revision = revision;
module->options_close_func = close_func;
}
void
grn_table_module_set_options(grn_ctx *ctx,
grn_table_module *module,
void *options,
grn_option_revision revision,
grn_close_func close_func)
{
CRITICAL_SECTION_ENTER(module->lock);
grn_table_module_set_options_without_lock(ctx,
module,
options,
revision,
close_func);
CRITICAL_SECTION_LEAVE(module->lock);
}
void
grn_table_modules_init(grn_ctx *ctx,
grn_obj *modules_buffer)
{
GRN_TEXT_INIT(modules_buffer, 0);
}
void
grn_table_modules_fin(grn_ctx *ctx,
grn_obj *modules_buffer)
{
grn_table_modules_rewind(ctx, modules_buffer);
GRN_OBJ_FIN(ctx, modules_buffer);
}
void
grn_table_modules_add(grn_ctx *ctx,
grn_obj *modules_buffer,
grn_obj *proc)
{
grn_bulk_space(ctx, modules_buffer, sizeof(grn_table_module));
size_t n = GRN_BULK_VSIZE(modules_buffer) / sizeof(grn_table_module);
grn_table_module *module =
((grn_table_module *)GRN_BULK_HEAD(modules_buffer)) + n - 1;
grn_table_module_init(ctx, module, grn_obj_id(ctx, proc));
grn_table_module_set_proc(ctx, module, proc);
}
void
grn_table_modules_rewind(grn_ctx *ctx,
grn_obj *modules_buffer)
{
grn_table_module *modules = (grn_table_module *)GRN_BULK_HEAD(modules_buffer);
size_t n = GRN_BULK_VSIZE(modules_buffer) / sizeof(grn_table_module);
size_t i;
for (i = 0; i < n; i++) {
grn_table_module_fin(ctx, modules + i);
}
GRN_BULK_REWIND(modules_buffer);
}
grn_table_module *
grn_table_modules_get_module(grn_ctx *ctx,
grn_obj *modules_buffer,
size_t i)
{
grn_table_module *modules = (grn_table_module *)GRN_BULK_HEAD(modules_buffer);
size_t n = GRN_BULK_VSIZE(modules_buffer) / sizeof(grn_table_module);
if (i >= n) {
return NULL;
}
return modules + i;
}
grn_obj *
grn_table_modules_get_proc(grn_ctx *ctx,
grn_obj *modules_buffer,
size_t i)
{
grn_table_module *module =
grn_table_modules_get_module(ctx, modules_buffer, i);
if (!module) {
return NULL;
}
return module->proc;
}
static grn_rc
grn_table_set_module_options(grn_ctx *ctx,
grn_obj *table,
const char *module_name,
grn_obj *options,
const char *context_tag)
{
GRN_API_ENTER;
if (!grn_obj_is_table_with_key(ctx, table)) {
ERR(GRN_INVALID_ARGUMENT,
"[table][%s][options][set] table must be key table: %s",
context_tag,
table ? grn_obj_type_to_string(table->header.type) : "(null)");
GRN_API_RETURN(ctx->rc);
}
if (options &&
options->header.type == GRN_VECTOR &&
grn_vector_size(ctx, options) > 0) {
grn_obj_set_option_values(ctx,
table,
module_name,
-1,
options);
} else {
grn_obj current_options;
GRN_VOID_INIT(¤t_options);
grn_obj_get_option_values(ctx,
table,
module_name,
-1,
GRN_OPTION_REVISION_NONE,
¤t_options);
if (current_options.header.type == GRN_VECTOR &&
grn_vector_size(ctx, ¤t_options) > 1) {
grn_obj empty_options;
GRN_TEXT_INIT(&empty_options, GRN_OBJ_VECTOR);
grn_obj_set_option_values(ctx,
table,
module_name,
-1,
&empty_options);
GRN_OBJ_FIN(ctx, &empty_options);
}
GRN_OBJ_FIN(ctx, ¤t_options);
}
GRN_API_RETURN(ctx->rc);
}
static grn_rc
grn_table_get_module_options(grn_ctx *ctx,
grn_obj *table,
const char *module_name,
grn_obj *options,
const char *context_tag)
{
GRN_API_ENTER;
if (!grn_obj_is_table_with_key(ctx, table)) {
ERR(GRN_INVALID_ARGUMENT,
"[table][%s][options][get] table must be key table: %s",
context_tag,
table ? grn_obj_type_to_string(table->header.type) : "(null)");
GRN_API_RETURN(ctx->rc);
}
grn_obj_get_option_values(ctx,
table,
module_name,
-1,
GRN_OPTION_REVISION_NONE,
options);
GRN_API_RETURN(ctx->rc);
}
typedef struct {
const char *context_tag;
const char *module_name;
grn_info_type type;
size_t index;
grn_table_module_open_options_func open_options_func;
grn_close_func close_options_func;
void *user_data;
} grn_table_cache_data;
static void *
grn_table_cache_module_options(grn_ctx *ctx,
grn_obj *table,
grn_table_cache_data *data)
{
grn_table_module *module = NULL;
grn_option_revision revision;
grn_obj raw_options;
void *options = NULL;
GRN_API_ENTER;
if (!grn_obj_is_table_with_key(ctx, table)) {
ERR(GRN_INVALID_ARGUMENT,
"[table][%s][options][cache] table must be key table: %s",
data->context_tag,
table ? grn_obj_type_to_string(table->header.type) : "(null)");
GRN_API_RETURN(NULL);
}
switch (data->type) {
case GRN_INFO_DEFAULT_TOKENIZER :
switch (table->header.type) {
case GRN_TABLE_HASH_KEY :
module = &(((grn_hash *)table)->tokenizer);
break;
case GRN_TABLE_PAT_KEY :
module = &(((grn_pat *)table)->tokenizer);
break;
case GRN_TABLE_DAT_KEY :
module = &(((grn_dat *)table)->tokenizer);
break;
default :
break;
}
break;
case GRN_INFO_NORMALIZER :
switch (table->header.type) {
case GRN_TABLE_HASH_KEY :
module = grn_table_modules_get_module(ctx,
&(((grn_hash *)table)->normalizers),
0);
break;
case GRN_TABLE_PAT_KEY :
module = grn_table_modules_get_module(ctx,
&(((grn_pat *)table)->normalizers),
0);
break;
case GRN_TABLE_DAT_KEY :
module = grn_table_modules_get_module(ctx,
&(((grn_dat *)table)->normalizers),
0);
break;
default :
break;
}
break;
case GRN_INFO_TOKEN_FILTERS :
{
grn_obj *token_filters = NULL;
switch (table->header.type) {
case GRN_TABLE_HASH_KEY :
token_filters = &(((grn_hash *)table)->token_filters);
break;
case GRN_TABLE_PAT_KEY :
token_filters = &(((grn_pat *)table)->token_filters);
break;
case GRN_TABLE_DAT_KEY :
token_filters = &(((grn_dat *)table)->token_filters);
break;
default :
break;
}
module =
((grn_table_module *)GRN_BULK_HEAD(token_filters)) +
data->index;
}
break;
case GRN_INFO_NORMALIZERS :
{
grn_obj *normalizers = NULL;
switch (table->header.type) {
case GRN_TABLE_HASH_KEY :
normalizers = &(((grn_hash *)table)->normalizers);
break;
case GRN_TABLE_PAT_KEY :
normalizers = &(((grn_pat *)table)->normalizers);
break;
case GRN_TABLE_DAT_KEY :
normalizers = &(((grn_dat *)table)->normalizers);
break;
default :
break;
}
module =
((grn_table_module *)GRN_BULK_HEAD(normalizers)) +
data->index;
}
break;
default :
break;
}
GRN_TEXT_INIT(&raw_options, GRN_OBJ_VECTOR);
if (module) {
CRITICAL_SECTION_ENTER(module->lock);
revision = grn_obj_get_option_values(ctx,
table,
data->module_name,
-1,
module->options_revision,
&raw_options);
bool need_update = true;
if (revision == GRN_OPTION_REVISION_UNCHANGED) {
need_update = false;
}
if (revision == GRN_OPTION_REVISION_NONE && module->options) {
need_update = false;
}
if (need_update) {
options = data->open_options_func(ctx,
module->proc,
&raw_options,
data->user_data);
if (ctx->rc == GRN_SUCCESS) {
grn_table_module_set_options_without_lock(ctx,
module,
options,
revision,
data->close_options_func);
} else if (options) {
data->close_options_func(ctx, options);
}
}
}
CRITICAL_SECTION_LEAVE(module->lock);
GRN_OBJ_FIN(ctx, &raw_options);
GRN_API_RETURN(module->options);
}
static void
grn_table_get_module_string_raw(grn_ctx *ctx,
grn_obj *table,
grn_obj *output,
grn_obj *proc,
const char *module_name)
{
char name[GRN_TABLE_MAX_KEY_SIZE];
int name_size;
grn_obj options;
unsigned int n = 0;
name_size = grn_obj_name(ctx, proc, name, GRN_TABLE_MAX_KEY_SIZE);
GRN_TEXT_PUT(ctx, output, name, name_size);
GRN_VOID_INIT(&options);
grn_obj_get_option_values(ctx,
table,
module_name,
-1,
GRN_OPTION_REVISION_NONE,
&options);
if (options.header.type != GRN_DB_VOID) {
n = grn_vector_size(ctx, &options);
}
if (n > 0) {
unsigned int i;
grn_obj option;
GRN_VOID_INIT(&option);
GRN_TEXT_PUTS(ctx, output, "(");
for (i = 0; i < n; i++) {
const char *value;
unsigned int value_size;
grn_id domain;
if (i > 0) {
GRN_TEXT_PUTS(ctx, output, ", ");
}
value_size = grn_vector_get_element(ctx,
&options,
i,
&value,
NULL,
&domain);
grn_obj_reinit(ctx, &option, domain, 0);
grn_bulk_write(ctx, &option, value, value_size);
grn_text_otoj(ctx, output, &option, NULL);
}
GRN_TEXT_PUTS(ctx, output, ")");
GRN_OBJ_FIN(ctx, &option);
}
GRN_OBJ_FIN(ctx, &options);
}
static bool
grn_table_using_normalizer(grn_ctx *ctx, grn_obj *table)
{
grn_id proc_id = GRN_ID_NIL;
switch (table->header.type) {
case GRN_TABLE_HASH_KEY :
proc_id = ((grn_hash *)table)->header.common->normalizer;
break;
case GRN_TABLE_PAT_KEY :
proc_id = ((grn_pat *)table)->header->normalizer;
break;
case GRN_TABLE_DAT_KEY :
proc_id = ((grn_dat *)table)->header->normalizer;
break;
default :
break;
}
return proc_id != GRN_ID_NIL;
}
static void
grn_table_module_format_name(
grn_ctx *ctx,
grn_obj *table,
const char *module_name,
uint32_t i,
grn_info_type type,
bool for_get,
char real_module_name[GRN_TABLE_MAX_KEY_SIZE])
{
bool need_index = false;
switch (type) {
case GRN_INFO_NORMALIZER :
if (for_get) {
need_index = !grn_table_using_normalizer(ctx, table);
}
break;
case GRN_INFO_NORMALIZERS :
if (for_get) {
if (i == 0) {
need_index = !grn_table_using_normalizer(ctx, table);
} else {
need_index = true;
}
} else {
need_index = true;
}
break;
case GRN_INFO_TOKEN_FILTERS :
need_index = true;
break;
default :
break;
}
if (need_index) {
grn_snprintf(real_module_name,
GRN_TABLE_MAX_KEY_SIZE,
GRN_TABLE_MAX_KEY_SIZE,
"%s%u",
module_name,
i);
} else {
grn_snprintf(real_module_name,
GRN_TABLE_MAX_KEY_SIZE,
GRN_TABLE_MAX_KEY_SIZE,
"%s",
module_name);
}
}
static grn_rc
grn_table_get_module_string(grn_ctx *ctx,
grn_obj *table,
grn_obj *output,
grn_info_type type,
const char *module_name,
const char *context_tag)
{
grn_obj *proc;
GRN_API_ENTER;
if (!grn_obj_is_table_with_key(ctx, table)) {
ERR(GRN_INVALID_ARGUMENT,
"[table][%s][options][string] table must be key table: %s",
context_tag,
table ? grn_obj_type_to_string(table->header.type) : "(null)");
GRN_API_RETURN(ctx->rc);
}
proc = grn_obj_get_info(ctx, table, type, NULL);
if (!proc) {
GRN_API_RETURN(ctx->rc);
}
grn_table_get_module_string_raw(ctx, table, output, proc, module_name);
GRN_API_RETURN(ctx->rc);
}
static grn_rc
grn_table_get_modules_string(grn_ctx *ctx,
grn_obj *table,
grn_obj *output,
grn_info_type type,
const char *module_name,
const char *context_tag)
{
grn_obj procs;
unsigned int i, n;
GRN_API_ENTER;
if (!grn_obj_is_table_with_key(ctx, table)) {
ERR(GRN_INVALID_ARGUMENT,
"[table][%s][options][string] table must be key table: %s",
context_tag,
table ? grn_obj_type_to_string(table->header.type) : "(null)");
GRN_API_RETURN(ctx->rc);
}
GRN_PTR_INIT(&procs, GRN_OBJ_VECTOR, GRN_ID_NIL);
grn_obj_get_info(ctx, table, type, &procs);
if (GRN_BULK_VSIZE(&procs) == 0) {
GRN_OBJ_FIN(ctx, &procs);
GRN_API_RETURN(ctx->rc);
}
n = grn_vector_size(ctx, &procs);
if (n == 0) {
GRN_API_RETURN(ctx->rc);
}
for (i = 0; i < n; i++) {
char real_module_name[GRN_TABLE_MAX_KEY_SIZE];
grn_obj *proc = GRN_PTR_VALUE_AT(&procs, i);
if (i > 0) {
GRN_TEXT_PUTS(ctx, output, ", ");
}
grn_table_module_format_name(ctx,
table,
module_name,
i,
type,
true,
real_module_name);
grn_table_get_module_string_raw(ctx,
table,
output,
proc,
real_module_name);
}
GRN_OBJ_FIN(ctx, &procs);
GRN_API_RETURN(ctx->rc);
}
grn_rc
grn_table_set_default_tokenizer_options(grn_ctx *ctx,
grn_obj *table,
grn_obj *options)
{
return grn_table_set_module_options(ctx,
table,
OPTION_NAME_DEFAULT_TOKENIZER,
options,
"default-tokenizer");
}
grn_rc
grn_table_get_default_tokenizer_options(grn_ctx *ctx,
grn_obj *table,
grn_obj *options)
{
return grn_table_get_module_options(ctx,
table,
OPTION_NAME_DEFAULT_TOKENIZER,
options,
"default-tokenizer");
}
void *
grn_table_cache_default_tokenizer_options(grn_ctx *ctx,
grn_obj *table,
grn_table_module_open_options_func open_options_func,
grn_close_func close_options_func,
void *user_data)
{
grn_table_cache_data data;
memset(&data, 0, sizeof(data));
data.context_tag = "default-tokenizer";
data.module_name = OPTION_NAME_DEFAULT_TOKENIZER;
data.type = GRN_INFO_DEFAULT_TOKENIZER;
data.open_options_func = open_options_func;
data.close_options_func = close_options_func;
data.user_data = user_data;
return grn_table_cache_module_options(ctx, table, &data);
}
grn_rc
grn_table_get_default_tokenizer_string(grn_ctx *ctx,
grn_obj *table,
grn_obj *output)
{
return grn_table_get_module_string(ctx,
table,
output,
GRN_INFO_DEFAULT_TOKENIZER,
OPTION_NAME_DEFAULT_TOKENIZER,
"default-tokenizer");
}
grn_rc
grn_table_set_normalizer_options(grn_ctx *ctx,
grn_obj *table,
grn_obj *options)
{
return grn_table_set_module_options(ctx,
table,
OPTION_NAME_NORMALIZER,
options,
"normalizer");
}
grn_rc
grn_table_get_normalizer_options(grn_ctx *ctx,
grn_obj *table,
grn_obj *options)
{
char module_name[GRN_TABLE_MAX_KEY_SIZE];
grn_table_module_format_name(ctx,
table,
OPTION_NAME_NORMALIZER,
0,
GRN_INFO_NORMALIZER,
true,
module_name);
return grn_table_get_module_options(ctx,
table,
module_name,
options,
"normalizer");
}
void *
grn_table_cache_normalizer_options(grn_ctx *ctx,
grn_obj *table,
grn_obj *string,
grn_table_module_open_options_func open_options_func,
grn_close_func close_options_func,
void *user_data)
{
grn_table_cache_data data;
memset(&data, 0, sizeof(data));
data.context_tag = "normalizer";
uint32_t i = grn_string_get_normalizer_index(ctx, string);
char module_name[GRN_TABLE_MAX_KEY_SIZE];
grn_table_module_format_name(ctx,
table,
OPTION_NAME_NORMALIZER,
i,
GRN_INFO_NORMALIZERS,
true,
module_name);
data.module_name = module_name;
data.type = GRN_INFO_NORMALIZER;
data.open_options_func = open_options_func;
data.close_options_func = close_options_func;
data.user_data = user_data;
return grn_table_cache_module_options(ctx, table, &data);
}
grn_rc
grn_table_get_normalizer_string(grn_ctx *ctx,
grn_obj *table,
grn_obj *output)
{
char module_name[GRN_TABLE_MAX_KEY_SIZE];
grn_table_module_format_name(ctx,
table,
OPTION_NAME_NORMALIZER,
0,
GRN_INFO_NORMALIZER,
true,
module_name);
return grn_table_get_module_string(ctx,
table,
output,
GRN_INFO_NORMALIZER,
module_name,
"normalizer");
}
grn_rc
grn_table_set_normalizers_options(grn_ctx *ctx,
grn_obj *table,
uint32_t i,
grn_obj *options)
{
char module_name[GRN_TABLE_MAX_KEY_SIZE];
grn_table_module_format_name(ctx,
table,
OPTION_NAME_NORMALIZER,
i,
GRN_INFO_NORMALIZERS,
false,
module_name);
return grn_table_set_module_options(ctx,
table,
module_name,
options,
"normalizers");
}
grn_rc
grn_table_get_normalizers_options(grn_ctx *ctx,
grn_obj *table,
uint32_t i,
grn_obj *options)
{
char module_name[GRN_TABLE_MAX_KEY_SIZE];
grn_table_module_format_name(ctx,
table,
OPTION_NAME_NORMALIZER,
i,
GRN_INFO_NORMALIZER,
true,
module_name);
return grn_table_get_module_options(ctx,
table,
module_name,
options,
"normalizers");
}
void *
grn_table_cache_normalizers_options(
grn_ctx *ctx,
grn_obj *table,
uint32_t i,
grn_table_module_open_options_func open_options_func,
grn_close_func close_options_func,
void *user_data)
{
grn_table_cache_data data;
char module_name[GRN_TABLE_MAX_KEY_SIZE];
grn_table_module_format_name(ctx,
table,
OPTION_NAME_NORMALIZER,
i,
GRN_INFO_NORMALIZERS,
true,
module_name);
memset(&data, 0, sizeof(data));
data.context_tag = "normalizers";
data.module_name = module_name;
data.type = GRN_INFO_NORMALIZERS;
data.index = i;
data.open_options_func = open_options_func;
data.close_options_func = close_options_func;
data.user_data = user_data;
return grn_table_cache_module_options(ctx, table, &data);
}
grn_rc
grn_table_get_normalizers_string(grn_ctx *ctx,
grn_obj *table,
grn_obj *output)
{
return grn_table_get_modules_string(ctx,
table,
output,
GRN_INFO_NORMALIZERS,
OPTION_NAME_NORMALIZER,
"normalizers");
}
grn_rc
grn_table_set_token_filter_options(grn_ctx *ctx,
grn_obj *table,
unsigned int i,
grn_obj *options)
{
return grn_table_set_token_filters_options(ctx, table, i, options);
}
grn_rc
grn_table_set_token_filters_options(grn_ctx *ctx,
grn_obj *table,
uint32_t i,
grn_obj *options)
{
char module_name[GRN_TABLE_MAX_KEY_SIZE];
grn_table_module_format_name(ctx,
table,
OPTION_NAME_TOKEN_FILTER,
i,
GRN_INFO_TOKEN_FILTERS,
false,
module_name);
return grn_table_set_module_options(ctx,
table,
module_name,
options,
"token-filters");
}
grn_rc
grn_table_get_token_filter_options(grn_ctx *ctx,
grn_obj *table,
unsigned int i,
grn_obj *options)
{
return grn_table_get_token_filters_options(ctx, table, i, options);
}
grn_rc
grn_table_get_token_filters_options(grn_ctx *ctx,
grn_obj *table,
uint32_t i,
grn_obj *options)
{
char module_name[GRN_TABLE_MAX_KEY_SIZE];
grn_table_module_format_name(ctx,
table,
OPTION_NAME_TOKEN_FILTER,
i,
GRN_INFO_TOKEN_FILTERS,
true,
module_name);
return grn_table_get_module_options(ctx,
table,
module_name,
options,
"token-filters");
}
void *
grn_table_cache_token_filter_options(
grn_ctx *ctx,
grn_obj *table,
unsigned int i,
grn_table_module_open_options_func open_options_func,
grn_close_func close_options_func,
void *user_data)
{
return grn_table_cache_token_filters_options(
ctx, table, i, open_options_func, close_options_func, user_data);
}
void *
grn_table_cache_token_filters_options(
grn_ctx *ctx,
grn_obj *table,
uint32_t i,
grn_table_module_open_options_func open_options_func,
grn_close_func close_options_func,
void *user_data)
{
grn_table_cache_data data;
char module_name[GRN_TABLE_MAX_KEY_SIZE];
grn_table_module_format_name(ctx,
table,
OPTION_NAME_TOKEN_FILTER,
i,
GRN_INFO_TOKEN_FILTERS,
true,
module_name);
memset(&data, 0, sizeof(data));
data.context_tag = "token-filter";
data.module_name = module_name;
data.type = GRN_INFO_TOKEN_FILTERS;
data.index = i;
data.open_options_func = open_options_func;
data.close_options_func = close_options_func;
data.user_data = user_data;
return grn_table_cache_module_options(ctx, table, &data);
}
grn_rc
grn_table_get_token_filters_string(grn_ctx *ctx,
grn_obj *table,
grn_obj *output)
{
return grn_table_get_modules_string(ctx,
table,
output,
GRN_INFO_TOKEN_FILTERS,
OPTION_NAME_TOKEN_FILTER,
"token-filters");
}
|