[Groonga-commit] groonga/groonga at 3439c7d [master] Support default tokenizer options and normalizer options at once

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Apr 27 15:36:05 JST 2018


Kouhei Sutou	2018-04-27 15:36:05 +0900 (Fri, 27 Apr 2018)

  New Revision: 3439c7d4e43dfcd96a38e7fdd3316c06b17cf0ad
  https://github.com/groonga/groonga/commit/3439c7d4e43dfcd96a38e7fdd3316c06b17cf0ad

  Message:
    Support default tokenizer options and normalizer options at once

  Added files:
    test/command/suite/table_create/options/multiple.expected
    test/command/suite/table_create/options/multiple.test
  Modified files:
    lib/options.c

  Modified: lib/options.c (+22 -3)
===================================================================
--- lib/options.c    2018-04-27 08:48:02 +0900 (d6f572bd1)
+++ lib/options.c    2018-04-27 15:36:05 +0900 (2587689c7)
@@ -222,16 +222,35 @@ grn_options_set(grn_ctx *ctx,
 
     msgpack_unpacker_init(&unpacker, MSGPACK_UNPACKER_INIT_BUFFER_SIZE);
     msgpack_unpacked_init(&unpacked);
+
+    msgpack_unpacker_reserve_buffer(&unpacker, length);
+    grn_memcpy(msgpack_unpacker_buffer(&unpacker), raw_value, length);
+    msgpack_unpacker_buffer_consumed(&unpacker, length);
+    while (MSGPACK_UNPACKER_NEXT(&unpacker, &unpacked)) {
+      msgpack_object *object = &(unpacked.data);
+      if (object->type == MSGPACK_OBJECT_MAP) {
+        msgpack_object_map *map = &(object->via.map);
+        uint32_t i;
+        msgpack_pack_map(&packer, map->size + 1);
+        for (i = 0; i < map->size; i++) {
+          msgpack_object_kv *kv = &(map->ptr[i]);
+          msgpack_pack_object(&packer, kv->key);
+          msgpack_pack_object(&packer, kv->val);
+        }
+      }
+    }
+
     msgpack_unpacked_destroy(&unpacked);
     msgpack_unpacker_destroy(&unpacker);
 
     grn_ja_unref(ctx, &iw);
   } else {
     msgpack_pack_map(&packer, 1);
-    msgpack_pack_str(&packer, name_length);
-    msgpack_pack_str_body(&packer, name, name_length);
   }
 
+  msgpack_pack_str(&packer, name_length);
+  msgpack_pack_str_body(&packer, name, name_length);
+
   n = grn_vector_size(ctx, values);
   msgpack_pack_array(&packer, n);
   for (i = 0; i < n; i++) {
@@ -310,7 +329,7 @@ grn_options_get(grn_ctx *ctx,
       msgpack_object_map *map = &(object->via.map);
       uint32_t i;
       for (i = 0; i < map->size; i++) {
-        msgpack_object_kv *kv = map->ptr;
+        msgpack_object_kv *kv = &(map->ptr[i]);
         if (kv->key.type == MSGPACK_OBJECT_STR &&
             MSGPACK_OBJECT_STR_SIZE(&(kv->key)) == name_length &&
             memcmp(MSGPACK_OBJECT_STR_PTR(&(kv->key)), name, name_length) == 0) {

  Added: test/command/suite/table_create/options/multiple.expected (+65 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/table_create/options/multiple.expected    2018-04-27 15:36:05 +0900 (ee55d99e7)
@@ -0,0 +1,65 @@
+table_create Memos TABLE_NO_KEY
+[[0,0.0,0.0],true]
+column_create Memos content COLUMN_SCALAR Text
+[[0,0.0,0.0],true]
+table_create Terms TABLE_PAT_KEY ShortText   --default_tokenizer 'TokenNgram("n", 3)'   --normalizer 'NormalizerNFKC100("unify_kana", true)'
+[[0,0.0,0.0],true]
+column_create Terms memos_content COLUMN_INDEX Memos content
+[[0,0.0,0.0],true]
+load --table Memos
+[
+{"content": "りんごですか?"},
+{"content": "リンゴです。"}
+]
+[[0,0.0,0.0],2]
+select Terms --output_columns _key --limit -1
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        10
+      ],
+      [
+        [
+          "_key",
+          "ShortText"
+        ]
+      ],
+      [
+        "?"
+      ],
+      [
+        "。"
+      ],
+      [
+        "か"
+      ],
+      [
+        "ごです"
+      ],
+      [
+        "す"
+      ],
+      [
+        "すか"
+      ],
+      [
+        "です"
+      ],
+      [
+        "ですか"
+      ],
+      [
+        "りんご"
+      ],
+      [
+        "んごで"
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/table_create/options/multiple.test (+15 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/table_create/options/multiple.test    2018-04-27 15:36:05 +0900 (362401872)
@@ -0,0 +1,15 @@
+table_create Memos TABLE_NO_KEY
+column_create Memos content COLUMN_SCALAR Text
+
+table_create Terms TABLE_PAT_KEY ShortText \
+  --default_tokenizer 'TokenNgram("n", 3)' \
+  --normalizer 'NormalizerNFKC100("unify_kana", true)'
+column_create Terms memos_content COLUMN_INDEX Memos content
+
+load --table Memos
+[
+{"content": "りんごですか?"},
+{"content": "リンゴです。"}
+]
+
+select Terms --output_columns _key --limit -1
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180427/0c4bd38b/attachment-0001.htm 



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