Kouhei Sutou
null+****@clear*****
Wed Feb 11 18:32:09 JST 2015
Kouhei Sutou 2015-02-11 18:32:09 +0900 (Wed, 11 Feb 2015) New Revision: 553dfb87c255015aae3a4d0c25d8abc6e04190b3 https://github.com/groonga/groonga/commit/553dfb87c255015aae3a4d0c25d8abc6e04190b3 Message: Support range search by nested multi-column index Added files: test/command/suite/select/index/multi_column/range/accessor.expected test/command/suite/select/index/multi_column/range/accessor.test Modified files: lib/expr.c Modified: lib/expr.c (+30 -3) =================================================================== --- lib/expr.c 2015-02-11 18:06:40 +0900 (28887aa) +++ lib/expr.c 2015-02-11 18:32:09 +0900 (d7b2478) @@ -4852,11 +4852,21 @@ grn_table_select_index_range_accessor(grn_ctx *ctx, grn_obj *table, { int i; + grn_obj weight_vector; + grn_search_optarg optarg; + GRN_INT32_INIT(&weight_vector, GRN_OBJ_VECTOR); + memset(&optarg, 0, sizeof(grn_search_optarg)); + if (si->op == GRN_OP_MATCH) { + optarg.mode = GRN_OP_EXACT; + } else { + optarg.mode = si->op; + } for (i = n_accessors - 1; i > 0; i--) { grn_rc rc = GRN_SUCCESS; grn_accessor *accessor; grn_obj *index; + int section; grn_obj *domain; grn_obj *target; grn_obj *next_res; @@ -4865,12 +4875,28 @@ grn_table_select_index_range_accessor(grn_ctx *ctx, grn_obj *table, accessor = (grn_accessor *)GRN_PTR_VALUE_AT(accessor_stack, i - 1); target = accessor->obj; - if (grn_column_index(ctx, target, GRN_OP_EQUAL, &index, 1, NULL) == 0) { + if (grn_column_index(ctx, target, GRN_OP_EQUAL, &index, 1, §ion) == 0) { grn_obj_unlink(ctx, current_res); current_res = NULL; break; } + if (section) { + int j; + int weight_position = section - 1; + + GRN_BULK_REWIND(&weight_vector); + GRN_INT32_SET_AT(ctx, &weight_vector, weight_position, 1); + optarg.weight_vector = &(GRN_INT32_VALUE(&weight_vector)); + optarg.vector_size = GRN_BULK_VSIZE(&weight_vector) / sizeof(int32_t); + for (j = 0; j < weight_position - 1; j++) { + optarg.weight_vector[j] = 0; + } + } else { + optarg.weight_vector = NULL; + optarg.vector_size = 1; + } + { grn_obj *range; range = grn_ctx_at(ctx, DB_OBJ(index)->range); @@ -4893,14 +4919,14 @@ grn_table_select_index_range_accessor(grn_ctx *ctx, grn_obj *table, if (domain->header.type == GRN_TABLE_NO_KEY) { rc = grn_ii_sel(ctx, (grn_ii *)index, (const char *)next_record_id, sizeof(grn_id), - (grn_hash *)next_res, next_op, NULL); + (grn_hash *)next_res, next_op, &optarg); } else { char key[GRN_TABLE_MAX_KEY_SIZE]; int key_len; key_len = grn_table_get_key(ctx, domain, *next_record_id, key, GRN_TABLE_MAX_KEY_SIZE); rc = grn_ii_sel(ctx, (grn_ii *)index, key, key_len, - (grn_hash *)next_res, next_op, NULL); + (grn_hash *)next_res, next_op, &optarg); } if (rc != GRN_SUCCESS) { break; @@ -4925,6 +4951,7 @@ grn_table_select_index_range_accessor(grn_ctx *ctx, grn_obj *table, break; } } + GRN_OBJ_FIN(ctx, &weight_vector); } return current_res == res; Added: test/command/suite/select/index/multi_column/range/accessor.expected (+90 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/index/multi_column/range/accessor.expected 2015-02-11 18:32:09 +0900 (fe7f6ea) @@ -0,0 +1,90 @@ +table_create Numbers TABLE_PAT_KEY Int32 +[[0,0.0,0.0],true] +table_create Pairs TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +column_create Pairs number1 COLUMN_SCALAR Int32 +[[0,0.0,0.0],true] +column_create Pairs number2 COLUMN_SCALAR Int32 +[[0,0.0,0.0],true] +column_create Numbers pairs COLUMN_INDEX|WITH_SECTION Pairs number1,number2 +[[0,0.0,0.0],true] +table_create Memos TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +column_create Memos pair1 COLUMN_SCALAR Pairs +[[0,0.0,0.0],true] +column_create Memos pair2 COLUMN_SCALAR Pairs +[[0,0.0,0.0],true] +column_create Pairs memos COLUMN_INDEX|WITH_SECTION Memos pair1,pair2 +[[0,0.0,0.0],true] +load --table Pairs +[ + { + "_key": "2-30", + "number1": 2, + "number2": 30 + }, + { + "_key": "3-10", + "number1": 3, + "number2": 10 + }, + { + "_key": "1-20", + "number1": 1, + "number2": 20 + } +] +[[0,0.0,0.0],3] +load --table Memos +[ + { + "_key": "300", + "pair1": "1-20", + "pair2": "2-30" + }, + { + "_key": "200", + "pair1": "3-10", + "pair2": "1-20" + }, + { + "_key": "100", + "pair1": "2-30", + "pair2": "3-10" + } +] +[[0,0.0,0.0],3] +select Memos --filter 'pair2.number1 >= 2 && pair2.number2 >= 20' --output_columns '_key,pair1,pair2' +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 1 + ], + [ + [ + "_key", + "ShortText" + ], + [ + "pair1", + "Pairs" + ], + [ + "pair2", + "Pairs" + ] + ], + [ + "300", + "1-20", + "2-30" + ] + ] + ] +] Added: test/command/suite/select/index/multi_column/range/accessor.test (+59 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/index/multi_column/range/accessor.test 2015-02-11 18:32:09 +0900 (071b164) @@ -0,0 +1,59 @@ +table_create Numbers TABLE_PAT_KEY Int32 + +table_create Pairs TABLE_HASH_KEY ShortText +column_create Pairs number1 COLUMN_SCALAR Int32 +column_create Pairs number2 COLUMN_SCALAR Int32 + +column_create Numbers pairs \ + COLUMN_INDEX|WITH_SECTION \ + Pairs number1,number2 + +table_create Memos TABLE_HASH_KEY ShortText +column_create Memos pair1 COLUMN_SCALAR Pairs +column_create Memos pair2 COLUMN_SCALAR Pairs + +column_create Pairs memos \ + COLUMN_INDEX|WITH_SECTION \ + Memos pair1,pair2 + +load --table Pairs +[ + { + "_key": "2-30", + "number1": 2, + "number2": 30 + }, + { + "_key": "3-10", + "number1": 3, + "number2": 10 + }, + { + "_key": "1-20", + "number1": 1, + "number2": 20 + } +] + +load --table Memos +[ + { + "_key": "300", + "pair1": "1-20", + "pair2": "2-30" + }, + { + "_key": "200", + "pair1": "3-10", + "pair2": "1-20" + }, + { + "_key": "100", + "pair1": "2-30", + "pair2": "3-10" + } +] + +select Memos \ + --filter 'pair2.number1 >= 2 && pair2.number2 >= 20' \ + --output_columns '_key,pair1,pair2' -------------- next part -------------- HTML����������������������������... Download