[Groonga-commit] groonga/groonga at f70f63d [master] functions/index_column: add index_column_source_records() function

Back to archive index

Naoya Murakami null+****@clear*****
Thu Dec 21 20:49:07 JST 2017


Naoya Murakami	2017-12-21 20:49:07 +0900 (Thu, 21 Dec 2017)

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

  Merged 9cfbc20: Merge pull request #790 from naoa/index_column_source_records

  Message:
    functions/index_column: add index_column_source_records() function
    
     It gets source records of index column.
    Syntax:
      index_column_source_records(index_column_name[, limit])
         index_column_name: name of index columns as string
         limit(option): number of records to get (default: -1, -1 means all records)

  Added files:
    test/command/suite/select/function/index_column/index_column_source_records/default.expected
    test/command/suite/select/function/index_column/index_column_source_records/default.test
    test/command/suite/select/function/index_column/index_column_source_records/limit.expected
    test/command/suite/select/function/index_column/index_column_source_records/limit.test
  Modified files:
    plugins/functions/index_column.c

  Modified: plugins/functions/index_column.c (+74 -0)
===================================================================
--- plugins/functions/index_column.c    2017-12-21 20:33:04 +0900 (a7f969c3e)
+++ plugins/functions/index_column.c    2017-12-21 20:49:07 +0900 (9315ca65c)
@@ -247,6 +247,76 @@ func_index_column_df_ratio(grn_ctx *ctx,
   }
 }
 
+static grn_obj *
+func_index_column_source_records(grn_ctx *ctx,
+                                 int n_args,
+                                 grn_obj **args,
+                                 grn_user_data *user_data)
+{
+  grn_ii *ii;
+  caller_index_info caller_index_info;
+  int64_t limit = -1;
+
+  if (n_args < 1 || n_args > 2) {
+    GRN_PLUGIN_ERROR(ctx,
+                     GRN_INVALID_ARGUMENT,
+                     "index_column_source_records(): "
+                     "wrong number of arguments (%d for 1..2)", n_args - 1);
+    return NULL;
+  }
+
+  memset(&caller_index_info, 0, sizeof(caller_index_info));
+
+  if (get_caller_index_info(ctx,
+                            args[0],
+                            user_data,
+                            &caller_index_info,
+                            "index_column_source_records()") != GRN_SUCCESS) {
+    return NULL;
+  }
+
+  if (n_args == 2) {
+    limit = grn_plugin_proc_func_arg_int64(ctx, args[1],
+                                           "index_column_source_records()");
+    if (ctx->rc != GRN_SUCCESS) {
+      return NULL;
+    }
+  }
+
+  ii = (grn_ii *)caller_index_info.index_column;
+
+  {
+    grn_obj *records;
+
+    records = grn_plugin_proc_alloc(ctx, user_data,
+                                    grn_obj_get_range(ctx, caller_index_info.index_column),
+                                    GRN_OBJ_VECTOR);
+    if (!records) {
+      return NULL;
+    }
+
+    {
+      grn_ii_cursor *ii_cursor;
+      grn_posting *posting;
+      int64_t n_records = 0;
+      ii_cursor = grn_ii_cursor_open(ctx, ii, caller_index_info.term_id,
+                                     GRN_ID_NIL, GRN_ID_MAX,
+                                     grn_ii_get_n_elements(ctx, ii), 0);
+      if (ii_cursor) {
+        while ((posting = grn_ii_cursor_next(ctx, ii_cursor))) {
+          if (limit > 0 && n_records >= limit) {
+            break;
+          }
+          GRN_RECORD_PUT(ctx, records, posting->rid);
+          n_records++;
+        }
+        grn_ii_cursor_close(ctx, ii_cursor);
+      }
+    }
+    return records;
+  }
+}
+
 grn_rc
 GRN_PLUGIN_INIT(grn_ctx *ctx)
 {
@@ -269,6 +339,10 @@ GRN_PLUGIN_REGISTER(grn_ctx *ctx)
                   GRN_PROC_FUNCTION,
                   func_index_column_df_ratio, NULL, NULL, 0, NULL);
 
