Kouhei Sutou
null+****@clear*****
Wed Feb 19 16:31:41 JST 2014
Kouhei Sutou 2014-02-19 16:31:41 +0900 (Wed, 19 Feb 2014) New Revision: 9925dc97e9d8689f5304f4893489b3c7e9953a26 https://github.com/groonga/groonga/commit/9925dc97e9d8689f5304f4893489b3c7e9953a26 Message: load: support forward index value loading TODO: * Old value isn't collected yet. Are there any effective way to collect old value. Added files: test/command/suite/load/index/forward/array/value_weight.expected test/command/suite/load/index/forward/array/value_weight.test test/command/suite/load/index/forward/object/value_weight.expected test/command/suite/load/index/forward/object/value_weight.test Modified files: lib/db.c Modified: lib/db.c (+40 -0) =================================================================== --- lib/db.c 2014-02-19 15:22:37 +0900 (9443abd) +++ lib/db.c 2014-02-19 16:31:41 +0900 (1c51d33) @@ -9580,6 +9580,11 @@ set_vector(grn_ctx *ctx, grn_obj *column, grn_id id, grn_obj *vector) static void set_map(grn_ctx *ctx, grn_obj *column, grn_id id, grn_obj *map) { + uint i, n; + grn_obj new_value; + grn_id range_id; + grn_obj *range; + if (column->header.type != GRN_COLUMN_INDEX) { char column_name[GRN_TABLE_MAX_KEY_SIZE]; int column_name_size; @@ -9590,6 +9595,41 @@ set_map(grn_ctx *ctx, grn_obj *column, grn_id id, grn_obj *map) column_name_size, column_name); return; } + + n = GRN_UINT32_VALUE(map); + range_id = grn_obj_get_range(ctx, column); + range = grn_ctx_at(ctx, range_id); + if (!range) { + char column_name[GRN_TABLE_MAX_KEY_SIZE]; + int column_name_size; + column_name_size = grn_obj_name(ctx, column, column_name, + GRN_TABLE_MAX_KEY_SIZE); + ERR(GRN_INVALID_ARGUMENT, + "<%.*s>: dangling range reference: <%d>", + column_name_size, column_name, + range_id); + return; + } + + GRN_RECORD_INIT(&new_value, GRN_OBJ_VECTOR, range_id); + for (i = 0; i < n; i += 2) { + grn_obj *key, *value; + grn_id token_id; + key = map + 1 + i; + value = key + 1; + token_id = grn_table_add(ctx, range, + GRN_TEXT_VALUE(key), GRN_TEXT_LEN(key), + NULL); + if (token_id == GRN_ID_NIL) { + break; + } + GRN_RECORD_PUT(ctx, &new_value, token_id); + } + if (!ctx->rc) { + grn_obj *old_value = NULL; /* TODO */ + grn_column_index_update(ctx, column, id, 1, old_value, &new_value); + } + GRN_OBJ_FIN(ctx, &new_value); } static inline int Added: test/command/suite/load/index/forward/array/value_weight.expected (+19 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/load/index/forward/array/value_weight.expected 2014-02-19 16:31:41 +0900 (efb398a) @@ -0,0 +1,19 @@ +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_INDEX|WITH_WEIGHT Tags +[[0,0.0,0.0],true] +load --table Memos +[ +["_key", "tags"], +[ + "Groonga is fast", + { + "groonga": 100 + } +] +] +[[0,0.0,0.0],1] +select Tags +[[0,0.0,0.0],[[[1],[["_id","UInt32"],["_key","ShortText"]],[1,"groonga"]]]] Added: test/command/suite/load/index/forward/array/value_weight.test (+17 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/load/index/forward/array/value_weight.test 2014-02-19 16:31:41 +0900 (04ca5ce) @@ -0,0 +1,17 @@ +table_create Tags TABLE_PAT_KEY ShortText + +table_create Memos TABLE_HASH_KEY ShortText +column_create Memos tags COLUMN_INDEX|WITH_WEIGHT Tags + +load --table Memos +[ +["_key", "tags"], +[ + "Groonga is fast", + { + "groonga": 100 + } +] +] + +select Tags Added: test/command/suite/load/index/forward/object/value_weight.expected (+18 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/load/index/forward/object/value_weight.expected 2014-02-19 16:31:41 +0900 (441cb57) @@ -0,0 +1,18 @@ +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_INDEX|WITH_WEIGHT Tags +[[0,0.0,0.0],true] +load --table Memos +[ +{ + "_key": "Groonga is fast", + "tags": { + "groonga": 100 + } +} +] +[[0,0.0,0.0],1] +select Tags +[[0,0.0,0.0],[[[1],[["_id","UInt32"],["_key","ShortText"]],[1,"groonga"]]]] Added: test/command/suite/load/index/forward/object/value_weight.test (+16 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/load/index/forward/object/value_weight.test 2014-02-19 16:31:41 +0900 (d11dcb9) @@ -0,0 +1,16 @@ +table_create Tags TABLE_PAT_KEY ShortText + +table_create Memos TABLE_HASH_KEY ShortText +column_create Memos tags COLUMN_INDEX|WITH_WEIGHT Tags + +load --table Memos +[ +{ + "_key": "Groonga is fast", + "tags": { + "groonga": 100 + } +} +] + +select Tags -------------- next part -------------- HTML����������������������������...Download