Kouhei Sutou
null+****@clear*****
Wed Jun 15 15:05:43 JST 2016
Kouhei Sutou 2016-06-15 15:05:43 +0900 (Wed, 15 Jun 2016) New Revision: f31c7bb6b06589069d00c79f2952f65ad9042f28 https://github.com/groonga/groonga/commit/f31c7bb6b06589069d00c79f2952f65ad9042f28 Message: query_expand: add a new command TODO: Document me. Added files: test/command/suite/query_expand/invalid/nonexistent_expander.expected test/command/suite/query_expand/invalid/nonexistent_expander.test test/command/suite/query_expand/invalid/nonexistent_flags.expected test/command/suite/query_expand/invalid/nonexistent_flags.test test/command/suite/query_expand/proc.expected test/command/suite/query_expand/proc.test Modified files: lib/grn_proc.h lib/proc.c lib/proc/proc_select.c lib/proc/sources.am Modified: lib/grn_proc.h (+6 -0) =================================================================== --- lib/grn_proc.h 2016-06-15 15:05:14 +0900 (d91043f) +++ lib/grn_proc.h 2016-06-15 15:05:43 +0900 (3f3bd37) @@ -55,6 +55,7 @@ void grn_proc_init_lock_release(grn_ctx *ctx); void grn_proc_init_object_exist(grn_ctx *ctx); void grn_proc_init_object_inspect(grn_ctx *ctx); void grn_proc_init_object_remove(grn_ctx *ctx); +void grn_proc_init_query_expand(grn_ctx *ctx); void grn_proc_init_schema(grn_ctx *ctx); void grn_proc_init_select(grn_ctx *ctx); void grn_proc_init_snippet(grn_ctx *ctx); @@ -119,6 +120,11 @@ grn_rc grn_proc_syntax_expand_query(grn_ctx *ctx, grn_obj *expanded_query, const char *error_message_tag); +grn_expr_flags grn_proc_expr_query_flags_parse(grn_ctx *ctx, + const char *query_flags, + size_t query_flags_size, + const char *error_message_tag); + #ifdef __cplusplus } #endif Modified: lib/proc.c (+2 -0) =================================================================== --- lib/proc.c 2016-06-15 15:05:14 +0900 (0f27426) +++ lib/proc.c 2016-06-15 15:05:43 +0900 (7f8548e) @@ -4335,4 +4335,6 @@ grn_db_init_builtin_commands(grn_ctx *ctx) grn_proc_init_snippet(ctx); grn_proc_init_highlight(ctx); + + grn_proc_init_query_expand(ctx); } Modified: lib/proc/proc_select.c (+22 -15) =================================================================== --- lib/proc/proc_select.c 2016-06-15 15:05:14 +0900 (1e7af24) +++ lib/proc/proc_select.c 2016-06-15 15:05:43 +0900 (0ef74d1) @@ -732,12 +732,14 @@ grn_drilldown_data_fill(grn_ctx *ctx, GRN_SELECT_FILL_STRING(drilldown->table_name, table); } -static grn_expr_flags -grn_parse_query_flags(grn_ctx *ctx, const char *query_flags, - unsigned int query_flags_len) +grn_expr_flags +grn_proc_expr_query_flags_parse(grn_ctx *ctx, + const char *query_flags, + size_t query_flags_size, + const char *error_message_tag) { grn_expr_flags flags = 0; - const char *query_flags_end = query_flags + query_flags_len; + const char *query_flags_end = query_flags + query_flags_size; while (query_flags < query_flags_end) { if (*query_flags == '|' || *query_flags == ' ') { @@ -745,13 +747,16 @@ grn_parse_query_flags(grn_ctx *ctx, const char *query_flags, continue; } -#define CHECK_EXPR_FLAG(name)\ - if (((query_flags_end - query_flags) >= (sizeof(#name) - 1)) &&\ - (!memcmp(query_flags, #name, sizeof(#name) - 1))) {\ - flags |= GRN_EXPR_ ## name;\ - query_flags += sizeof(#name) - 1;\ - continue;\ - } +#define CHECK_EXPR_FLAG(name) \ + if (((query_flags_end - query_flags) >= (sizeof(#name) - 1)) && \ + (memcmp(query_flags, #name, sizeof(#name) - 1) == 0) && \ + (((query_flags_end - query_flags) == (sizeof(#name) - 1)) || \ + (query_flags[sizeof(#name) - 1] == '|') || \ + (query_flags[sizeof(#name) - 1] == ' '))) { \ + flags |= GRN_EXPR_ ## name; \ + query_flags += sizeof(#name) - 1; \ + continue; \ + } CHECK_EXPR_FLAG(ALLOW_PRAGMA); CHECK_EXPR_FLAG(ALLOW_COLUMN); @@ -763,7 +768,8 @@ grn_parse_query_flags(grn_ctx *ctx, const char *query_flags, #undef GNR_EXPR_NONE GRN_PLUGIN_ERROR(ctx, GRN_INVALID_ARGUMENT, - "invalid query flag: <%.*s>", + "%s invalid query flag: <%.*s>", + error_message_tag, (int)(query_flags_end - query_flags), query_flags); return 0; @@ -1171,9 +1177,10 @@ grn_select_filter(grn_ctx *ctx, flags = GRN_EXPR_SYNTAX_QUERY; if (data->query_flags.length) { - flags |= grn_parse_query_flags(ctx, - data->query_flags.value, - data->query_flags.length); + flags |= grn_proc_expr_query_flags_parse(ctx, + data->query_flags.value, + data->query_flags.length, + "[select]"); if (ctx->rc) { return GRN_FALSE; } Modified: lib/proc/sources.am (+1 -0) =================================================================== --- lib/proc/sources.am 2016-06-15 15:05:14 +0900 (f0f88b1) +++ lib/proc/sources.am 2016-06-15 15:05:43 +0900 (83045e9) @@ -5,6 +5,7 @@ libgrnproc_la_SOURCES = \ proc_lock.c \ proc_object.c \ proc_object_inspect.c \ + proc_query.c \ proc_schema.c \ proc_select.c \ proc_snippet.c \ Added: test/command/suite/query_expand/invalid/nonexistent_expander.expected (+3 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/query_expand/invalid/nonexistent_expander.expected 2016-06-15 15:05:43 +0900 (e45cfe9) @@ -0,0 +1,3 @@ +query_expand Nonexistent +[[[-22,0.0,0.0],"[query][expand] nonexistent query expander: <Nonexistent>"]] +#|e| [query][expand] nonexistent query expander: <Nonexistent> Added: test/command/suite/query_expand/invalid/nonexistent_expander.test (+1 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/query_expand/invalid/nonexistent_expander.test 2016-06-15 15:05:43 +0900 (74fa785) @@ -0,0 +1 @@ +query_expand Nonexistent Added: test/command/suite/query_expand/invalid/nonexistent_flags.expected (+5 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/query_expand/invalid/nonexistent_flags.expected 2016-06-15 15:05:43 +0900 (b5374a5) @@ -0,0 +1,5 @@ +register "query_expanders/tsv" +[[0,0.0,0.0],true] +query_expand QueryExpanderTSV rroonga ALLOW_COLUMN|NONEXISTENT +[[[-22,0.0,0.0],"[query][expand] invalid query flag: <NONEXISTENT>"]] +#|e| [query][expand] invalid query flag: <NONEXISTENT> Added: test/command/suite/query_expand/invalid/nonexistent_flags.test (+5 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/query_expand/invalid/nonexistent_flags.test 2016-06-15 15:05:43 +0900 (d56f820) @@ -0,0 +1,5 @@ +#$GRN_QUERY_EXPANDER_TSV_SYNONYMS_FILE=#{base_directory}/tmp/synonyms.tsv +#@copy-path fixture/query_expander/tsv/expand.tsv tmp/synonyms.tsv +register "query_expanders/tsv" + +query_expand QueryExpanderTSV rroonga ALLOW_COLUMN|NONEXISTENT Added: test/command/suite/query_expand/proc.expected (+4 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/query_expand/proc.expected 2016-06-15 15:05:43 +0900 (66046c8) @@ -0,0 +1,4 @@ +register "query_expanders/tsv" +[[0,0.0,0.0],true] +query_expand QueryExpanderTSV rroonga +[[0,0.0,0.0],"((rroonga) OR (Ruby groonga))"] Added: test/command/suite/query_expand/proc.test (+5 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/query_expand/proc.test 2016-06-15 15:05:43 +0900 (b261c8a) @@ -0,0 +1,5 @@ +#$GRN_QUERY_EXPANDER_TSV_SYNONYMS_FILE=#{base_directory}/tmp/synonyms.tsv +#@copy-path fixture/query_expander/tsv/expand.tsv tmp/synonyms.tsv +register "query_expanders/tsv" + +query_expand QueryExpanderTSV rroonga -------------- next part -------------- HTML����������������������������... Download