Naoya Murakami
null+****@clear*****
Mon Jul 11 23:32:19 JST 2016
Naoya Murakami 2016-07-11 23:32:19 +0900 (Mon, 11 Jul 2016) New Revision: 38d018f72307aaf2964224e60750cd5a64037c30 https://github.com/groonga/groonga/commit/38d018f72307aaf2964224e60750cd5a64037c30 Merged 5b9a489: Merge pull request #582 from naoa/vector-slice Message: plugin vector: add vector_slice() Added files: test/command/suite/select/function/vector/vector_slice/from.expected test/command/suite/select/function/vector/vector_slice/from.test test/command/suite/select/function/vector/vector_slice/negative_from.expected test/command/suite/select/function/vector/vector_slice/negative_from.test test/command/suite/select/function/vector/vector_slice/negative_length.expected test/command/suite/select/function/vector/vector_slice/negative_length.test test/command/suite/select/function/vector/vector_slice/no_length.expected test/command/suite/select/function/vector/vector_slice/no_length.test test/command/suite/select/function/vector/vector_slice/over_length.expected test/command/suite/select/function/vector/vector_slice/over_length.test test/command/suite/select/function/vector/vector_slice/reference_vector.expected test/command/suite/select/function/vector/vector_slice/reference_vector.test test/command/suite/select/function/vector/vector_slice/vector.expected test/command/suite/select/function/vector/vector_slice/vector.test test/command/suite/select/function/vector/vector_slice/weight_reference_vector.expected test/command/suite/select/function/vector/vector_slice/weight_reference_vector.test Modified files: plugins/functions/vector.c Modified: plugins/functions/vector.c (+209 -0) =================================================================== --- plugins/functions/vector.c 2016-07-07 13:22:45 +0900 (a92fee9) +++ plugins/functions/vector.c 2016-07-11 23:32:19 +0900 (f54dbf2) @@ -70,6 +70,212 @@ func_vector_size(grn_ctx *ctx, int n_args, grn_obj **args, return grn_size; } +static grn_obj * +func_vector_slice(grn_ctx *ctx, int n_args, grn_obj **args, + grn_user_data *user_data) +{ + grn_obj *target; + grn_obj *from_raw = NULL; + grn_obj *length_raw = NULL; + int64_t from = 0; + int64_t length = -1; + uint32_t to = 0; + uint32_t size = 0; + grn_obj *slice; + + if (n_args < 2) { + GRN_PLUGIN_ERROR(ctx, GRN_INVALID_ARGUMENT, + "vector_slice(): wrong number of arguments (%d for 2..3)", + n_args); + return NULL; + } + + target = args[0]; + from_raw = args[1]; + if (n_args == 3) { + length_raw = args[2]; + } else { + length = 1; + } + switch (target->header.type) { + case GRN_VECTOR : + case GRN_PVECTOR : + case GRN_UVECTOR : + size = grn_vector_size(ctx, target); + break; + default : + { + grn_obj inspected; + + GRN_TEXT_INIT(&inspected, 0); + grn_inspect(ctx, target, &inspected); + GRN_PLUGIN_ERROR(ctx, GRN_INVALID_ARGUMENT, + "vector_slice(): target object must be vector: <%.*s>", + (int)GRN_TEXT_LEN(&inspected), + GRN_TEXT_VALUE(&inspected)); + GRN_OBJ_FIN(ctx, &inspected); + return NULL; + } + break; + } + + if (!grn_type_id_is_number_family(ctx, from_raw->header.domain)) { + grn_obj inspected; + + GRN_TEXT_INIT(&inspected, 0); + grn_inspect(ctx, &inspected, from_raw); + GRN_PLUGIN_ERROR(ctx, GRN_INVALID_ARGUMENT, + "vector_slice(): from must be a number: <%.*s>", + (int)GRN_TEXT_LEN(&inspected), + GRN_TEXT_VALUE(&inspected)); + GRN_OBJ_FIN(ctx, &inspected); + return NULL; + } + if (from_raw->header.domain == GRN_DB_INT32) { + from = GRN_INT32_VALUE(from_raw); + } else if (from_raw->header.domain == GRN_DB_INT64) { + from = GRN_INT64_VALUE(from_raw); + } else { + grn_obj buffer; + grn_rc rc; + + GRN_INT64_INIT(&buffer, 0); + rc = grn_obj_cast(ctx, from_raw, &buffer, GRN_FALSE); + if (rc == GRN_SUCCESS) { + from = GRN_INT64_VALUE(&buffer); + } + GRN_OBJ_FIN(ctx, &buffer); + + if (rc != GRN_SUCCESS) { + grn_obj inspected; + + GRN_TEXT_INIT(&inspected, 0); + grn_inspect(ctx, &inspected, from_raw); + GRN_PLUGIN_ERROR(ctx, rc, + "vector_slice(): " + "failed to cast from value to number: <%.*s>", + (int)GRN_TEXT_LEN(&inspected), + GRN_TEXT_VALUE(&inspected)); + GRN_OBJ_FIN(ctx, &inspected); + return NULL; + } + } + + if (length_raw) { + if (!grn_type_id_is_number_family(ctx, length_raw->header.domain)) { + grn_obj inspected; + + GRN_TEXT_INIT(&inspected, 0); + grn_inspect(ctx, &inspected, length_raw); + GRN_PLUGIN_ERROR(ctx, GRN_INVALID_ARGUMENT, + "vector_slice(): length must be a number: <%.*s>", + (int)GRN_TEXT_LEN(&inspected), + GRN_TEXT_VALUE(&inspected)); + GRN_OBJ_FIN(ctx, &inspected); + return NULL; + } + if (length_raw->header.domain == GRN_DB_INT32) { + length = GRN_INT32_VALUE(length_raw); + } else if (length_raw->header.domain == GRN_DB_INT64) { + length = GRN_INT64_VALUE(length_raw); + } else { + grn_obj buffer; + grn_rc rc; + + GRN_INT64_INIT(&buffer, 0); + rc = grn_obj_cast(ctx, length_raw, &buffer, GRN_FALSE); + if (rc == GRN_SUCCESS) { + length = GRN_INT64_VALUE(&buffer); + } + GRN_OBJ_FIN(ctx, &buffer); + + if (rc != GRN_SUCCESS) { + grn_obj inspected; + + GRN_TEXT_INIT(&inspected, 0); + grn_inspect(ctx, &inspected, length_raw); + GRN_PLUGIN_ERROR(ctx, rc, + "vector_slice(): " + "failed to cast length value to number: <%.*s>", + (int)GRN_TEXT_LEN(&inspected), + GRN_TEXT_VALUE(&inspected)); + GRN_OBJ_FIN(ctx, &inspected); + return NULL; + } + } + } + + slice = grn_plugin_proc_alloc(ctx, user_data, target->header.domain, GRN_OBJ_VECTOR); + if (!slice) { + return NULL; + } + + if (target->header.flags & GRN_OBJ_WITH_WEIGHT) { + slice->header.flags |= GRN_OBJ_WITH_WEIGHT; + } + + if (size == 0) { + return slice; + } + + if (length == 0) { + return slice; + } else if (length < 0) { + length = size; + } + + if (from < 0) { + from = size + from; + } + + if (from + length > size) { + to = size; + } else { + to = from + length; + } + + switch (target->header.type) { + case GRN_VECTOR : + { + unsigned int i; + for (i = from; i < to; i++) { + const char *content; + unsigned int content_length; + unsigned int weight; + grn_id domain; + content_length = + grn_vector_get_element(ctx, target, i, + &content, &weight, &domain); + grn_vector_add_element(ctx, slice, + content, content_length, weight, domain); + } + } + break; + case GRN_PVECTOR : + { + unsigned int i; + for (i = from; i < to; i++) { + grn_obj *element = GRN_PTR_VALUE_AT(target, i); + GRN_PTR_PUT(ctx, slice, element); + } + } + break; + case GRN_UVECTOR : + { + unsigned int i; + for (i = from; i < to; i++) { + grn_id id; + unsigned int weight; + id = grn_uvector_get_element(ctx, target, i, &weight); + grn_uvector_add_element(ctx, slice, id, weight); + } + } + break; + } + + return slice; +} + grn_rc GRN_PLUGIN_INIT(grn_ctx *ctx) { @@ -84,6 +290,9 @@ GRN_PLUGIN_REGISTER(grn_ctx *ctx) grn_proc_create(ctx, "vector_size", -1, GRN_PROC_FUNCTION, func_vector_size, NULL, NULL, 0, NULL); + grn_proc_create(ctx, "vector_slice", -1, GRN_PROC_FUNCTION, func_vector_slice, + NULL, NULL, 0, NULL); + return rc; } Added: test/command/suite/select/function/vector/vector_slice/from.expected (+63 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/vector/vector_slice/from.expected 2016-07-11 23:32:19 +0900 (f82bd7e) @@ -0,0 +1,63 @@ +plugin_register functions/vector +[[0,0.0,0.0],true] +table_create Memos TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +column_create Memos tags COLUMN_VECTOR ShortText +[[0,0.0,0.0],true] +load --table Memos +[ +{"_key": "Groonga", "tags": ["Groonga"]}, +{"_key": "Rroonga", "tags": ["Groonga", "Ruby"]}, +{"_key": "Nothing"} +] +[[0,0.0,0.0],3] +select Memos --output_columns 'tags, vector_slice(tags, 1, 1)' +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 3 + ], + [ + [ + "tags", + "ShortText" + ], + [ + "vector_slice", + null + ] + ], + [ + [ + "Groonga" + ], + [ + + ] + ], + [ + [ + "Groonga", + "Ruby" + ], + [ + "Ruby" + ] + ], + [ + [ + + ], + [ + + ] + ] + ] + ] +] Added: test/command/suite/select/function/vector/vector_slice/from.test (+14 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/vector/vector_slice/from.test 2016-07-11 23:32:19 +0900 (06b9f5d) @@ -0,0 +1,14 @@ +plugin_register functions/vector + +table_create Memos TABLE_HASH_KEY ShortText +column_create Memos tags COLUMN_VECTOR ShortText + +load --table Memos +[ +{"_key": "Groonga", "tags": ["Groonga"]}, +{"_key": "Rroonga", "tags": ["Groonga", "Ruby"]}, +{"_key": "Nothing"} +] + +select Memos \ + --output_columns 'tags, vector_slice(tags, 1, 1)' Added: test/command/suite/select/function/vector/vector_slice/negative_from.expected (+63 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/vector/vector_slice/negative_from.expected 2016-07-11 23:32:19 +0900 (795e1ba) @@ -0,0 +1,63 @@ +plugin_register functions/vector +[[0,0.0,0.0],true] +table_create Memos TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +column_create Memos tags COLUMN_VECTOR ShortText +[[0,0.0,0.0],true] +load --table Memos +[ +{"_key": "Groonga", "tags": ["Groonga"]}, +{"_key": "Rroonga", "tags": ["Groonga", "Ruby"]}, +{"_key": "Nothing"} +] +[[0,0.0,0.0],3] +select Memos --output_columns 'tags, vector_slice(tags, -1, 1)' +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 3 + ], + [ + [ + "tags", + "ShortText" + ], + [ + "vector_slice", + null + ] + ], + [ + [ + "Groonga" + ], + [ + "Groonga" + ] + ], + [ + [ + "Groonga", + "Ruby" + ], + [ + "Ruby" + ] + ], + [ + [ + + ], + [ + + ] + ] + ] + ] +] Added: test/command/suite/select/function/vector/vector_slice/negative_from.test (+14 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/vector/vector_slice/negative_from.test 2016-07-11 23:32:19 +0900 (64e5490) @@ -0,0 +1,14 @@ +plugin_register functions/vector + +table_create Memos TABLE_HASH_KEY ShortText +column_create Memos tags COLUMN_VECTOR ShortText + +load --table Memos +[ +{"_key": "Groonga", "tags": ["Groonga"]}, +{"_key": "Rroonga", "tags": ["Groonga", "Ruby"]}, +{"_key": "Nothing"} +] + +select Memos \ + --output_columns 'tags, vector_slice(tags, -1, 1)' Added: test/command/suite/select/function/vector/vector_slice/negative_length.expected (+64 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/vector/vector_slice/negative_length.expected 2016-07-11 23:32:19 +0900 (46d4f91) @@ -0,0 +1,64 @@ +plugin_register functions/vector +[[0,0.0,0.0],true] +table_create Memos TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +column_create Memos tags COLUMN_VECTOR ShortText +[[0,0.0,0.0],true] +load --table Memos +[ +{"_key": "Groonga", "tags": ["Groonga"]}, +{"_key": "Rroonga", "tags": ["Groonga", "Ruby"]}, +{"_key": "Nothing"} +] +[[0,0.0,0.0],3] +select Memos --output_columns 'tags, vector_slice(tags, 0, -1)' +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 3 + ], + [ + [ + "tags", + "ShortText" + ], + [ + "vector_slice", + null + ] + ], + [ + [ + "Groonga" + ], + [ + "Groonga" + ] + ], + [ + [ + "Groonga", + "Ruby" + ], + [ + "Groonga", + "Ruby" + ] + ], + [ + [ + + ], + [ + + ] + ] + ] + ] +] Added: test/command/suite/select/function/vector/vector_slice/negative_length.test (+14 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/vector/vector_slice/negative_length.test 2016-07-11 23:32:19 +0900 (6c4a54d) @@ -0,0 +1,14 @@ +plugin_register functions/vector + +table_create Memos TABLE_HASH_KEY ShortText +column_create Memos tags COLUMN_VECTOR ShortText + +load --table Memos +[ +{"_key": "Groonga", "tags": ["Groonga"]}, +{"_key": "Rroonga", "tags": ["Groonga", "Ruby"]}, +{"_key": "Nothing"} +] + +select Memos \ + --output_columns 'tags, vector_slice(tags, 0, -1)' Added: test/command/suite/select/function/vector/vector_slice/no_length.expected (+63 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/vector/vector_slice/no_length.expected 2016-07-11 23:32:19 +0900 (8795ce1) @@ -0,0 +1,63 @@ +plugin_register functions/vector +[[0,0.0,0.0],true] +table_create Memos TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +column_create Memos tags COLUMN_VECTOR ShortText +[[0,0.0,0.0],true] +load --table Memos +[ +{"_key": "Groonga", "tags": ["Groonga"]}, +{"_key": "Rroonga", "tags": ["Groonga", "Ruby"]}, +{"_key": "Nothing"} +] +[[0,0.0,0.0],3] +select Memos --output_columns 'tags, vector_slice(tags, 0)' +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 3 + ], + [ + [ + "tags", + "ShortText" + ], + [ + "vector_slice", + null + ] + ], + [ + [ + "Groonga" + ], + [ + "Groonga" + ] + ], + [ + [ + "Groonga", + "Ruby" + ], + [ + "Groonga" + ] + ], + [ + [ + + ], + [ + + ] + ] + ] + ] +] Added: test/command/suite/select/function/vector/vector_slice/no_length.test (+14 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/vector/vector_slice/no_length.test 2016-07-11 23:32:19 +0900 (8a65c75) @@ -0,0 +1,14 @@ +plugin_register functions/vector + +table_create Memos TABLE_HASH_KEY ShortText +column_create Memos tags COLUMN_VECTOR ShortText + +load --table Memos +[ +{"_key": "Groonga", "tags": ["Groonga"]}, +{"_key": "Rroonga", "tags": ["Groonga", "Ruby"]}, +{"_key": "Nothing"} +] + +select Memos \ + --output_columns 'tags, vector_slice(tags, 0)' Added: test/command/suite/select/function/vector/vector_slice/over_length.expected (+64 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/vector/vector_slice/over_length.expected 2016-07-11 23:32:19 +0900 (e4e93a9) @@ -0,0 +1,64 @@ +plugin_register functions/vector +[[0,0.0,0.0],true] +table_create Memos TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +column_create Memos tags COLUMN_VECTOR ShortText +[[0,0.0,0.0],true] +load --table Memos +[ +{"_key": "Groonga", "tags": ["Groonga"]}, +{"_key": "Rroonga", "tags": ["Groonga", "Ruby"]}, +{"_key": "Nothing"} +] +[[0,0.0,0.0],3] +select Memos --output_columns 'tags, vector_slice(tags, 0, 2)' +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 3 + ], + [ + [ + "tags", + "ShortText" + ], + [ + "vector_slice", + null + ] + ], + [ + [ + "Groonga" + ], + [ + "Groonga" + ] + ], + [ + [ + "Groonga", + "Ruby" + ], + [ + "Groonga", + "Ruby" + ] + ], + [ + [ + + ], + [ + + ] + ] + ] + ] +] Added: test/command/suite/select/function/vector/vector_slice/over_length.test (+14 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/vector/vector_slice/over_length.test 2016-07-11 23:32:19 +0900 (ef1c06e) @@ -0,0 +1,14 @@ +plugin_register functions/vector + +table_create Memos TABLE_HASH_KEY ShortText +column_create Memos tags COLUMN_VECTOR ShortText + +load --table Memos +[ +{"_key": "Groonga", "tags": ["Groonga"]}, +{"_key": "Rroonga", "tags": ["Groonga", "Ruby"]}, +{"_key": "Nothing"} +] + +select Memos \ + --output_columns 'tags, vector_slice(tags, 0, 2)' Added: test/command/suite/select/function/vector/vector_slice/reference_vector.expected (+65 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/vector/vector_slice/reference_vector.expected 2016-07-11 23:32:19 +0900 (dca288f) @@ -0,0 +1,65 @@ +plugin_register functions/vector +[[0,0.0,0.0],true] +table_create Tags TABLE_PAT_KEY ShortText +[[0,0.0,0.0],true] +table_create Memos TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +column_create Memos tags COLUMN_VECTOR Tags +[[0,0.0,0.0],true] +load --table Memos +[ +{"_key": "Groonga", "tags": ["Groonga"]}, +{"_key": "Rroonga", "tags": ["Groonga", "Ruby"]}, +{"_key": "Nothing"} +] +[[0,0.0,0.0],3] +select Memos --output_columns 'tags, vector_slice(tags, 0, 1)' +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 3 + ], + [ + [ + "tags", + "Tags" + ], + [ + "vector_slice", + null + ] + ], + [ + [ + "Groonga" + ], + [ + "Groonga" + ] + ], + [ + [ + "Groonga", + "Ruby" + ], + [ + "Groonga" + ] + ], + [ + [ + + ], + [ + + ] + ] + ] + ] +] Added: test/command/suite/select/function/vector/vector_slice/reference_vector.test (+16 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/vector/vector_slice/reference_vector.test 2016-07-11 23:32:19 +0900 (245fc54) @@ -0,0 +1,16 @@ +plugin_register functions/vector + +table_create Tags TABLE_PAT_KEY ShortText + +table_create Memos TABLE_HASH_KEY ShortText +column_create Memos tags COLUMN_VECTOR Tags + +load --table Memos +[ +{"_key": "Groonga", "tags": ["Groonga"]}, +{"_key": "Rroonga", "tags": ["Groonga", "Ruby"]}, +{"_key": "Nothing"} +] + +select Memos \ + --output_columns 'tags, vector_slice(tags, 0, 1)' Added: test/command/suite/select/function/vector/vector_slice/vector.expected (+63 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/vector/vector_slice/vector.expected 2016-07-11 23:32:19 +0900 (2466b6e) @@ -0,0 +1,63 @@ +plugin_register functions/vector +[[0,0.0,0.0],true] +table_create Memos TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +column_create Memos tags COLUMN_VECTOR ShortText +[[0,0.0,0.0],true] +load --table Memos +[ +{"_key": "Groonga", "tags": ["Groonga"]}, +{"_key": "Rroonga", "tags": ["Groonga", "Ruby"]}, +{"_key": "Nothing"} +] +[[0,0.0,0.0],3] +select Memos --output_columns 'tags, vector_slice(tags, 0, 1)' +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 3 + ], + [ + [ + "tags", + "ShortText" + ], + [ + "vector_slice", + null + ] + ], + [ + [ + "Groonga" + ], + [ + "Groonga" + ] + ], + [ + [ + "Groonga", + "Ruby" + ], + [ + "Groonga" + ] + ], + [ + [ + + ], + [ + + ] + ] + ] + ] +] Added: test/command/suite/select/function/vector/vector_slice/vector.test (+14 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/vector/vector_slice/vector.test 2016-07-11 23:32:19 +0900 (a5c4b52) @@ -0,0 +1,14 @@ +plugin_register functions/vector + +table_create Memos TABLE_HASH_KEY ShortText +column_create Memos tags COLUMN_VECTOR ShortText + +load --table Memos +[ +{"_key": "Groonga", "tags": ["Groonga"]}, +{"_key": "Rroonga", "tags": ["Groonga", "Ruby"]}, +{"_key": "Nothing"} +] + +select Memos \ + --output_columns 'tags, vector_slice(tags, 0, 1)' Added: test/command/suite/select/function/vector/vector_slice/weight_reference_vector.expected (+63 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/vector/vector_slice/weight_reference_vector.expected 2016-07-11 23:32:19 +0900 (e6b4d4e) @@ -0,0 +1,63 @@ +plugin_register functions/vector +[[0,0.0,0.0],true] +table_create Tags TABLE_PAT_KEY ShortText +[[0,0.0,0.0],true] +table_create Memos TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +column_create Memos tags COLUMN_VECTOR|WITH_WEIGHT Tags +[[0,0.0,0.0],true] +load --table Memos +[ +{"_key": "Groonga", "tags": {"Groonga": 100}}, +{"_key": "Rroonga", "tags": {"Groonga": 100, "Ruby": 50}}, +{"_key": "Nothing"} +] +[[0,0.0,0.0],3] +select Memos --columns[slice].stage output --columns[slice].type Tags --columns[slice].flags COLUMN_VECTOR|WITH_WEIGHT --columns[slice].value 'vector_slice(tags, 0, 1)' --output_columns 'tags, slice' +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 3 + ], + [ + [ + "tags", + "Tags" + ], + [ + "slice", + "Tags" + ] + ], + [ + { + "Groonga": 100 + }, + { + "Groonga": 100 + } + ], + [ + { + "Groonga": 100, + "Ruby": 50 + }, + { + "Groonga": 100 + } + ], + [ + { + }, + { + } + ] + ] + ] +] Added: test/command/suite/select/function/vector/vector_slice/weight_reference_vector.test (+20 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/vector/vector_slice/weight_reference_vector.test 2016-07-11 23:32:19 +0900 (24e2daf) @@ -0,0 +1,20 @@ +plugin_register functions/vector + +table_create Tags TABLE_PAT_KEY ShortText + +table_create Memos TABLE_HASH_KEY ShortText +column_create Memos tags COLUMN_VECTOR|WITH_WEIGHT Tags + +load --table Memos +[ +{"_key": "Groonga", "tags": {"Groonga": 100}}, +{"_key": "Rroonga", "tags": {"Groonga": 100, "Ruby": 50}}, +{"_key": "Nothing"} +] + +select Memos \ + --columns[slice].stage output \ + --columns[slice].type Tags \ + --columns[slice].flags COLUMN_VECTOR|WITH_WEIGHT \ + --columns[slice].value 'vector_slice(tags, 0, 1)' \ + --output_columns 'tags, slice' -------------- next part -------------- HTML����������������������������... Télécharger