[Groonga-commit] groonga/groonga at 7f0c3a9 [master] select: support 'reference_column @^ "query"' without index

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Nov 19 18:27:58 JST 2014


Kouhei Sutou	2014-11-19 18:27:58 +0900 (Wed, 19 Nov 2014)

  New Revision: 7f0c3a9a12601879c81220ed863d2fb83ce9562b
  https://github.com/groonga/groonga/commit/7f0c3a9a12601879c81220ed863d2fb83ce9562b

  Message:
    select: support 'reference_column @^ "query"' without index

  Added files:
    test/command/suite/select/filter/no_index/prefix_search/reference_text/no_normalizer.expected
    test/command/suite/select/filter/no_index/prefix_search/reference_text/no_normalizer.test
    test/command/suite/select/filter/no_index/prefix_search/reference_text/normalizer.expected
    test/command/suite/select/filter/no_index/prefix_search/reference_text/normalizer.test
    test/command/suite/select/filter/no_index/prefix_search/text_text.expected
    test/command/suite/select/filter/no_index/prefix_search/text_text.test
  Modified files:
    lib/expr.c

  Modified: lib/expr.c (+130 -6)
===================================================================
--- lib/expr.c    2014-11-19 17:56:24 +0900 (e86ece7)
+++ lib/expr.c    2014-11-19 18:27:58 +0900 (6823d50)
@@ -2784,6 +2784,127 @@ pseudo_query_scan(grn_ctx *ctx, grn_obj *x, grn_obj *y)
   }
 }
 
