Kouhei Sutou
null+****@clear*****
Wed Nov 18 13:03:44 JST 2015
Kouhei Sutou 2015-11-18 13:03:44 +0900 (Wed, 18 Nov 2015) New Revision: b6944faa2f1fc8e4eff07de1449a287c897f80b8 https://github.com/groonga/groonga/commit/b6944faa2f1fc8e4eff07de1449a287c897f80b8 Message: prefix_rk_search: stop index resolving It should be done by sub_filter. Added files: test/command/suite/select/function/sub_filter/complete/rk_only.test test/command/suite/select/function/sub_filter/complete/rk_or_prefix.expected test/command/suite/select/function/sub_filter/complete/rk_or_prefix.test Copied files: test/command/suite/select/function/sub_filter/complete/rk_only.expected (from test/command/suite/select/function/prefix_rk_search/romaji.expected) Modified files: lib/proc.c test/command/suite/select/function/prefix_rk_search/hiragana.expected test/command/suite/select/function/prefix_rk_search/hiragana.test test/command/suite/select/function/prefix_rk_search/katakana.expected test/command/suite/select/function/prefix_rk_search/katakana.test test/command/suite/select/function/prefix_rk_search/romaji.expected test/command/suite/select/function/prefix_rk_search/romaji.test Modified: lib/proc.c (+17 -28) =================================================================== --- lib/proc.c 2015-11-18 12:16:09 +0900 (1b24f32) +++ lib/proc.c 2015-11-18 13:03:44 +0900 (082d66d) @@ -8230,9 +8230,6 @@ selector_prefix_rk_search(grn_ctx *ctx, grn_obj *table, grn_obj *index, grn_rc rc = GRN_SUCCESS; grn_obj *column; grn_obj *query; - grn_index_datum index_datum; - unsigned int n_indexes; - grn_obj *index_lexicon; if ((nargs - 1) != 2) { ERR(GRN_INVALID_ARGUMENT, @@ -8244,14 +8241,12 @@ selector_prefix_rk_search(grn_ctx *ctx, grn_obj *table, grn_obj *index, column = args[1]; query = args[2]; - n_indexes = grn_column_find_index_data(ctx, column, GRN_OP_PREFIX, - &index_datum, 1); - if (n_indexes == 0) { + if (!grn_obj_is_key_accessor(ctx, column)) { grn_obj inspected_column; GRN_TEXT_INIT(&inspected_column, 0); grn_inspect(ctx, &inspected_column, column); ERR(GRN_INVALID_ARGUMENT, - "prefix_rk_serach(): column doesn't have index for prefix search: %.*s", + "prefix_rk_serach(): column must be _key: %.*s", (int)GRN_TEXT_LEN(&inspected_column), GRN_TEXT_VALUE(&inspected_column)); rc = ctx->rc; @@ -8259,24 +8254,16 @@ selector_prefix_rk_search(grn_ctx *ctx, grn_obj *table, grn_obj *index, goto exit; } - index = index_datum.index; - index_lexicon = grn_ctx_at(ctx, index->header.domain); - if (index_lexicon->header.type != GRN_TABLE_PAT_KEY) { - grn_obj inspected_index; - grn_obj inspected_column; - GRN_TEXT_INIT(&inspected_index, 0); - GRN_TEXT_INIT(&inspected_column, 0); - grn_inspect(ctx, &inspected_index, index); - grn_inspect(ctx, &inspected_column, column); + if (table->header.type != GRN_TABLE_PAT_KEY) { + grn_obj inspected_table; + GRN_TEXT_INIT(&inspected_table, 0); + grn_inspect(ctx, &inspected_table, table); ERR(GRN_INVALID_ARGUMENT, - "prefix_rk_serach(): index lexicon must TABLE_PAT_KEY: %.*s: %.*s", - (int)GRN_TEXT_LEN(&inspected_index), - GRN_TEXT_VALUE(&inspected_index), - (int)GRN_TEXT_LEN(&inspected_column), - GRN_TEXT_VALUE(&inspected_column)); + "prefix_rk_serach(): table of _key must TABLE_PAT_KEY: %.*s", + (int)GRN_TEXT_LEN(&inspected_table), + GRN_TEXT_VALUE(&inspected_table)); rc = ctx->rc; - GRN_OBJ_FIN(ctx, &inspected_index); - GRN_OBJ_FIN(ctx, &inspected_column); + GRN_OBJ_FIN(ctx, &inspected_table); goto exit; } @@ -8287,7 +8274,7 @@ selector_prefix_rk_search(grn_ctx *ctx, grn_obj *table, grn_obj *index, int offset = 0; int limit = -1; - cursor = grn_table_cursor_open(ctx, index_lexicon, + cursor = grn_table_cursor_open(ctx, table, GRN_TEXT_VALUE(query), GRN_TEXT_LEN(query), max, max_size, @@ -8300,10 +8287,12 @@ selector_prefix_rk_search(grn_ctx *ctx, grn_obj *table, grn_obj *index, { grn_id record_id; while ((record_id = grn_table_cursor_next(ctx, cursor)) != GRN_ID_NIL) { - rc = grn_ii_at(ctx, (grn_ii *)index, record_id, (grn_hash *)res, op); - if (rc != GRN_SUCCESS) { - break; - } + grn_posting posting; + posting.rid = record_id; + posting.sid = 1; + posting.pos = 0; + posting.weight = 0; + grn_ii_posting_add(ctx, &posting, (grn_hash *)res, op); } } grn_table_cursor_close(ctx, cursor); Modified: test/command/suite/select/function/prefix_rk_search/hiragana.expected (+5 -18) =================================================================== --- test/command/suite/select/function/prefix_rk_search/hiragana.expected 2015-11-18 12:16:09 +0900 (84ba3ae) +++ test/command/suite/select/function/prefix_rk_search/hiragana.expected 2015-11-18 13:03:44 +0900 (0f03de2) @@ -1,17 +1,11 @@ -table_create Kana TABLE_PAT_KEY ShortText --normalizer NormalizerAuto +table_create Readings TABLE_PAT_KEY ShortText --normalizer NormalizerAuto [[0,0.0,0.0],true] -table_create Items TABLE_HASH_KEY ShortText -[[0,0.0,0.0],true] -column_create Items kana COLUMN_VECTOR Kana -[[0,0.0,0.0],true] -column_create Kana items COLUMN_INDEX Items kana -[[0,0.0,0.0],true] -load --table Items +load --table Readings [ -{"_key": "Groonga", "kana": ["グルンガ"]} +{"_key": "グルンガ"} ] [[0,0.0,0.0],1] -select Items --filter 'prefix_rk_search(kana, "ぐる")' +select Readings --filter 'prefix_rk_search(_key, "ぐる")' [ [ 0, @@ -31,18 +25,11 @@ select Items --filter 'prefix_rk_search(kana, "ぐる")' [ "_key", "ShortText" - ], - [ - "kana", - "Kana" ] ], [ 1, - "Groonga", - [ - "グルンガ" - ] + "グルンガ" ] ] ] Modified: test/command/suite/select/function/prefix_rk_search/hiragana.test (+4 -9) =================================================================== --- test/command/suite/select/function/prefix_rk_search/hiragana.test 2015-11-18 12:16:09 +0900 (1f7f122) +++ test/command/suite/select/function/prefix_rk_search/hiragana.test 2015-11-18 13:03:44 +0900 (b7c5567) @@ -1,13 +1,8 @@ -table_create Kana TABLE_PAT_KEY ShortText --normalizer NormalizerAuto +table_create Readings TABLE_PAT_KEY ShortText --normalizer NormalizerAuto -table_create Items TABLE_HASH_KEY ShortText -column_create Items kana COLUMN_VECTOR Kana - -column_create Kana items COLUMN_INDEX Items kana - -load --table Items +load --table Readings [ -{"_key": "Groonga", "kana": ["グルンガ"]} +{"_key": "グルンガ"} ] -select Items --filter 'prefix_rk_search(kana, "ぐる")' +select Readings --filter 'prefix_rk_search(_key, "ぐる")' Modified: test/command/suite/select/function/prefix_rk_search/katakana.expected (+5 -18) =================================================================== --- test/command/suite/select/function/prefix_rk_search/katakana.expected 2015-11-18 12:16:09 +0900 (2c9815a) +++ test/command/suite/select/function/prefix_rk_search/katakana.expected 2015-11-18 13:03:44 +0900 (bf18b29) @@ -1,17 +1,11 @@ -table_create Kana TABLE_PAT_KEY ShortText --normalizer NormalizerAuto +table_create Readings TABLE_PAT_KEY ShortText --normalizer NormalizerAuto [[0,0.0,0.0],true] -table_create Items TABLE_HASH_KEY ShortText -[[0,0.0,0.0],true] -column_create Items kana COLUMN_VECTOR Kana -[[0,0.0,0.0],true] -column_create Kana items COLUMN_INDEX Items kana -[[0,0.0,0.0],true] -load --table Items +load --table Readings [ -{"_key": "Groonga", "kana": ["グルンガ"]} +{"_key": "グルンガ"} ] [[0,0.0,0.0],1] -select Items --filter 'prefix_rk_search(kana, "グル")' +select Readings --filter 'prefix_rk_search(_key, "グル")' [ [ 0, @@ -31,18 +25,11 @@ select Items --filter 'prefix_rk_search(kana, "グル")' [ "_key", "ShortText" - ], - [ - "kana", - "Kana" ] ], [ 1, - "Groonga", - [ - "グルンガ" - ] + "グルンガ" ] ] ] Modified: test/command/suite/select/function/prefix_rk_search/katakana.test (+4 -9) =================================================================== --- test/command/suite/select/function/prefix_rk_search/katakana.test 2015-11-18 12:16:09 +0900 (5b79a9b) +++ test/command/suite/select/function/prefix_rk_search/katakana.test 2015-11-18 13:03:44 +0900 (6754e0f) @@ -1,13 +1,8 @@ -table_create Kana TABLE_PAT_KEY ShortText --normalizer NormalizerAuto +table_create Readings TABLE_PAT_KEY ShortText --normalizer NormalizerAuto -table_create Items TABLE_HASH_KEY ShortText -column_create Items kana COLUMN_VECTOR Kana - -column_create Kana items COLUMN_INDEX Items kana - -load --table Items +load --table Readings [ -{"_key": "Groonga", "kana": ["グルンガ"]} +{"_key": "グルンガ"} ] -select Items --filter 'prefix_rk_search(kana, "グル")' +select Readings --filter 'prefix_rk_search(_key, "グル")' Modified: test/command/suite/select/function/prefix_rk_search/romaji.expected (+5 -18) =================================================================== --- test/command/suite/select/function/prefix_rk_search/romaji.expected 2015-11-18 12:16:09 +0900 (79ba14a) +++ test/command/suite/select/function/prefix_rk_search/romaji.expected 2015-11-18 13:03:44 +0900 (0359a89) @@ -1,17 +1,11 @@ -table_create Kana TABLE_PAT_KEY ShortText --normalizer NormalizerAuto +table_create Readings TABLE_PAT_KEY ShortText --normalizer NormalizerAuto [[0,0.0,0.0],true] -table_create Items TABLE_HASH_KEY ShortText -[[0,0.0,0.0],true] -column_create Items kana COLUMN_VECTOR Kana -[[0,0.0,0.0],true] -column_create Kana items COLUMN_INDEX Items kana -[[0,0.0,0.0],true] -load --table Items +load --table Readings [ -{"_key": "Groonga", "kana": ["グルンガ"]} +{"_key": "グルンガ"} ] [[0,0.0,0.0],1] -select Items --filter 'prefix_rk_search(kana, "gur")' +select Readings --filter 'prefix_rk_search(_key, "gur")' [ [ 0, @@ -31,18 +25,11 @@ select Items --filter 'prefix_rk_search(kana, "gur")' [ "_key", "ShortText" - ], - [ - "kana", - "Kana" ] ], [ 1, - "Groonga", - [ - "グルンガ" - ] + "グルンガ" ] ] ] Modified: test/command/suite/select/function/prefix_rk_search/romaji.test (+4 -9) =================================================================== --- test/command/suite/select/function/prefix_rk_search/romaji.test 2015-11-18 12:16:09 +0900 (03c087e) +++ test/command/suite/select/function/prefix_rk_search/romaji.test 2015-11-18 13:03:44 +0900 (39db7fa) @@ -1,13 +1,8 @@ -table_create Kana TABLE_PAT_KEY ShortText --normalizer NormalizerAuto +table_create Readings TABLE_PAT_KEY ShortText --normalizer NormalizerAuto -table_create Items TABLE_HASH_KEY ShortText -column_create Items kana COLUMN_VECTOR Kana - -column_create Kana items COLUMN_INDEX Items kana - -load --table Items +load --table Readings [ -{"_key": "Groonga", "kana": ["グルンガ"]} +{"_key": "グルンガ"} ] -select Items --filter 'prefix_rk_search(kana, "gur")' +select Readings --filter 'prefix_rk_search(_key, "gur")' Copied: test/command/suite/select/function/sub_filter/complete/rk_only.expected (+7 -7) 57% =================================================================== --- test/command/suite/select/function/prefix_rk_search/romaji.expected 2015-11-18 12:16:09 +0900 (79ba14a) +++ test/command/suite/select/function/sub_filter/complete/rk_only.expected 2015-11-18 13:03:44 +0900 (36516e1) @@ -1,17 +1,17 @@ -table_create Kana TABLE_PAT_KEY ShortText --normalizer NormalizerAuto +table_create Readings TABLE_PAT_KEY ShortText --normalizer NormalizerAuto [[0,0.0,0.0],true] table_create Items TABLE_HASH_KEY ShortText [[0,0.0,0.0],true] -column_create Items kana COLUMN_VECTOR Kana +column_create Items readings COLUMN_VECTOR Readings [[0,0.0,0.0],true] -column_create Kana items COLUMN_INDEX Items kana +column_create Readings items_index COLUMN_INDEX Items readings [[0,0.0,0.0],true] load --table Items [ -{"_key": "Groonga", "kana": ["グルンガ"]} +{"_key": "Groonga", "readings": ["グルンガ"]} ] [[0,0.0,0.0],1] -select Items --filter 'prefix_rk_search(kana, "gur")' +select Items --filter 'sub_filter(readings, "prefix_rk_search(_key, \\"guru\\")")' [ [ 0, @@ -33,8 +33,8 @@ select Items --filter 'prefix_rk_search(kana, "gur")' "ShortText" ], [ - "kana", - "Kana" + "readings", + "Readings" ] ], [ Added: test/command/suite/select/function/sub_filter/complete/rk_only.test (+14 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/sub_filter/complete/rk_only.test 2015-11-18 13:03:44 +0900 (2835799) @@ -0,0 +1,14 @@ +table_create Readings TABLE_PAT_KEY ShortText --normalizer NormalizerAuto + +table_create Items TABLE_HASH_KEY ShortText +column_create Items readings COLUMN_VECTOR Readings + +column_create Readings items_index COLUMN_INDEX Items readings + +load --table Items +[ +{"_key": "Groonga", "readings": ["グルンガ"]} +] + +select Items \ + --filter 'sub_filter(readings, "prefix_rk_search(_key, \\"guru\\")")' Added: test/command/suite/select/function/sub_filter/complete/rk_or_prefix.expected (+50 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/sub_filter/complete/rk_or_prefix.expected 2015-11-18 13:03:44 +0900 (1c8a293) @@ -0,0 +1,50 @@ +table_create Readings TABLE_PAT_KEY ShortText --normalizer NormalizerAuto +[[0,0.0,0.0],true] +table_create Items TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +column_create Items readings COLUMN_VECTOR Readings +[[0,0.0,0.0],true] +column_create Readings items_index COLUMN_INDEX Items readings +[[0,0.0,0.0],true] +load --table Items +[ +{"_key": "Groonga", "readings": ["グルンガ", "Groonga"]} +] +[[0,0.0,0.0],1] +select Items --filter 'sub_filter(readings, "prefix_rk_search(_key, \\"gro\\") || _key @^ \\"gro\\"")' +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 1 + ], + [ + [ + "_id", + "UInt32" + ], + [ + "_key", + "ShortText" + ], + [ + "readings", + "Readings" + ] + ], + [ + 1, + "Groonga", + [ + "グルンガ", + "groonga" + ] + ] + ] + ] +] Added: test/command/suite/select/function/sub_filter/complete/rk_or_prefix.test (+16 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/sub_filter/complete/rk_or_prefix.test 2015-11-18 13:03:44 +0900 (2ac8989) @@ -0,0 +1,16 @@ +table_create Readings TABLE_PAT_KEY ShortText --normalizer NormalizerAuto + +table_create Items TABLE_HASH_KEY ShortText +column_create Items readings COLUMN_VECTOR Readings + +column_create Readings items_index COLUMN_INDEX Items readings + +load --table Items +[ +{"_key": "Groonga", "readings": ["グルンガ", "Groonga"]} +] + +select Items \ + --filter 'sub_filter(readings, \ + "prefix_rk_search(_key, \\"gro\\") || \ + _key @^ \\"gro\\"")' -------------- next part -------------- HTML����������������������������...Download