[Groonga-commit] groonga/groonga at dddfde7 [master] Use "default_tokenizer"

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Apr 6 09:40:20 JST 2018


Kouhei Sutou	2018-04-06 09:40:20 +0900 (Fri, 06 Apr 2018)

  New Revision: dddfde764a4c8d8cdaf2a5f03be028b61fe58158
  https://github.com/groonga/groonga/commit/dddfde764a4c8d8cdaf2a5f03be028b61fe58158

  Message:
    Use "default_tokenizer"

  Modified files:
    include/groonga/table.h
    lib/db.c
    lib/obj.c
    lib/proc/proc_dump.c
    lib/proc/proc_schema.c
    lib/table.c
    lib/tokenizers.c

  Modified: include/groonga/table.h (+17 -8)
===================================================================
--- include/groonga/table.h    2018-04-05 18:21:31 +0900 (934ea5f59)
+++ include/groonga/table.h    2018-04-06 09:40:20 +0900 (9d228d2c4)
@@ -1,5 +1,5 @@
 /*
-  Copyright(C) 2009-2016 Brazil
+  Copyright(C) 2009-2018 Brazil
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -247,17 +247,26 @@ typedef void *(*grn_tokenizer_open_options_func)(grn_ctx *ctx,
                                                  void *user_data);
 
 GRN_API grn_rc
-grn_table_get_tokenizer_options(grn_ctx *ctx, grn_obj *table, grn_obj *options);
+grn_table_set_default_tokenizer_options(grn_ctx *ctx,
+                                        grn_obj *table,
+                                        grn_obj *options);
+
+GRN_API grn_rc
+grn_table_get_default_tokenizer_options(grn_ctx *ctx,
+                                        grn_obj *table,
+                                        grn_obj *options);
 
 GRN_API void *
-grn_table_cache_tokenizer_options(grn_ctx *ctx,
-                                  grn_obj *table,
-                                  grn_tokenizer_open_options_func open_options_func,
-                                  grn_close_func close_options_func,
-                                  void *user_data);
+grn_table_cache_default_tokenizer_options(grn_ctx *ctx,
+                                          grn_obj *table,
+                                          grn_tokenizer_open_options_func open_options_func,
+                                          grn_close_func close_options_func,
+                                          void *user_data);
 
 GRN_API grn_rc
-grn_table_get_tokenizer_string(grn_ctx *ctx, grn_obj *table, grn_obj *output);
+grn_table_get_default_tokenizer_string(grn_ctx *ctx,
+                                       grn_obj *table,
+                                       grn_obj *output);
 
 #ifdef __cplusplus
 }

  Modified: lib/db.c (+1 -3)
===================================================================
--- lib/db.c    2018-04-05 18:21:31 +0900 (efac6ed3e)
+++ lib/db.c    2018-04-06 09:40:20 +0900 (b6307cc62)
@@ -9121,9 +9121,7 @@ grn_obj_set_info_default_tokenizer(grn_ctx *ctx,
     break;
   }
 
-  if (grn_vector_size(ctx, &options) > 0) {
-    grn_obj_set_option_values(ctx, table,  "tokenizer", -1, &options);
-  }
+  grn_table_set_default_tokenizer_options(ctx, table, &options);
 
 exit :
   GRN_OBJ_FIN(ctx, &options);

  Modified: lib/obj.c (+7 -11)
===================================================================
--- lib/obj.c    2018-04-05 18:21:31 +0900 (e1bed6354)
+++ lib/obj.c    2018-04-06 09:40:20 +0900 (ac1b1d3e8)
@@ -716,18 +716,14 @@ grn_obj_set_option_values(grn_ctx *ctx,
                           int name_length,
                           grn_obj *values)
 {
-  grn_rc rc;
-
   GRN_API_ENTER;
-
-  rc = grn_db_set_option_values(ctx,
-                                grn_ctx_db(ctx),
-                                grn_obj_id(ctx, obj),
-                                name,
-                                name_length,
-                                values);
-
-  GRN_API_RETURN(rc);
+  grn_db_set_option_values(ctx,
+                           grn_ctx_db(ctx),
+                           grn_obj_id(ctx, obj),
+                           name,
+                           name_length,
+                           values);
+  GRN_API_RETURN(ctx->rc);
 }
 
 grn_option_revision

  Modified: lib/proc/proc_dump.c (+1 -1)
===================================================================
--- lib/proc/proc_dump.c    2018-04-05 18:21:31 +0900 (16a1e76bb)
+++ lib/proc/proc_dump.c    2018-04-06 09:40:20 +0900 (b6bb29f13)
@@ -780,7 +780,7 @@ dump_table(grn_ctx *ctx, grn_dumper *dumper, grn_obj *table)
     grn_obj sub_output;
     GRN_TEXT_PUTS(ctx, dumper->output, " --default_tokenizer ");
     GRN_TEXT_INIT(&sub_output, 0);
-    grn_table_get_tokenizer_string(ctx, table, &sub_output);
+    grn_table_get_default_tokenizer_string(ctx, table, &sub_output);
     dump_optionable_obj_string(ctx, dumper, &sub_output);
     GRN_OBJ_FIN(ctx, &sub_output);
   }

  Modified: lib/proc/proc_schema.c (+2 -2)
===================================================================
--- lib/proc/proc_schema.c    2018-04-05 18:21:31 +0900 (a9b527c1e)
+++ lib/proc/proc_schema.c    2018-04-06 09:40:20 +0900 (cf649c758)
@@ -554,7 +554,7 @@ command_schema_table_output_tokenizer(grn_ctx *ctx, grn_obj *table)
     unsigned int n;
 
     GRN_VOID_INIT(&options);
-    grn_table_get_tokenizer_options(ctx, table, &options);
+    grn_table_get_default_tokenizer_options(ctx, table, &options);
     if (options.header.type == GRN_VOID) {
       grn_ctx_output_null(ctx);
     } else {
@@ -715,7 +715,7 @@ command_schema_table_command_collect_arguments(grn_ctx *ctx,
     if (tokenizer) {
       grn_obj sub_output;
       GRN_TEXT_INIT(&sub_output, 0);
-      grn_table_get_tokenizer_string(ctx, table, &sub_output);
+      grn_table_get_default_tokenizer_string(ctx, table, &sub_output);
       GRN_TEXT_PUTC(ctx, &sub_output, '\0');
       ADD("default_tokenizer", GRN_TEXT_VALUE(&sub_output));
       GRN_OBJ_FIN(ctx, &sub_output);

  Modified: lib/table.c (+69 -18)
===================================================================
--- lib/table.c    2018-04-05 18:21:31 +0900 (6201dbdf5)
+++ lib/table.c    2018-04-06 09:40:20 +0900 (198e3fa2d)
@@ -23,6 +23,8 @@
 #include "grn_hash.h"
 #include "grn_pat.h"
 
+static const char *OPTION_NAME_DEFAULT_TOKENIZER = "default-tokenizer";
+
 grn_rc
 grn_table_apply_expr(grn_ctx *ctx,
                      grn_obj *table,
@@ -185,22 +187,70 @@ grn_table_tokenizer_set_options(grn_ctx *ctx,
 }
 
 grn_rc
-grn_table_get_tokenizer_options(grn_ctx *ctx,
-                                grn_obj *table,
-                                grn_obj *options)
+grn_table_set_default_tokenizer_options(grn_ctx *ctx,
+                                        grn_obj *table,
+                                        grn_obj *options)
+{
+  GRN_API_ENTER;
+
+  if (!grn_obj_is_lexicon(ctx, table)) {
+    ERR(GRN_INVALID_ARGUMENT,
+        "[table][default-tokenizer][options][set] table must be key table: %s",
+        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,
+                              OPTION_NAME_DEFAULT_TOKENIZER,
+                              -1,
+                              options);
+  } else {
+    grn_obj current_options;
+    GRN_VOID_INIT(&current_options);
+    grn_obj_get_option_values(ctx,
+                              table,
+                              OPTION_NAME_DEFAULT_TOKENIZER,
+                              -1,
+                              GRN_OPTION_REVISION_NONE,
+                              &current_options);
+    if (current_options.header.type == GRN_VECTOR &&
+        grn_vector_size(ctx, &current_options) > 1) {
+      grn_obj empty_options;
+      GRN_TEXT_INIT(&empty_options, GRN_OBJ_VECTOR);
+      grn_obj_set_option_values(ctx,
+                                table,
+                                OPTION_NAME_DEFAULT_TOKENIZER,
+                                -1,
+                                &empty_options);
+      GRN_OBJ_FIN(ctx, &empty_options);
+    }
+    GRN_OBJ_FIN(ctx, &current_options);
+  }
+
+  GRN_API_RETURN(ctx->rc);
+}
+
+grn_rc
+grn_table_get_default_tokenizer_options(grn_ctx *ctx,
+                                        grn_obj *table,
+                                        grn_obj *options)
 {
   GRN_API_ENTER;
 
   if (!grn_obj_is_lexicon(ctx, table)) {
     ERR(GRN_INVALID_ARGUMENT,
-        "[table][tokenizer-options][get] table must be key table: %s",
+        "[table][default-tokenizer][options][get] table must be key table: %s",
         table ? grn_obj_type_to_string(table->header.type) : "(null)");
     GRN_API_RETURN(ctx->rc);
   }
 
   grn_obj_get_option_values(ctx,
                             table,
-                            "tokenizer",
+                            OPTION_NAME_DEFAULT_TOKENIZER,
                             -1,
                             GRN_OPTION_REVISION_NONE,
                             options);
@@ -208,11 +258,11 @@ grn_table_get_tokenizer_options(grn_ctx *ctx,
 }
 
 void *
-grn_table_cache_tokenizer_options(grn_ctx *ctx,
-                                  grn_obj *table,
-                                  grn_tokenizer_open_options_func open_options_func,
-                                  grn_close_func close_options_func,
-                                  void *user_data)
+grn_table_cache_default_tokenizer_options(grn_ctx *ctx,
+                                          grn_obj *table,
+                                          grn_tokenizer_open_options_func open_options_func,
+                                          grn_close_func close_options_func,
+                                          void *user_data)
 {
   grn_table_tokenizer *tokenizer;
   grn_option_revision revision;
@@ -223,7 +273,7 @@ grn_table_cache_tokenizer_options(grn_ctx *ctx,
 
   if (!table) {
     ERR(GRN_INVALID_ARGUMENT,
-        "[table][tokenizer-options][cache] table is NULL");
+        "[table][default-tokenizer][options][cache] table is NULL");
     GRN_API_RETURN(NULL);
   }
 
@@ -239,7 +289,7 @@ grn_table_cache_tokenizer_options(grn_ctx *ctx,
     break;
   default :
     ERR(GRN_INVALID_ARGUMENT,
-        "[table][tokenizer-options][cache] table must key table: %s",
+        "[table][default-tokenizer][options][cache] table must key table: %s",
         grn_obj_type_to_string(table->header.type));
     GRN_API_RETURN(NULL);
     break;
@@ -248,7 +298,7 @@ grn_table_cache_tokenizer_options(grn_ctx *ctx,
   GRN_VOID_INIT(&raw_options);
   revision = grn_obj_get_option_values(ctx,
                                        table,
-                                       "tokenizer",
+                                       OPTION_NAME_DEFAULT_TOKENIZER,
                                        -1,
                                        tokenizer->options_revision,
                                        &raw_options);
@@ -271,9 +321,9 @@ exit :
 }
 
 grn_rc
-grn_table_get_tokenizer_string(grn_ctx *ctx,
-                               grn_obj *table,
-                               grn_obj *output)
+grn_table_get_default_tokenizer_string(grn_ctx *ctx,
+                                       grn_obj *table,
+                                       grn_obj *output)
 {
   grn_obj *tokenizer;
   char name[GRN_TABLE_MAX_KEY_SIZE];
@@ -285,7 +335,8 @@ grn_table_get_tokenizer_string(grn_ctx *ctx,
 
   if (!grn_obj_is_lexicon(ctx, table)) {
     ERR(GRN_INVALID_ARGUMENT,
-        "[table][tokenizer-options][get] table must be key table: %s",
+        "[table][default-tokenizer][options][string] "
+        "table must be key table: %s",
         table ? grn_obj_type_to_string(table->header.type) : "(null)");
     GRN_API_RETURN(ctx->rc);
   }
@@ -301,7 +352,7 @@ grn_table_get_tokenizer_string(grn_ctx *ctx,
   GRN_VOID_INIT(&options);
   grn_obj_get_option_values(ctx,
                             table,
-                            "tokenizer",
+                            OPTION_NAME_DEFAULT_TOKENIZER,
                             -1,
                             GRN_OPTION_REVISION_NONE,
                             &options);

  Modified: lib/tokenizers.c (+5 -5)
===================================================================
--- lib/tokenizers.c    2018-04-05 18:21:31 +0900 (555a07cb7)
+++ lib/tokenizers.c    2018-04-06 09:40:20 +0900 (9bcec23e2)
@@ -413,11 +413,11 @@ ngram_init(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)
   grn_obj *lexicon = args[0];
   ngram_options *options;
 
-  options = grn_table_cache_tokenizer_options(ctx,
-                                              lexicon,
-                                              ngram_open_options,
-                                              ngram_close_options,
-                                              NULL);
+  options = grn_table_cache_default_tokenizer_options(ctx,
+                                                      lexicon,
+                                                      ngram_open_options,
+                                                      ngram_close_options,
+                                                      NULL);
   if (ctx->rc != GRN_SUCCESS) {
     return NULL;
   }
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180406/0744f8f6/attachment-0001.htm 



More information about the Groonga-commit mailing list
Back to archive index