+static grn_bool
+pseudo_prefix_search_match(grn_ctx *ctx,
+                           const char *x, unsigned int x_len,
+                           const char *y, unsigned int y_len)
+{
+  return (x_len >= y_len && strncmp(x, y, y_len) == 0);
+}
+
+static grn_bool
+pseudo_prefix_search_raw_text_raw_text(grn_ctx *ctx,
+                                       const char *x, unsigned int x_len,
+                                       const char *y, unsigned int y_len)
+{
+  grn_obj *normalizer;
+  grn_obj *norm_x;
+  grn_obj *norm_y;
+  const char *norm_x_raw;
+  const char *norm_y_raw;
+  unsigned int norm_x_raw_len;
+  unsigned int norm_y_raw_len;
+  grn_bool matched = GRN_FALSE;
+
+  normalizer = grn_ctx_get(ctx, GRN_NORMALIZER_AUTO_NAME, -1);
+  norm_x = grn_string_open(ctx, x, x_len, normalizer, 0);
+  norm_y = grn_string_open(ctx, y, y_len, normalizer, 0);
+  grn_string_get_normalized(ctx, norm_x, &norm_x_raw, &norm_x_raw_len, NULL);
+  grn_string_get_normalized(ctx, norm_y, &norm_y_raw, &norm_y_raw_len, NULL);
+  matched = pseudo_prefix_search_match(ctx,
+                                       norm_x_raw, norm_x_raw_len,
+                                       norm_y_raw, norm_y_raw_len);
+
+  grn_obj_close(ctx, norm_x);
+  grn_obj_close(ctx, norm_y);
+  grn_obj_unlink(ctx, normalizer);
+
+  return matched;
+}
+
+static grn_bool
+pseudo_prefix_search_record_text(grn_ctx *ctx, grn_obj *record, grn_obj *table,
+                                 grn_obj *y)
+{
+  grn_obj *normalizer;
+  char x_key[GRN_TABLE_MAX_KEY_SIZE];
+  int x_key_len;
+  grn_bool matched = GRN_FALSE;
+
+  if (table->header.domain != GRN_DB_SHORT_TEXT) {
+    return GRN_FALSE;
+  }
+
+  x_key_len = grn_table_get_key(ctx, table, GRN_RECORD_VALUE(record),
+                                x_key, GRN_TABLE_MAX_KEY_SIZE);
+  grn_table_get_info(ctx, table, NULL, NULL, NULL, &normalizer, NULL);
+  if (normalizer) {
+    grn_obj *norm_y;
+    const char *norm_y_raw;
+    unsigned int norm_y_raw_len;
+    norm_y = grn_string_open(ctx, GRN_TEXT_VALUE(y), GRN_TEXT_LEN(y),
+                             normalizer, 0);
+    grn_string_get_normalized(ctx, norm_y, &norm_y_raw, &norm_y_raw_len, NULL);
+    matched = pseudo_prefix_search_match(ctx,
+                                         x_key, x_key_len,
+                                         norm_y_raw, norm_y_raw_len);
+    grn_obj_close(ctx, norm_y);
+  } else {
+    matched = pseudo_prefix_search_raw_text_raw_text(ctx,
+                                                     x_key,
+                                                     x_key_len,
+                                                     GRN_TEXT_VALUE(y),
+                                                     GRN_TEXT_LEN(y));
+  }
+
+  return matched;
+}
+
+static grn_bool
+pseudo_prefix_search_text_text(grn_ctx *ctx, grn_obj *x, grn_obj *y)
+{
+  return pseudo_prefix_search_raw_text_raw_text(ctx,
+                                                GRN_TEXT_VALUE(x),
+                                                GRN_TEXT_LEN(x),
+                                                GRN_TEXT_VALUE(y),
+                                                GRN_TEXT_LEN(y));
+}
+
+static grn_bool
+pseudo_prefix_search(grn_ctx *ctx, grn_obj *x, grn_obj *y)
+{
+  switch (x->header.domain) {
+  case GRN_DB_SHORT_TEXT :
+  case GRN_DB_TEXT :
+  case GRN_DB_LONG_TEXT :
+    switch (y->header.domain) {
+    case GRN_DB_SHORT_TEXT :
+    case GRN_DB_TEXT :
+    case GRN_DB_LONG_TEXT :
+      return pseudo_prefix_search_text_text(ctx, x, y);
+    default :
+      break;
+    }
+    return GRN_FALSE;
+  default:
+    {
+      grn_obj *domain;
+      domain = grn_ctx_at(ctx, x->header.domain);
+      if (GRN_OBJ_TABLEP(domain)) {
+        switch (y->header.domain) {
+        case GRN_DB_SHORT_TEXT :
+        case GRN_DB_TEXT :
+        case GRN_DB_LONG_TEXT :
+          return pseudo_prefix_search_record_text(ctx, x, domain, y);
+        default :
+          break;
+        }
+      }
+    }
+    return GRN_FALSE;
+  }
+}
+
 inline static void
 grn_expr_exec_get_member(grn_ctx *ctx,
                          grn_obj *expr,
@@ -3484,12 +3605,15 @@ grn_expr_exec(grn_ctx *ctx, grn_obj *expr, int nargs)
       case GRN_OP_PREFIX :
         {
           grn_obj *x, *y;
-          POP2ALLOC1(x, y, res);
-          GRN_INT32_SET(ctx, res,
-                        (GRN_TEXT_LEN(x) >= GRN_TEXT_LEN(y) &&
-                         !memcmp(GRN_TEXT_VALUE(x), GRN_TEXT_VALUE(y), GRN_TEXT_LEN(y))));
-          res->header.type = GRN_BULK;
-          res->header.domain = GRN_DB_INT32;
+          grn_bool matched;
+          POP1(y);
+          POP1(x);
+          WITH_SPSAVE({
+            matched = pseudo_prefix_search(ctx, x, y);
+          });
+          ALLOC1(res);
+          grn_obj_reinit(ctx, res, GRN_DB_INT32, 0);
+          GRN_INT32_SET(ctx, res, matched ? 1 : 0);
         }
         code++;
         break;

  Added: test/command/suite/select/filter/no_index/prefix_search/reference_text/no_normalizer.expected (+40 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/no_index/prefix_search/reference_text/no_normalizer.expected    2014-11-19 18:27:58 +0900 (0c58b0b)
@@ -0,0 +1,40 @@
+table_create Paths 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 path COLUMN_SCALAR Paths
+[[0,0.0,0.0],true]
+load --table Memos
+[
+{"path": "/data/Groonga/db"}
+]
+[[0,0.0,0.0],1]
+select Memos --filter 'path @^ "/data/gROONGA"'
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        1
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "path",
+          "Paths"
+        ]
+      ],
+      [
+        1,
+        "/data/Groonga/db"
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/filter/no_index/prefix_search/reference_text/no_normalizer.test (+11 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/no_index/prefix_search/reference_text/no_normalizer.test    2014-11-19 18:27:58 +0900 (1927b03)
@@ -0,0 +1,11 @@
+table_create Paths TABLE_PAT_KEY ShortText
+
+table_create Memos TABLE_NO_KEY
+column_create Memos path COLUMN_SCALAR Paths
+
+load --table Memos
+[
+{"path": "/data/Groonga/db"}
+]
+
+select Memos --filter 'path @^ "/data/gROONGA"'

  Added: test/command/suite/select/filter/no_index/prefix_search/reference_text/normalizer.expected (+40 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/no_index/prefix_search/reference_text/normalizer.expected    2014-11-19 18:27:58 +0900 (e6b3bea)
@@ -0,0 +1,40 @@
+table_create Paths TABLE_PAT_KEY ShortText --normalizer NormalizerAuto
+[[0,0.0,0.0],true]
+table_create Memos TABLE_NO_KEY
+[[0,0.0,0.0],true]
+column_create Memos path COLUMN_SCALAR Paths
+[[0,0.0,0.0],true]
+load --table Memos
+[
+{"path": "/data/Groonga/db"}
+]
+[[0,0.0,0.0],1]
+select Memos --filter 'path @^ "/data/gROONGA"'
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        1
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "path",
+          "Paths"
+        ]
+      ],
+      [
+        1,
+        "/data/groonga/db"
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/filter/no_index/prefix_search/reference_text/normalizer.test (+11 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/no_index/prefix_search/reference_text/normalizer.test    2014-11-19 18:27:58 +0900 (4897079)
@@ -0,0 +1,11 @@
+table_create Paths TABLE_PAT_KEY ShortText --normalizer NormalizerAuto
+
+table_create Memos TABLE_NO_KEY
+column_create Memos path COLUMN_SCALAR Paths
+
+load --table Memos
+[
+{"path": "/data/Groonga/db"}
+]
+
+select Memos --filter 'path @^ "/data/gROONGA"'

  Added: test/command/suite/select/filter/no_index/prefix_search/text_text.expected (+11 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/no_index/prefix_search/text_text.expected    2014-11-19 18:27:58 +0900 (dd674a7)
@@ -0,0 +1,11 @@
+table_create Memos TABLE_NO_KEY
+[[0,0.0,0.0],true]
+column_create Memos path COLUMN_SCALAR Text
+[[0,0.0,0.0],true]
+load --table Memos
+[
+{"path": "/data/Groonga/db"}
+]
+[[0,0.0,0.0],1]
+select Memos --filter 'path @^ "/data/gROONGA"'
+[[0,0.0,0.0],[[[1],[["_id","UInt32"],["path","Text"]],[1,"/data/Groonga/db"]]]]

  Added: test/command/suite/select/filter/no_index/prefix_search/text_text.test (+9 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/no_index/prefix_search/text_text.test    2014-11-19 18:27:58 +0900 (e86cb9d)
@@ -0,0 +1,9 @@
+table_create Memos TABLE_NO_KEY
+column_create Memos path COLUMN_SCALAR Text
+
+load --table Memos
+[
+{"path": "/data/Groonga/db"}
+]
+
+select Memos --filter 'path @^ "/data/gROONGA"'
-------------- next part --------------
HTML����������������������������...
下載 



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