Kouhei Sutou
null+****@clear*****
Wed Nov 18 00:03:49 JST 2015
Kouhei Sutou 2015-11-18 00:03:49 +0900 (Wed, 18 Nov 2015) New Revision: 34cf7c9811865bfbf5eb53071680d76af5c5a60d https://github.com/groonga/groonga/commit/34cf7c9811865bfbf5eb53071680d76af5c5a60d Message: Add prefix_rk_search() selector Added files: 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 files: lib/proc.c Modified: lib/proc.c (+101 -0) =================================================================== --- lib/proc.c 2015-11-17 23:10:41 +0900 (9e2c496) +++ lib/proc.c 2015-11-18 00:03:49 +0900 (1b24f32) @@ -8222,6 +8222,98 @@ proc_reindex(grn_ctx *ctx, int nargs, grn_obj **args, return NULL; } +static grn_rc +selector_prefix_rk_search(grn_ctx *ctx, grn_obj *table, grn_obj *index, + int nargs, grn_obj **args, + grn_obj *res, grn_operator op) +{ + 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, + "prefix_rk_serach(): wrong number of arguments (%d for 2)", nargs - 1); + rc = ctx->rc; + goto exit; + } + + 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) { + 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", + (int)GRN_TEXT_LEN(&inspected_column), + GRN_TEXT_VALUE(&inspected_column)); + rc = ctx->rc; + GRN_OBJ_FIN(ctx, &inspected_column); + 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); + 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)); + rc = ctx->rc; + GRN_OBJ_FIN(ctx, &inspected_index); + GRN_OBJ_FIN(ctx, &inspected_column); + goto exit; + } + + { + grn_table_cursor *cursor; + const void *max = NULL; + unsigned int max_size = 0; + int offset = 0; + int limit = -1; + + cursor = grn_table_cursor_open(ctx, index_lexicon, + GRN_TEXT_VALUE(query), + GRN_TEXT_LEN(query), + max, max_size, + offset, limit, + GRN_CURSOR_PREFIX | GRN_CURSOR_RK); + if (!cursor) { + rc = ctx->rc; + goto exit; + } + { + 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_table_cursor_close(ctx, cursor); + grn_ii_resolve_sel_and(ctx, (grn_hash *)res, op); + } + +exit : + return rc; +} + #define DEF_VAR(v,name_str) do {\ (v).name = (name_str);\ (v).name_size = GRN_STRLEN(name_str);\ @@ -8524,4 +8616,13 @@ grn_db_init_builtin_query(grn_ctx *ctx) DEF_VAR(vars[0], "object"); DEF_COMMAND("reindex", proc_reindex, 1, vars); + + { + grn_obj *selector_proc; + + selector_proc = grn_proc_create(ctx, "prefix_rk_search", -1, + GRN_PROC_FUNCTION, + NULL, NULL, NULL, 0, NULL); + grn_proc_set_selector(ctx, selector_proc, selector_prefix_rk_search); + } } Added: test/command/suite/select/function/prefix_rk_search/hiragana.expected (+49 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/prefix_rk_search/hiragana.expected 2015-11-18 00:03:49 +0900 (84ba3ae) @@ -0,0 +1,49 @@ +table_create Kana 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 +[ +{"_key": "Groonga", "kana": ["グルンガ"]} +] +[[0,0.0,0.0],1] +select Items --filter 'prefix_rk_search(kana, "ぐる")' +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 1 + ], + [ + [ + "_id", + "UInt32" + ], + [ + "_key", + "ShortText" + ], + [ + "kana", + "Kana" + ] + ], + [ + 1, + "Groonga", + [ + "グルンガ" + ] + ] + ] + ] +] Added: test/command/suite/select/function/prefix_rk_search/hiragana.test (+13 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/prefix_rk_search/hiragana.test 2015-11-18 00:03:49 +0900 (1f7f122) @@ -0,0 +1,13 @@ +table_create Kana 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 +[ +{"_key": "Groonga", "kana": ["グルンガ"]} +] + +select Items --filter 'prefix_rk_search(kana, "ぐる")' Added: test/command/suite/select/function/prefix_rk_search/katakana.expected (+49 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/prefix_rk_search/katakana.expected 2015-11-18 00:03:49 +0900 (2c9815a) @@ -0,0 +1,49 @@ +table_create Kana 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 +[ +{"_key": "Groonga", "kana": ["グルンガ"]} +] +[[0,0.0,0.0],1] +select Items --filter 'prefix_rk_search(kana, "グル")' +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 1 + ], + [ + [ + "_id", + "UInt32" + ], + [ + "_key", + "ShortText" + ], + [ + "kana", + "Kana" + ] + ], + [ + 1, + "Groonga", + [ + "グルンガ" + ] + ] + ] + ] +] Added: test/command/suite/select/function/prefix_rk_search/katakana.test (+13 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/prefix_rk_search/katakana.test 2015-11-18 00:03:49 +0900 (5b79a9b) @@ -0,0 +1,13 @@ +table_create Kana 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 +[ +{"_key": "Groonga", "kana": ["グルンガ"]} +] + +select Items --filter 'prefix_rk_search(kana, "グル")' Added: test/command/suite/select/function/prefix_rk_search/romaji.expected (+49 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/prefix_rk_search/romaji.expected 2015-11-18 00:03:49 +0900 (79ba14a) @@ -0,0 +1,49 @@ +table_create Kana 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 +[ +{"_key": "Groonga", "kana": ["グルンガ"]} +] +[[0,0.0,0.0],1] +select Items --filter 'prefix_rk_search(kana, "gur")' +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 1 + ], + [ + [ + "_id", + "UInt32" + ], + [ + "_key", + "ShortText" + ], + [ + "kana", + "Kana" + ] + ], + [ + 1, + "Groonga", + [ + "グルンガ" + ] + ] + ] + ] +] Added: test/command/suite/select/function/prefix_rk_search/romaji.test (+13 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/prefix_rk_search/romaji.test 2015-11-18 00:03:49 +0900 (03c087e) @@ -0,0 +1,13 @@ +table_create Kana 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 +[ +{"_key": "Groonga", "kana": ["グルンガ"]} +] + +select Items --filter 'prefix_rk_search(kana, "gur")' -------------- next part -------------- HTML����������������������������...다운로드