[Groonga-commit] groonga/groonga at e3e5be1 [master] regexp: make match target no normalizer reference in vector normalized

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Sep 8 11:47:42 JST 2015


Kouhei Sutou	2015-09-08 11:47:42 +0900 (Tue, 08 Sep 2015)

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

  Message:
    regexp: make match target no normalizer reference in vector normalized
    
    It's not incompatible change. Because reference vector wasn't supported
    yet.

  Added files:
    test/command/suite/select/filter/no_index/regexp/vector_reference.expected
    test/command/suite/select/filter/no_index/regexp/vector_reference.test
  Modified files:
    lib/operator.c

  Modified: lib/operator.c (+30 -1)
===================================================================
--- lib/operator.c    2015-09-08 11:42:05 +0900 (caacda2)
+++ lib/operator.c    2015-09-08 11:47:42 +0900 (e370574)
@@ -1026,6 +1026,8 @@ exec_regexp_uvector_bulk(grn_ctx *ctx, grn_obj *uvector, grn_obj *pattern)
   unsigned int i, size;
   OnigRegex regex;
   grn_obj *domain;
+  grn_obj *normalizer;
+  grn_obj *normalizer_auto = NULL;
 
   size = grn_uvector_size(ctx, uvector);
   if (size == 0) {
@@ -1043,6 +1045,11 @@ exec_regexp_uvector_bulk(grn_ctx *ctx, grn_obj *uvector, grn_obj *pattern)
     return GRN_FALSE;
   }
 
+  grn_table_get_info(ctx, domain, NULL, NULL, NULL, &normalizer, NULL);
+  if (!normalizer) {
+    normalizer_auto = grn_ctx_get(ctx, GRN_NORMALIZER_AUTO_NAME, -1);
+  }
+
   for (i = 0; i < size; i++) {
     grn_id record_id;
     char key[GRN_TABLE_MAX_KEY_SIZE];
@@ -1051,8 +1058,26 @@ exec_regexp_uvector_bulk(grn_ctx *ctx, grn_obj *uvector, grn_obj *pattern)
     record_id = grn_uvector_get_element(ctx, uvector, i, NULL);
     key_size = grn_table_get_key(ctx, domain, record_id,
                                  key, GRN_TABLE_MAX_KEY_SIZE);
-    if (key_size > 0) {
+    if (key_size == 0) {
+      continue;
+    }
+
+    if (normalizer) {
       matched = regexp_is_match(ctx, regex, key, key_size);
+    } else {
+      grn_obj *norm_key;
+      const char *norm_key_raw;
+      unsigned int norm_key_raw_length_in_bytes;
+
+      norm_key = grn_string_open(ctx, key, key_size, normalizer_auto, 0);
+      grn_string_get_normalized(ctx, norm_key,
+                                &norm_key_raw,
+                                &norm_key_raw_length_in_bytes,
+                                NULL);
+      matched = regexp_is_match(ctx, regex,
+                                norm_key_raw,
+                                norm_key_raw_length_in_bytes);
+      grn_obj_unlink(ctx, norm_key);
     }
 
     if (matched) {
@@ -1060,6 +1085,10 @@ exec_regexp_uvector_bulk(grn_ctx *ctx, grn_obj *uvector, grn_obj *pattern)
     }
   }
 
+  if (normalizer_auto) {
+    grn_obj_unlink(ctx, normalizer_auto);
+  }
+
   grn_obj_unlink(ctx, domain);
 
   onig_free(regex);

  Added: test/command/suite/select/filter/no_index/regexp/vector_reference.expected (+45 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/no_index/regexp/vector_reference.expected    2015-09-08 11:47:42 +0900 (54fb8e2)
@@ -0,0 +1,45 @@
+table_create Tags TABLE_PAT_KEY ShortText
+[[0,0.0,0.0],true]
+table_create Memos TABLE_NO_KEY
+[[0,0.0,0.0],true]
+column_create Memos tags COLUMN_VECTOR Tags
+[[0,0.0,0.0],true]
+load --table Memos
+[
+{"tags": ["Groonga", "Rroonga",  "Mroonga"]},
+{"tags": ["Groonga", "PGroonga", "Mroonga"]}
+]
+[[0,0.0,0.0],2]
+select Memos --filter 'tags @~ "\\\\Apgr"'
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        1
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "tags",
+          "Tags"
+        ]
+      ],
+      [
+        2,
+        [
+          "Groonga",
+          "PGroonga",
+          "Mroonga"
+        ]
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/filter/no_index/regexp/vector_reference.test (+12 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/no_index/regexp/vector_reference.test    2015-09-08 11:47:42 +0900 (42a1cf3)
@@ -0,0 +1,12 @@
+table_create Tags TABLE_PAT_KEY ShortText
+
+table_create Memos TABLE_NO_KEY
+column_create Memos tags COLUMN_VECTOR Tags
+
+load --table Memos
+[
+{"tags": ["Groonga", "Rroonga",  "Mroonga"]},
+{"tags": ["Groonga", "PGroonga", "Mroonga"]}
+]
+
+select Memos --filter 'tags @~ "\\\\Apgr"'
-------------- next part --------------
HTML����������������������������...
Download 



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