[Groonga-commit] groonga/groonga at 1d36164 [master] Fix a bug that normalizer/tokenizer options may be ignored

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Jul 18 16:30:15 JST 2018


Kouhei Sutou	2018-07-18 16:30:15 +0900 (Wed, 18 Jul 2018)

  New Revision: 1d36164a15febd1ff183f12658cda42cae837722
  https://github.com/groonga/groonga/commit/1d36164a15febd1ff183f12658cda42cae837722

  Message:
    Fix a bug that normalizer/tokenizer options may be ignored
    
    It's occurred when the same object ID is reused.

  Added files:
    test/command/suite/table_create/normalizer/nfkc100/options/recreate.expected
    test/command/suite/table_create/normalizer/nfkc100/options/recreate.test
  Modified files:
    lib/options.c

  Modified: lib/options.c (+22 -1)
===================================================================
--- lib/options.c    2018-07-17 13:49:38 +0900 (06167b325)
+++ lib/options.c    2018-07-18 16:30:15 +0900 (50db70685)
@@ -231,9 +231,30 @@ grn_options_set(grn_ctx *ctx,
       if (object->type == MSGPACK_OBJECT_MAP) {
         msgpack_object_map *map = &(object->via.map);
         uint32_t i;
-        msgpack_pack_map(&packer, map->size + 1);
+        grn_bool have_same_key = GRN_FALSE;
+        uint32_t same_key_index = 0;
+
         for (i = 0; i < map->size; i++) {
           msgpack_object_kv *kv = &(map->ptr[i]);
+          msgpack_object *key = &(kv->key);
+          if (key->type == MSGPACK_OBJECT_STR &&
+              name_length == MSGPACK_OBJECT_STR_SIZE(key) &&
+              memcmp(name, MSGPACK_OBJECT_STR_PTR(key), name_length) == 0) {
+            have_same_key = GRN_TRUE;
+            same_key_index = i;
+            break;
+          }
+        }
+        if (have_same_key) {
+          msgpack_pack_map(&packer, map->size);
+        } else {
+          msgpack_pack_map(&packer, map->size + 1);
+        }
+        for (i = 0; i < map->size; i++) {
+          msgpack_object_kv *kv = &(map->ptr[i]);
+          if (have_same_key && i == same_key_index) {
+            continue;
+          }
           msgpack_pack_object(&packer, kv->key);
           msgpack_pack_object(&packer, kv->val);
         }

  Added: test/command/suite/table_create/normalizer/nfkc100/options/recreate.expected (+10 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/table_create/normalizer/nfkc100/options/recreate.expected    2018-07-18 16:30:15 +0900 (63bdd3da8)
@@ -0,0 +1,10 @@
+table_create Terms TABLE_PAT_KEY ShortText   --default_tokenizer TokenBigram   --normalizer 'NormalizerNFKC100("unify_kana", true)'
+[[0,0.0,0.0],true]
+dump
+table_create Terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer "NormalizerNFKC100(\"unify_kana\", true)"
+table_remove Terms
+[[0,0.0,0.0],true]
+table_create Terms TABLE_PAT_KEY ShortText   --default_tokenizer TokenBigram   --normalizer 'NormalizerNFKC100("unify_kana", false)'
+[[0,0.0,0.0],true]
+dump
+table_create Terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer "NormalizerNFKC100(\"unify_kana\", false)"

  Added: test/command/suite/table_create/normalizer/nfkc100/options/recreate.test (+11 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/table_create/normalizer/nfkc100/options/recreate.test    2018-07-18 16:30:15 +0900 (0b2d6d378)
@@ -0,0 +1,11 @@
+table_create Terms TABLE_PAT_KEY ShortText \
+  --default_tokenizer TokenBigram \
+  --normalizer 'NormalizerNFKC100("unify_kana", true)'
+dump
+
+table_remove Terms
+
+table_create Terms TABLE_PAT_KEY ShortText \
+  --default_tokenizer TokenBigram \
+  --normalizer 'NormalizerNFKC100("unify_kana", false)'
+dump
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180718/35998f8c/attachment-0001.htm 



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