[Groonga-commit] groonga/groonga at 5cf879e [master] schema: support normalizer with options

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Apr 17 15:56:06 JST 2018


Kouhei Sutou	2018-04-17 15:56:06 +0900 (Tue, 17 Apr 2018)

  New Revision: 5cf879e0c211e3bc6d6dc5739e3d738ddb8d1af6
  https://github.com/groonga/groonga/commit/5cf879e0c211e3bc6d6dc5739e3d738ddb8d1af6

  Message:
    schema: support normalizer with options

  Added files:
    test/command/suite/schema/tables/normalizer_with_options.test
  Copied files:
    test/command/suite/schema/tables/normalizer_with_options.expected
      (from test/command/suite/schema/tables/normalizer.expected)
  Modified files:
    lib/proc/proc_schema.c
    test/command/suite/schema/tables/columns/type/index_medium.expected
    test/command/suite/schema/tables/columns/type/index_small.expected
    test/command/suite/schema/tables/columns/type/vector.expected
    test/command/suite/schema/tables/normalizer.expected

  Modified: lib/proc/proc_schema.c (+51 -30)
===================================================================
--- lib/proc/proc_schema.c    2018-04-17 15:45:13 +0900 (cf649c758)
+++ lib/proc/proc_schema.c    2018-04-17 15:56:06 +0900 (48661f6b8)
@@ -530,6 +530,39 @@ command_schema_table_output_value_type(grn_ctx *ctx, grn_obj *table)
 }
 
 static void
+command_schema_table_output_options(grn_ctx *ctx, grn_obj *options)
+{
+  if (options->header.type == GRN_VOID) {
+    grn_ctx_output_null(ctx);
+  } else {
+    unsigned int i;
+    unsigned int n;
+    grn_obj option;
+
+    n = grn_vector_size(ctx, options);
+    grn_ctx_output_array_open(ctx, "options", n);
+    GRN_VOID_INIT(&option);
+    for (i = 0; i < n; i++) {
+      const char *value;
+      unsigned int length;
+      grn_id domain;
+
+      length = grn_vector_get_element(ctx,
+                                      options,
+                                      i,
+                                      &value,
+                                      NULL,
+                                      &domain);
+      grn_obj_reinit(ctx, &option, domain, 0);
+      grn_bulk_write(ctx, &option, value, length);
+      grn_ctx_output_obj(ctx, &option, NULL);
+    }
+    GRN_OBJ_FIN(ctx, &option);
+    grn_ctx_output_array_close(ctx);
+  }
+}
+
+static void
 command_schema_table_output_tokenizer(grn_ctx *ctx, grn_obj *table)
 {
   grn_obj *tokenizer;
@@ -551,37 +584,10 @@ command_schema_table_output_tokenizer(grn_ctx *ctx, grn_obj *table)
   grn_ctx_output_cstr(ctx, "options");
   {
     grn_obj options;
-    unsigned int n;
 
     GRN_VOID_INIT(&options);
     grn_table_get_default_tokenizer_options(ctx, table, &options);
-    if (options.header.type == GRN_VOID) {
-      grn_ctx_output_null(ctx);
-    } else {
-      grn_obj option;
-      unsigned int i;
-
-      n = grn_vector_size(ctx, &options);
-      grn_ctx_output_array_open(ctx, "options", n);
-      GRN_VOID_INIT(&option);
-      for (i = 0; i < n; i++) {
-        const char *value;
-        unsigned int length;
-        grn_id domain;
-
-        length = grn_vector_get_element(ctx,
-                                        &options,
-                                        i,
-                                        &value,
-                                        NULL,
-                                        &domain);
-        grn_obj_reinit(ctx, &option, domain, 0);
-        grn_bulk_write(ctx, &option, value, length);
-        grn_ctx_output_obj(ctx, &option, NULL);
-      }
-      GRN_OBJ_FIN(ctx, &option);
-      grn_ctx_output_array_close(ctx);
-    }
+    command_schema_table_output_options(ctx, &options);
     GRN_OBJ_FIN(ctx, &options);
   }
 
@@ -599,7 +605,7 @@ command_schema_table_output_normalizer(grn_ctx *ctx, grn_obj *table)
     return;
   }
 
-  grn_ctx_output_map_open(ctx, "normalizer", 2);
+  grn_ctx_output_map_open(ctx, "normalizer", 3);
 
   grn_ctx_output_cstr(ctx, "id");
   command_schema_output_id(ctx, normalizer);
@@ -607,6 +613,16 @@ command_schema_table_output_normalizer(grn_ctx *ctx, grn_obj *table)
   grn_ctx_output_cstr(ctx, "name");
   command_schema_output_name(ctx, normalizer);
 
+  grn_ctx_output_cstr(ctx, "options");
+  {
+    grn_obj options;
+
+    GRN_VOID_INIT(&options);
+    grn_table_get_normalizer_options(ctx, table, &options);
+    command_schema_table_output_options(ctx, &options);
+    GRN_OBJ_FIN(ctx, &options);
+  }
+
   grn_ctx_output_map_close(ctx);
 }
 
