Kouhei Sutou
null+****@clear*****
Tue May 10 14:11:21 JST 2016
Kouhei Sutou 2016-05-10 14:11:21 +0900 (Tue, 10 May 2016) New Revision: e48544dcd166935253d38e29bbf039b3d27f004c https://github.com/groonga/groonga/commit/e48544dcd166935253d38e29bbf039b3d27f004c Message: Share common code to grn_accessor_resolve() Modified files: lib/db.c lib/grn_db.h lib/proc.c Modified: lib/db.c (+15 -21) =================================================================== --- lib/db.c 2016-05-10 13:37:42 +0900 (4a3ffe1) +++ lib/db.c 2016-05-10 14:11:21 +0900 (2bf3172) @@ -3233,7 +3233,8 @@ grn_accessor_resolve_one_data_column(grn_ctx *ctx, grn_accessor *accessor, grn_rc grn_accessor_resolve(grn_ctx *ctx, grn_obj *accessor, int deep, - grn_obj *base_res, grn_obj **res) + grn_obj *base_res, grn_obj *res, + grn_operator op) { grn_rc rc = GRN_SUCCESS; grn_accessor *a; @@ -3278,9 +3279,19 @@ grn_accessor_resolve(grn_ctx *ctx, grn_obj *accessor, int deep, } if (rc == GRN_SUCCESS && current_res != base_res) { - *res = current_res; + grn_id *record_id; + grn_rset_recinfo *recinfo; + GRN_HASH_EACH(ctx, (grn_hash *)current_res, id, &record_id, NULL, &recinfo, { + grn_posting posting; + posting.rid = *record_id; + posting.sid = 1; + posting.pos = 0; + posting.weight = recinfo->score - 1; + grn_ii_posting_add(ctx, &posting, (grn_hash *)res, op); + }); + grn_obj_unlink(ctx, current_res); + grn_ii_resolve_sel_and(ctx, (grn_hash *)res, op); } else { - *res = NULL; if (rc == GRN_SUCCESS) { rc = GRN_INVALID_ARGUMENT; } @@ -3333,7 +3344,6 @@ grn_obj_search_accessor(grn_ctx *ctx, grn_obj *obj, grn_obj *query, rc = grn_obj_search(ctx, index, query, res, op, optarg); } else { grn_obj *base_res; - grn_obj *resolve_res = NULL; grn_obj *range = grn_ctx_at(ctx, DB_OBJ(index)->range); base_res = grn_table_create(ctx, NULL, 0, NULL, GRN_TABLE_HASH_KEY|GRN_OBJ_WITH_SUBREC, @@ -3349,23 +3359,7 @@ grn_obj_search_accessor(grn_ctx *ctx, grn_obj *obj, grn_obj *query, grn_obj_unlink(ctx, base_res); goto exit; } - rc = grn_accessor_resolve(ctx, obj, n_accessors - 1, base_res, - &resolve_res); - if (resolve_res) { - grn_id *record_id; - grn_rset_recinfo *recinfo; - GRN_HASH_EACH(ctx, (grn_hash *)resolve_res, id, &record_id, NULL, - &recinfo, { - grn_posting posting; - posting.rid = *record_id; - posting.sid = 1; - posting.pos = 0; - posting.weight = recinfo->score - 1; - grn_ii_posting_add(ctx, &posting, (grn_hash *)res, op); - }); - grn_ii_resolve_sel_and(ctx, (grn_hash *)res, op); - grn_obj_unlink(ctx, resolve_res); - } + rc = grn_accessor_resolve(ctx, obj, n_accessors - 1, base_res, res, op); grn_obj_unlink(ctx, base_res); } } Modified: lib/grn_db.h (+6 -2) =================================================================== --- lib/grn_db.h 2016-05-10 13:37:42 +0900 (f34023a) +++ lib/grn_db.h 2016-05-10 14:11:21 +0900 (b503608) @@ -432,8 +432,12 @@ GRN_API grn_rc grn_column_filter(grn_ctx *ctx, grn_obj *column, grn_obj *value, grn_obj *result_set, grn_operator set_op); -grn_rc grn_accessor_resolve(grn_ctx *ctx, grn_obj *accessor, int deep, - grn_obj *base_res, grn_obj **res); +grn_rc grn_accessor_resolve(grn_ctx *ctx, + grn_obj *accessor, + int deep, + grn_obj *base_res, + grn_obj *res, + grn_operator op); typedef struct { grn_id target; Modified: lib/proc.c (+2 -7) =================================================================== --- lib/proc.c 2016-05-10 13:37:42 +0900 (7978f6e) +++ lib/proc.c 2016-05-10 14:11:21 +0900 (e9e6d6f) @@ -2609,14 +2609,13 @@ run_sub_filter(grn_ctx *ctx, grn_obj *table, { grn_obj *base_res = NULL; - grn_obj *resolve_res = NULL; base_res = grn_table_create(ctx, NULL, 0, NULL, GRN_TABLE_HASH_KEY|GRN_OBJ_WITH_SUBREC, scope_domain, NULL); grn_table_select(ctx, scope_domain, sub_filter, base_res, GRN_OP_OR); if (scope->header.type == GRN_ACCESSOR) { - rc = grn_accessor_resolve(ctx, scope, -1, base_res, &resolve_res); + rc = grn_accessor_resolve(ctx, scope, -1, base_res, res, op); } else { grn_accessor accessor; accessor.header.type = GRN_ACCESSOR; @@ -2624,11 +2623,7 @@ run_sub_filter(grn_ctx *ctx, grn_obj *table, accessor.action = GRN_ACCESSOR_GET_COLUMN_VALUE; accessor.next = NULL; rc = grn_accessor_resolve(ctx, (grn_obj *)&accessor, -1, base_res, - &resolve_res); - } - if (resolve_res) { - rc = grn_table_setoperation(ctx, res, resolve_res, res, op); - grn_obj_unlink(ctx, resolve_res); + res, op); } grn_obj_unlink(ctx, base_res); } -------------- next part -------------- HTML����������������������������...下载