+  grn_proc_create(ctx, "index_column_source_records", -1,
+                  GRN_PROC_FUNCTION,
+                  func_index_column_source_records, NULL, NULL, 0, NULL);
+
   return ctx->rc;
 }
 

  Added: test/command/suite/select/function/index_column/index_column_source_records/default.expected (+179 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/function/index_column/index_column_source_records/default.expected    2017-12-21 20:49:07 +0900 (4bfa4495c)
@@ -0,0 +1,179 @@
+plugin_register functions/index_column
+[[0,0.0,0.0],true]
+table_create Memos TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+table_create Terms TABLE_PAT_KEY ShortText   --default_tokenizer TokenBigram   --normalizer NormalizerAuto
+[[0,0.0,0.0],true]
+column_create Terms index COLUMN_INDEX|WITH_POSITION Memos _key
+[[0,0.0,0.0],true]
+load --table Memos
+[
+{"_key": "Groonga is a fast full text search engine."},
+{"_key": "Mroonga is a MySQL storage engine based on Groonga."},
+{"_key": "Rroonga is a Ruby bindings for Groonga."}
+]
+[[0,0.0,0.0],3]
+select Terms   --limit -1   --sort_keys _id   --columns[index_records].stage output   --columns[index_records].type Memos   --columns[index_records].flags COLUMN_VECTOR   --columns[index_records].value 'index_column_source_records("index")'   --output_columns '_id, _key, index_records'
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        18
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "index_records",
+          "Memos"
+        ]
+      ],
+      [
+        1,
+        "groonga",
+        [
+          "Groonga is a fast full text search engine.",
+          "Mroonga is a MySQL storage engine based on Groonga.",
+          "Rroonga is a Ruby bindings for Groonga."
+        ]
+      ],
+      [
+        2,
+        "is",
+        [
+          "Groonga is a fast full text search engine.",
+          "Mroonga is a MySQL storage engine based on Groonga.",
+          "Rroonga is a Ruby bindings for Groonga."
+        ]
+      ],
+      [
+        3,
+        "a",
+        [
+          "Groonga is a fast full text search engine.",
+          "Mroonga is a MySQL storage engine based on Groonga.",
+          "Rroonga is a Ruby bindings for Groonga."
+        ]
+      ],
+      [
+        4,
+        "fast",
+        [
+          "Groonga is a fast full text search engine."
+        ]
+      ],
+      [
+        5,
+        "full",
+        [
+          "Groonga is a fast full text search engine."
+        ]
+      ],
+      [
+        6,
+        "text",
+        [
+          "Groonga is a fast full text search engine."
+        ]
+      ],
+      [
+        7,
+        "search",
+        [
+          "Groonga is a fast full text search engine."
+        ]
+      ],
+      [
+        8,
+        "engine",
+        [
+          "Groonga is a fast full text search engine.",
+          "Mroonga is a MySQL storage engine based on Groonga."
+        ]
+      ],
+      [
+        9,
+        ".",
+        [
+          "Groonga is a fast full text search engine.",
+          "Mroonga is a MySQL storage engine based on Groonga.",
+          "Rroonga is a Ruby bindings for Groonga."
+        ]
+      ],
+      [
+        10,
+        "mroonga",
+        [
+          "Mroonga is a MySQL storage engine based on Groonga."
+        ]
+      ],
+      [
+        11,
+        "mysql",
+        [
+          "Mroonga is a MySQL storage engine based on Groonga."
+        ]
+      ],
+      [
+        12,
+        "storage",
+        [
+          "Mroonga is a MySQL storage engine based on Groonga."
+        ]
+      ],
+      [
+        13,
+        "based",
+        [
+          "Mroonga is a MySQL storage engine based on Groonga."
+        ]
+      ],
+      [
+        14,
+        "on",
+        [
+          "Mroonga is a MySQL storage engine based on Groonga."
+        ]
+      ],
+      [
+        15,
+        "rroonga",
+        [
+          "Rroonga is a Ruby bindings for Groonga."
+        ]
+      ],
+      [
+        16,
+        "ruby",
+        [
+          "Rroonga is a Ruby bindings for Groonga."
+        ]
+      ],
+      [
+        17,
+        "bindings",
+        [
+          "Rroonga is a Ruby bindings for Groonga."
+        ]
+      ],
+      [
+        18,
+        "for",
+        [
+          "Rroonga is a Ruby bindings for Groonga."
+        ]
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/function/index_column/index_column_source_records/default.test (+24 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/function/index_column/index_column_source_records/default.test    2017-12-21 20:49:07 +0900 (3700f0ba6)
@@ -0,0 +1,24 @@
+plugin_register functions/index_column
+
+table_create Memos TABLE_HASH_KEY ShortText
+
+table_create Terms TABLE_PAT_KEY ShortText \
+  --default_tokenizer TokenBigram \
+  --normalizer NormalizerAuto
+column_create Terms index COLUMN_INDEX|WITH_POSITION Memos _key
+
+load --table Memos
+[
+{"_key": "Groonga is a fast full text search engine."},
+{"_key": "Mroonga is a MySQL storage engine based on Groonga."},
+{"_key": "Rroonga is a Ruby bindings for Groonga."}
+]
+
+select Terms \
+  --limit -1 \
+  --sort_keys _id \
+  --columns[index_records].stage output \
+  --columns[index_records].type Memos \
+  --columns[index_records].flags COLUMN_VECTOR \
+  --columns[index_records].value 'index_column_source_records("index")' \
+  --output_columns '_id, _key, index_records'

  Added: test/command/suite/select/function/index_column/index_column_source_records/limit.expected (+175 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/function/index_column/index_column_source_records/limit.expected    2017-12-21 20:49:07 +0900 (6a7d7fc49)
@@ -0,0 +1,175 @@
+plugin_register functions/index_column
+[[0,0.0,0.0],true]
+table_create Memos TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+table_create Terms TABLE_PAT_KEY ShortText   --default_tokenizer TokenBigram   --normalizer NormalizerAuto
+[[0,0.0,0.0],true]
+column_create Terms index COLUMN_INDEX|WITH_POSITION Memos _key
+[[0,0.0,0.0],true]
+load --table Memos
+[
+{"_key": "Groonga is a fast full text search engine."},
+{"_key": "Mroonga is a MySQL storage engine based on Groonga."},
+{"_key": "Rroonga is a Ruby bindings for Groonga."}
+]
+[[0,0.0,0.0],3]
+select Terms   --limit -1   --sort_keys _id   --columns[index_records].stage output   --columns[index_records].type Memos   --columns[index_records].flags COLUMN_VECTOR   --columns[index_records].value 'index_column_source_records("index", 2)'   --output_columns '_id, _key, index_records'
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        18
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "index_records",
+          "Memos"
+        ]
+      ],
+      [
+        1,
+        "groonga",
+        [
+          "Groonga is a fast full text search engine.",
+          "Mroonga is a MySQL storage engine based on Groonga."
+        ]
+      ],
+      [
+        2,
+        "is",
+        [
+          "Groonga is a fast full text search engine.",
+          "Mroonga is a MySQL storage engine based on Groonga."
+        ]
+      ],
+      [
+        3,
+        "a",
+        [
+          "Groonga is a fast full text search engine.",
+          "Mroonga is a MySQL storage engine based on Groonga."
+        ]
+      ],
+      [
+        4,
+        "fast",
+        [
+          "Groonga is a fast full text search engine."
+        ]
+      ],
+      [
+        5,
+        "full",
+        [
+          "Groonga is a fast full text search engine."
+        ]
+      ],
+      [
+        6,
+        "text",
+        [
+          "Groonga is a fast full text search engine."
+        ]
+      ],
+      [
+        7,
+        "search",
+        [
+          "Groonga is a fast full text search engine."
+        ]
+      ],
+      [
+        8,
+        "engine",
+        [
+          "Groonga is a fast full text search engine.",
+          "Mroonga is a MySQL storage engine based on Groonga."
+        ]
+      ],
+      [
+        9,
+        ".",
+        [
+          "Groonga is a fast full text search engine.",
+          "Mroonga is a MySQL storage engine based on Groonga."
+        ]
+      ],
+      [
+        10,
+        "mroonga",
+        [
+          "Mroonga is a MySQL storage engine based on Groonga."
+        ]
+      ],
+      [
+        11,
+        "mysql",
+        [
+          "Mroonga is a MySQL storage engine based on Groonga."
+        ]
+      ],
+      [
+        12,
+        "storage",
+        [
+          "Mroonga is a MySQL storage engine based on Groonga."
+        ]
+      ],
+      [
+        13,
+        "based",
+        [
+          "Mroonga is a MySQL storage engine based on Groonga."
+        ]
+      ],
+      [
+        14,
+        "on",
+        [
+          "Mroonga is a MySQL storage engine based on Groonga."
+        ]
+      ],
+      [
+        15,
+        "rroonga",
+        [
+          "Rroonga is a Ruby bindings for Groonga."
+        ]
+      ],
+      [
+        16,
+        "ruby",
+        [
+          "Rroonga is a Ruby bindings for Groonga."
+        ]
+      ],
+      [
+        17,
+        "bindings",
+        [
+          "Rroonga is a Ruby bindings for Groonga."
+        ]
+      ],
+      [
+        18,
+        "for",
+        [
+          "Rroonga is a Ruby bindings for Groonga."
+        ]
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/function/index_column/index_column_source_records/limit.test (+24 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/function/index_column/index_column_source_records/limit.test    2017-12-21 20:49:07 +0900 (a50b16fd9)
@@ -0,0 +1,24 @@
+plugin_register functions/index_column
+
+table_create Memos TABLE_HASH_KEY ShortText
+
+table_create Terms TABLE_PAT_KEY ShortText \
+  --default_tokenizer TokenBigram \
+  --normalizer NormalizerAuto
+column_create Terms index COLUMN_INDEX|WITH_POSITION Memos _key
+
+load --table Memos
+[
+{"_key": "Groonga is a fast full text search engine."},
+{"_key": "Mroonga is a MySQL storage engine based on Groonga."},
+{"_key": "Rroonga is a Ruby bindings for Groonga."}
+]
+
+select Terms \
+  --limit -1 \
+  --sort_keys _id \
+  --columns[index_records].stage output \
+  --columns[index_records].type Memos \
+  --columns[index_records].flags COLUMN_VECTOR \
+  --columns[index_records].value 'index_column_source_records("index", 2)' \
+  --output_columns '_id, _key, index_records'
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20171221/5c38f7c1/attachment-0001.htm 



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