@@ -729,7 +745,12 @@ command_schema_table_command_collect_arguments(grn_ctx *ctx,
       normalizer = grn_ctx_get(ctx, "NormalizerAuto", -1);
     }
     if (normalizer) {
-      ADD_OBJECT_NAME("normalizer", normalizer);
+      grn_obj sub_output;
+      GRN_TEXT_INIT(&sub_output, 0);
+      grn_table_get_normalizer_string(ctx, table, &sub_output);
+      GRN_TEXT_PUTC(ctx, &sub_output, '\0');
+      ADD("normalizer", GRN_TEXT_VALUE(&sub_output));
+      GRN_OBJ_FIN(ctx, &sub_output);
     }
   }
 

  Modified: test/command/suite/schema/tables/columns/type/index_medium.expected (+2 -1)
===================================================================
--- test/command/suite/schema/tables/columns/type/index_medium.expected    2018-04-17 15:45:13 +0900 (33089f2d1)
+++ test/command/suite/schema/tables/columns/type/index_medium.expected    2018-04-17 15:56:06 +0900 (aa9f4a989)
@@ -347,7 +347,8 @@ schema
         },
         "normalizer": {
           "id": 79,
-          "name": "NormalizerAuto"
+          "name": "NormalizerAuto",
+          "options": null
         },
         "token_filters": [
 

  Modified: test/command/suite/schema/tables/columns/type/index_small.expected (+2 -1)
===================================================================
--- test/command/suite/schema/tables/columns/type/index_small.expected    2018-04-17 15:45:13 +0900 (ca070aea2)
+++ test/command/suite/schema/tables/columns/type/index_small.expected    2018-04-17 15:56:06 +0900 (010c2f075)
@@ -347,7 +347,8 @@ schema
         },
         "normalizer": {
           "id": 79,
-          "name": "NormalizerAuto"
+          "name": "NormalizerAuto",
+          "options": null
         },
         "token_filters": [
 

  Modified: test/command/suite/schema/tables/columns/type/vector.expected (+2 -1)
===================================================================
--- test/command/suite/schema/tables/columns/type/vector.expected    2018-04-17 15:45:13 +0900 (f04e88e2b)
+++ test/command/suite/schema/tables/columns/type/vector.expected    2018-04-17 15:56:06 +0900 (1667a56ed)
@@ -289,7 +289,8 @@ schema
         "tokenizer": null,
         "normalizer": {
           "id": 79,
-          "name": "NormalizerAuto"
+          "name": "NormalizerAuto",
+          "options": null
         },
         "token_filters": [
 

  Modified: test/command/suite/schema/tables/normalizer.expected (+2 -1)
===================================================================
--- test/command/suite/schema/tables/normalizer.expected    2018-04-17 15:45:13 +0900 (70ce81083)
+++ test/command/suite/schema/tables/normalizer.expected    2018-04-17 15:56:06 +0900 (89aca91fd)
@@ -223,7 +223,8 @@ schema
         "tokenizer": null,
         "normalizer": {
           "id": 79,
-          "name": "NormalizerAuto"
+          "name": "NormalizerAuto",
+          "options": null
         },
         "token_filters": [
 

  Copied: test/command/suite/schema/tables/normalizer_with_options.expected (+9 -5) 93%
===================================================================
--- test/command/suite/schema/tables/normalizer.expected    2018-04-17 15:45:13 +0900 (70ce81083)
+++ test/command/suite/schema/tables/normalizer_with_options.expected    2018-04-17 15:56:06 +0900 (9815a7bb5)
@@ -1,4 +1,4 @@
-table_create Tags TABLE_PAT_KEY ShortText --normalizer NormalizerAuto
+table_create Tags TABLE_PAT_KEY ShortText   --normalizer 'NormalizerNFKC100("unify_kana", true)'
 [[0,0.0,0.0],true]
 schema
 [
@@ -222,8 +222,12 @@ schema
         "value_type": null,
         "tokenizer": null,
         "normalizer": {
-          "id": 79,
-          "name": "NormalizerAuto"
+          "id": 81,
+          "name": "NormalizerNFKC100",
+          "options": [
+            "unify_kana",
+            true
+          ]
         },
         "token_filters": [
 
@@ -237,9 +241,9 @@ schema
             "name": "Tags",
             "flags": "TABLE_PAT_KEY",
             "key_type": "ShortText",
-            "normalizer": "NormalizerAuto"
+            "normalizer": "NormalizerNFKC100(\"unify_kana\", true)"
           },
-          "command_line": "table_create --name Tags --flags TABLE_PAT_KEY --key_type ShortText --normalizer NormalizerAuto"
+          "command_line": "table_create --name Tags --flags TABLE_PAT_KEY --key_type ShortText --normalizer \"NormalizerNFKC100(\\\"unify_kana\\\", true)\""
         },
         "columns": {
         }

  Added: test/command/suite/schema/tables/normalizer_with_options.test (+4 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/schema/tables/normalizer_with_options.test    2018-04-17 15:56:06 +0900 (f73204982)
@@ -0,0 +1,4 @@
+table_create Tags TABLE_PAT_KEY ShortText \
+  --normalizer 'NormalizerNFKC100("unify_kana", true)'
+
+schema
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180417/7397aa20/attachment-0001.htm 



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