Kouhei Sutou
null+****@clear*****
Mon Mar 3 17:37:14 JST 2014
Kouhei Sutou 2014-03-03 17:37:14 +0900 (Mon, 03 Mar 2014) New Revision: cb5c7e5629d0b78711e67440c131bb124322237e https://github.com/groonga/groonga/commit/cb5c7e5629d0b78711e67440c131bb124322237e Message: select: fix --adjust implementation We should use WITH_WEIGHT of inverted index for weight. Modified files: lib/db.c lib/expr.c lib/proc.c test/command/suite/select/adjuster/multiple.expected test/command/suite/select/adjuster/multiple.test test/command/suite/select/adjuster/no_factor.expected test/command/suite/select/adjuster/no_factor.test test/command/suite/select/adjuster/not_all_match.expected test/command/suite/select/adjuster/not_all_match.test test/command/suite/select/adjuster/not_forward_index.expected test/command/suite/select/adjuster/not_forward_index.test test/command/suite/select/adjuster/one.expected test/command/suite/select/adjuster/one.test test/command/suite/select/match_columns/weight/forward_index.expected test/command/suite/select/match_columns/weight/forward_index.test test/command/suite/select/match_columns/weight/nested_forward_index.expected test/command/suite/select/match_columns/weight/nested_forward_index.test test/command/suite/select/query/forward_index.expected test/command/suite/select/query/forward_index.test Modified: lib/db.c (+3 -153) =================================================================== --- lib/db.c 2014-02-26 23:03:51 +0900 (4384bf0) +++ lib/db.c 2014-03-03 17:37:14 +0900 (b25bb68) @@ -2791,7 +2791,7 @@ grn_obj_search_accessor(grn_ctx *ctx, grn_obj *obj, grn_obj *query, if (!base_res) { goto exit; } - rc = grn_obj_search(ctx, last_obj, query, base_res, GRN_OP_OR, optarg); + rc = grn_obj_search(ctx, index, query, base_res, GRN_OP_OR, optarg); if (rc != GRN_SUCCESS) { grn_obj_unlink(ctx, base_res); goto exit; @@ -2917,141 +2917,6 @@ grn_obj_search_column_inverted_index(grn_ctx *ctx, grn_obj *obj, grn_obj *query, return rc; } -static grn_id -grn_obj_search_column_forward_index_get_adjust_id(grn_ctx *ctx, - grn_obj *forward_index, - grn_obj *value) -{ - grn_id adjust_id = GRN_ID_NIL; - grn_obj *adjust_keys; - grn_id adjust_keys_id; - const char *adjust_key = NULL; - unsigned int adjust_key_size = 0; - grn_obj casted_adjust_key; - grn_bool need_cast; - - adjust_keys_id = grn_obj_get_range(ctx, forward_index); - adjust_keys = grn_ctx_at(ctx, adjust_keys_id); - if (!adjust_keys) { - char column_name[GRN_TABLE_MAX_KEY_SIZE]; - int column_name_size; - column_name_size = grn_obj_name(ctx, forward_index, - column_name, GRN_TABLE_MAX_KEY_SIZE); - ERR(GRN_INVALID_ARGUMENT, - "<%.*s>: dangling range reference: <%d>", - column_name_size, column_name, - adjust_keys_id); - return GRN_ID_NIL; - } - - need_cast = adjust_keys->header.domain != value->header.domain; - if (need_cast) { - grn_rc rc; - GRN_OBJ_INIT(&casted_adjust_key, GRN_BULK, 0, adjust_keys->header.domain); - rc = grn_obj_cast(ctx, value, &casted_adjust_key, GRN_FALSE); - if (rc == GRN_SUCCESS) { - adjust_key = GRN_BULK_HEAD(&casted_adjust_key); - adjust_key_size = GRN_BULK_VSIZE(&casted_adjust_key); - } else { - grn_obj *range; - range = grn_ctx_at(ctx, adjust_keys->header.domain); - ERR_CAST(forward_index, range, value); - grn_obj_unlink(ctx, range); - } - } else { - adjust_key = GRN_BULK_HEAD(value); - adjust_key_size = GRN_BULK_VSIZE(value); - } - - if (adjust_key) { - adjust_id = grn_table_get(ctx, adjust_keys, adjust_key, adjust_key_size); - } - - if (need_cast) { - GRN_OBJ_FIN(ctx, &casted_adjust_key); - } - - grn_obj_unlink(ctx, adjust_keys); - - return adjust_id; -} - -static grn_rc -grn_obj_search_column_forward_index(grn_ctx *ctx, grn_obj *forward_index, - grn_obj *query, - grn_obj *res, grn_operator op, - grn_search_optarg *optarg) -{ - grn_obj *index; - unsigned int n_indexes; - grn_ii *ii = (grn_ii *)forward_index; - grn_id adjust_id; - grn_obj *targets; - grn_table_cursor *table_cursor; - double factor = 0.0; - - n_indexes = grn_column_index(ctx, forward_index, - GRN_OP_MATCH, &index, 1, NULL); - if (n_indexes == 0) { - return GRN_INVALID_ARGUMENT; - } - - adjust_id = grn_obj_search_column_forward_index_get_adjust_id(ctx, - forward_index, - query); - if (adjust_id == GRN_ID_NIL) { - return GRN_SUCCESS; - } - - if (optarg && !optarg->weight_vector && optarg->vector_size > 0) { - factor = optarg->vector_size; - } - - { - grn_obj *table; - table = grn_ctx_at(ctx, forward_index->header.domain); - targets = grn_table_create(ctx, NULL, 0, NULL, - GRN_TABLE_HASH_KEY|GRN_OBJ_WITH_SUBREC, - table, NULL); - grn_obj_unlink(ctx, table); - } - - grn_obj_search(ctx, index, query, targets, GRN_OP_OR, NULL); - - table_cursor = grn_table_cursor_open(ctx, targets, NULL, 0, NULL, 0, - 0, -1, GRN_CURSOR_BY_ID); - if (table_cursor) { - while (grn_table_cursor_next(ctx, table_cursor) != GRN_ID_NIL) { - grn_id id; - void *key; - grn_ii_cursor *ii_cursor; - int flags = GRN_OBJ_WITH_WEIGHT; - - grn_table_cursor_get_key(ctx, table_cursor, &key); - id = *((grn_id *)key); - ii_cursor = grn_ii_cursor_open(ctx, ii, id, GRN_ID_NIL, GRN_ID_MAX, - ii->n_elements, flags); - if (ii_cursor) { - grn_ii_posting *posting; - while ((posting = grn_ii_cursor_next(ctx, ii_cursor))) { - grn_ii_posting adjust_posting; - if (posting->rid != adjust_id) { - continue; - } - adjust_posting.rid = id; - adjust_posting.weight = posting->weight * factor - 1; - grn_ii_posting_add(ctx, &adjust_posting, (grn_hash *)res, op); - } - grn_ii_cursor_close(ctx, ii_cursor); - } - } - grn_table_cursor_close(ctx, table_cursor); - } - grn_obj_unlink(ctx, targets); - - return ctx->rc; -} - grn_rc grn_obj_search(grn_ctx *ctx, grn_obj *obj, grn_obj *query, grn_obj *res, grn_operator op, grn_search_optarg *optarg) @@ -3069,20 +2934,8 @@ grn_obj_search(grn_ctx *ctx, grn_obj *obj, grn_obj *query, const void *key = GRN_BULK_HEAD(query); uint32_t key_size = GRN_BULK_VSIZE(query); grn_operator mode = optarg ? optarg->mode : GRN_OP_EXACT; - if (!key || !key_size) { - return GRN_INVALID_ARGUMENT; - } - rc = grn_table_search(ctx, obj, key, key_size, mode, res, op); - } - break; - case GRN_COLUMN_FIX_SIZE : - case GRN_COLUMN_VAR_SIZE : - { - grn_obj *index; - unsigned int n_indexes; - n_indexes = grn_column_index(ctx, obj, GRN_OP_MATCH, &index, 1, NULL); - if (n_indexes > 0) { - rc = grn_obj_search(ctx, index, query, res, op, optarg); + if (key && key_size) { + rc = grn_table_search(ctx, obj, key, key_size, mode, res, op); } } break; @@ -3090,9 +2943,6 @@ grn_obj_search(grn_ctx *ctx, grn_obj *obj, grn_obj *query, if (GRN_OBJ_INVERTED_INDEX_COLUMNP(obj)) { rc = grn_obj_search_column_inverted_index(ctx, obj, query, res, op, optarg); - } else { - rc = grn_obj_search_column_forward_index(ctx, obj, query, - res, op, optarg); } break; } Modified: lib/expr.c (+16 -10) =================================================================== --- lib/expr.c 2014-02-26 23:03:51 +0900 (5420941) +++ lib/expr.c 2014-03-03 17:37:14 +0900 (7ddcacb) @@ -4426,17 +4426,23 @@ scan_info_build(grn_ctx *ctx, grn_obj *expr, int *n, } break; case GRN_COLUMN_INDEX : - sid = 0; - index = ec->value; - if (j > 2 && - ec[1].value && - ec[1].value->header.domain == GRN_DB_UINT32 && - ec[2].op == GRN_OP_GET_MEMBER) { - sid = GRN_UINT32_VALUE(ec[1].value) + 1; - j -= 2; - ec += 2; + if (GRN_OBJ_FORWARD_INDEX_COLUMNP(ec->value)) { + if (grn_column_index(ctx, ec->value, c->op, &index, 1, &sid)) { + scan_info_put_index(ctx, si, index, sid, get_weight(ctx, ec)); + } + } else { + sid = 0; + index = ec->value; + if (j > 2 && + ec[1].value && + ec[1].value->header.domain == GRN_DB_UINT32 && + ec[2].op == GRN_OP_GET_MEMBER) { + sid = GRN_UINT32_VALUE(ec[1].value) + 1; + j -= 2; + ec += 2; + } + scan_info_put_index(ctx, si, index, sid, get_weight(ctx, ec)); } - scan_info_put_index(ctx, si, index, sid, get_weight(ctx, ec)); break; } } Modified: lib/proc.c (+1 -1) =================================================================== --- lib/proc.c 2014-02-26 23:03:51 +0900 (433d4e1) +++ lib/proc.c 2014-03-03 17:37:14 +0900 (d2c7c53) @@ -500,7 +500,7 @@ grn_select_apply_adjuster_adjust(grn_ctx *ctx, grn_obj *table, grn_obj *res, options.proc = NULL; options.max_size = 0; - grn_obj_search(ctx, column, value, res, GRN_OP_ADJUST, &options); + grn_obj_search(ctx, index, value, res, GRN_OP_ADJUST, &options); } } Modified: test/command/suite/select/adjuster/multiple.expected (+4 -4) =================================================================== --- test/command/suite/select/adjuster/multiple.expected 2014-02-26 23:03:51 +0900 (821d5e4) +++ test/command/suite/select/adjuster/multiple.expected 2014-03-03 17:37:14 +0900 (0f8ce4c) @@ -4,7 +4,7 @@ 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] -column_create Tags memos_tags COLUMN_INDEX Memos tags +column_create Tags memos_tags COLUMN_INDEX|WITH_WEIGHT Memos tags [[0,0.0,0.0],true] load --table Memos [ @@ -53,15 +53,15 @@ select Memos --filter true --adjuster 'tags @ "groonga" * 4 + tags @ "mroong ], [ "Groonga is fast", - 401 + 405 ], [ "Mroonga is also fast", - 341 + 348 ], [ "Ruby is an object oriented script language", - 201 + 203 ] ] ] Modified: test/command/suite/select/adjuster/multiple.test (+1 -1) =================================================================== --- test/command/suite/select/adjuster/multiple.test 2014-02-26 23:03:51 +0900 (ba439b7) +++ test/command/suite/select/adjuster/multiple.test 2014-03-03 17:37:14 +0900 (41c1456) @@ -3,7 +3,7 @@ table_create Tags TABLE_PAT_KEY ShortText table_create Memos TABLE_HASH_KEY ShortText column_create Memos tags COLUMN_INDEX|WITH_WEIGHT Tags -column_create Tags memos_tags COLUMN_INDEX Memos tags +column_create Tags memos_tags COLUMN_INDEX|WITH_WEIGHT Memos tags load --table Memos [ Modified: test/command/suite/select/adjuster/no_factor.expected (+3 -3) =================================================================== --- test/command/suite/select/adjuster/no_factor.expected 2014-02-26 23:03:51 +0900 (88c9d8a) +++ test/command/suite/select/adjuster/no_factor.expected 2014-03-03 17:37:14 +0900 (afe57c5) @@ -4,7 +4,7 @@ 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] -column_create Tags memos_tags COLUMN_INDEX Memos tags +column_create Tags memos_tags COLUMN_INDEX|WITH_WEIGHT Memos tags [[0,0.0,0.0],true] load --table Memos [ @@ -53,11 +53,11 @@ select Memos --filter true --adjuster 'tags @ "groonga" + tags @ "mroonga"' ], [ "Groonga is fast", - 101 + 102 ], [ "Mroonga is also fast", - 111 + 113 ], [ "Ruby is an object oriented script language", Modified: test/command/suite/select/adjuster/no_factor.test (+1 -1) =================================================================== --- test/command/suite/select/adjuster/no_factor.test 2014-02-26 23:03:51 +0900 (84cb8e3) +++ test/command/suite/select/adjuster/no_factor.test 2014-03-03 17:37:14 +0900 (20004c9) @@ -3,7 +3,7 @@ table_create Tags TABLE_PAT_KEY ShortText table_create Memos TABLE_HASH_KEY ShortText column_create Memos tags COLUMN_INDEX|WITH_WEIGHT Tags -column_create Tags memos_tags COLUMN_INDEX Memos tags +column_create Tags memos_tags COLUMN_INDEX|WITH_WEIGHT Memos tags load --table Memos [ Modified: test/command/suite/select/adjuster/not_all_match.expected (+3 -3) =================================================================== --- test/command/suite/select/adjuster/not_all_match.expected 2014-02-26 23:03:51 +0900 (93906f0) +++ test/command/suite/select/adjuster/not_all_match.expected 2014-03-03 17:37:14 +0900 (d2862a4) @@ -4,7 +4,7 @@ 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] -column_create Tags memos_tags COLUMN_INDEX Memos tags +column_create Tags memos_tags COLUMN_INDEX|WITH_WEIGHT Memos tags [[0,0.0,0.0],true] load --table Memos [ @@ -56,11 +56,11 @@ select Memos --filter '_id != 1' --adjuster 'tags @ "groonga" * 1' --outpu ], [ "Groonga is fast", - 101 + 102 ], [ "Mroonga is also fast", - 11 + 12 ], [ "Ruby is an object oriented script language", Modified: test/command/suite/select/adjuster/not_all_match.test (+1 -1) =================================================================== --- test/command/suite/select/adjuster/not_all_match.test 2014-02-26 23:03:51 +0900 (3a3a116) +++ test/command/suite/select/adjuster/not_all_match.test 2014-03-03 17:37:14 +0900 (29730bb) @@ -3,7 +3,7 @@ table_create Tags TABLE_PAT_KEY ShortText table_create Memos TABLE_HASH_KEY ShortText column_create Memos tags COLUMN_INDEX|WITH_WEIGHT Tags -column_create Tags memos_tags COLUMN_INDEX Memos tags +column_create Tags memos_tags COLUMN_INDEX|WITH_WEIGHT Memos tags load --table Memos [ Modified: test/command/suite/select/adjuster/not_forward_index.expected (+1 -1) =================================================================== --- test/command/suite/select/adjuster/not_forward_index.expected 2014-02-26 23:03:51 +0900 (a04d801) +++ test/command/suite/select/adjuster/not_forward_index.expected 2014-03-03 17:37:14 +0900 (38f6d02) @@ -4,7 +4,7 @@ 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] -column_create Tags memos_tags COLUMN_INDEX Memos tags +column_create Tags memos_tags COLUMN_INDEX|WITH_WEIGHT Memos tags [[0,0.0,0.0],true] load --table Memos [ Modified: test/command/suite/select/adjuster/not_forward_index.test (+1 -1) =================================================================== --- test/command/suite/select/adjuster/not_forward_index.test 2014-02-26 23:03:51 +0900 (637b66e) +++ test/command/suite/select/adjuster/not_forward_index.test 2014-03-03 17:37:14 +0900 (69965f9) @@ -3,7 +3,7 @@ table_create Tags TABLE_PAT_KEY ShortText table_create Memos TABLE_HASH_KEY ShortText column_create Memos tags COLUMN_VECTOR Tags -column_create Tags memos_tags COLUMN_INDEX Memos tags +column_create Tags memos_tags COLUMN_INDEX|WITH_WEIGHT Memos tags load --table Memos [ Modified: test/command/suite/select/adjuster/one.expected (+3 -3) =================================================================== --- test/command/suite/select/adjuster/one.expected 2014-02-26 23:03:51 +0900 (74fe1f7) +++ test/command/suite/select/adjuster/one.expected 2014-03-03 17:37:14 +0900 (fcb0f17) @@ -4,7 +4,7 @@ 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] -column_create Tags memos_tags COLUMN_INDEX Memos tags +column_create Tags memos_tags COLUMN_INDEX|WITH_WEIGHT Memos tags [[0,0.0,0.0],true] load --table Memos [ @@ -53,11 +53,11 @@ select Memos --filter true --adjuster 'tags @ "groonga" * 2' --output_colu ], [ "Groonga is fast", - 201 + 203 ], [ "Mroonga is also fast", - 21 + 23 ], [ "Ruby is an object oriented script language", Modified: test/command/suite/select/adjuster/one.test (+1 -1) =================================================================== --- test/command/suite/select/adjuster/one.test 2014-02-26 23:03:51 +0900 (a554cfa) +++ test/command/suite/select/adjuster/one.test 2014-03-03 17:37:14 +0900 (5cc0949) @@ -3,7 +3,7 @@ table_create Tags TABLE_PAT_KEY ShortText table_create Memos TABLE_HASH_KEY ShortText column_create Memos tags COLUMN_INDEX|WITH_WEIGHT Tags -column_create Tags memos_tags COLUMN_INDEX Memos tags +column_create Tags memos_tags COLUMN_INDEX|WITH_WEIGHT Memos tags load --table Memos [ Modified: test/command/suite/select/match_columns/weight/forward_index.expected (+3 -3) =================================================================== --- test/command/suite/select/match_columns/weight/forward_index.expected 2014-02-26 23:03:51 +0900 (571d21d) +++ test/command/suite/select/match_columns/weight/forward_index.expected 2014-03-03 17:37:14 +0900 (062b92a) @@ -4,7 +4,7 @@ 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] -column_create Tags memos_tags COLUMN_INDEX Memos tags +column_create Tags memos_tags COLUMN_INDEX|WITH_WEIGHT Memos tags [[0,0.0,0.0],true] load --table Memos [ @@ -53,11 +53,11 @@ select Memos --match_columns 'tags * 10' --query groonga --output_columns ], [ "Groonga is fast", - 1000 + 1010 ], [ "Mroonga is also fast", - 100 + 110 ] ] ] Modified: test/command/suite/select/match_columns/weight/forward_index.test (+1 -1) =================================================================== --- test/command/suite/select/match_columns/weight/forward_index.test 2014-02-26 23:03:51 +0900 (f8622b1) +++ test/command/suite/select/match_columns/weight/forward_index.test 2014-03-03 17:37:14 +0900 (610ce70) @@ -3,7 +3,7 @@ table_create Tags TABLE_PAT_KEY ShortText table_create Memos TABLE_HASH_KEY ShortText column_create Memos tags COLUMN_INDEX|WITH_WEIGHT Tags -column_create Tags memos_tags COLUMN_INDEX Memos tags +column_create Tags memos_tags COLUMN_INDEX|WITH_WEIGHT Memos tags load --table Memos [ Modified: test/command/suite/select/match_columns/weight/nested_forward_index.expected (+4 -4) =================================================================== --- test/command/suite/select/match_columns/weight/nested_forward_index.expected 2014-02-26 23:03:51 +0900 (74851a1) +++ test/command/suite/select/match_columns/weight/nested_forward_index.expected 2014-03-03 17:37:14 +0900 (9d88186) @@ -4,7 +4,7 @@ table_create Products TABLE_HASH_KEY ShortText [[0,0.0,0.0],true] column_create Products tags COLUMN_INDEX|WITH_WEIGHT Tags [[0,0.0,0.0],true] -column_create Tags products_tags COLUMN_INDEX Products tags +column_create Tags products_tags COLUMN_INDEX|WITH_WEIGHT Products tags [[0,0.0,0.0],true] table_create Programmers TABLE_PAT_KEY ShortText [[0,0.0,0.0],true] @@ -97,15 +97,15 @@ select Programmers --match_columns 'products.tags * 10' --query groonga -- ], [ "daijiro", - 1500 + 1520 ], [ "kou", - 1600 + 1630 ], [ "maruyama", - 500 + 510 ] ] ] Modified: test/command/suite/select/match_columns/weight/nested_forward_index.test (+1 -1) =================================================================== --- test/command/suite/select/match_columns/weight/nested_forward_index.test 2014-02-26 23:03:51 +0900 (fe36617) +++ test/command/suite/select/match_columns/weight/nested_forward_index.test 2014-03-03 17:37:14 +0900 (66ffd0e) @@ -3,7 +3,7 @@ table_create Tags TABLE_PAT_KEY ShortText table_create Products TABLE_HASH_KEY ShortText column_create Products tags COLUMN_INDEX|WITH_WEIGHT Tags -column_create Tags products_tags COLUMN_INDEX Products tags +column_create Tags products_tags COLUMN_INDEX|WITH_WEIGHT Products tags table_create Programmers TABLE_PAT_KEY ShortText column_create Programmers products COLUMN_VECTOR Products Modified: test/command/suite/select/query/forward_index.expected (+3 -3) =================================================================== --- test/command/suite/select/query/forward_index.expected 2014-02-26 23:03:51 +0900 (5101717) +++ test/command/suite/select/query/forward_index.expected 2014-03-03 17:37:14 +0900 (5e79fc4) @@ -4,7 +4,7 @@ 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] -column_create Tags memos_tags COLUMN_INDEX Memos tags +column_create Tags memos_tags COLUMN_INDEX|WITH_WEIGHT Memos tags [[0,0.0,0.0],true] load --table Memos [ @@ -53,11 +53,11 @@ select Memos --match_columns tags --query groonga --output_columns _key,_s ], [ "Groonga is fast", - 100 + 101 ], [ "Mroonga is also fast", - 10 + 11 ] ] ] Modified: test/command/suite/select/query/forward_index.test (+1 -1) =================================================================== --- test/command/suite/select/query/forward_index.test 2014-02-26 23:03:51 +0900 (aed5699) +++ test/command/suite/select/query/forward_index.test 2014-03-03 17:37:14 +0900 (9f2aa9f) @@ -3,7 +3,7 @@ table_create Tags TABLE_PAT_KEY ShortText table_create Memos TABLE_HASH_KEY ShortText column_create Memos tags COLUMN_INDEX|WITH_WEIGHT Tags -column_create Tags memos_tags COLUMN_INDEX Memos tags +column_create Tags memos_tags COLUMN_INDEX|WITH_WEIGHT Memos tags load --table Memos [ -------------- next part -------------- HTML����������������������������... Download