susumu.yata
null+****@clear*****
Thu Nov 26 11:37:29 JST 2015
susumu.yata 2015-11-26 11:37:29 +0900 (Thu, 26 Nov 2015) New Revision: ddbf2453d5812cbde39bd37834fd10bb750cbcb2 https://github.com/groonga/groonga/commit/ddbf2453d5812cbde39bd37834fd10bb750cbcb2 Message: grn_ts: add grn_ts_str_score_assignment() Modified files: lib/ts.c lib/ts/ts_str.c lib/ts/ts_str.h Modified: lib/ts.c (+1 -16) =================================================================== --- lib/ts.c 2015-11-26 11:13:40 +0900 (a6435de9) +++ lib/ts.c 2015-11-26 11:37:29 +0900 (081b6c7) @@ -658,25 +658,10 @@ grn_ts_select_scorer(grn_ctx *ctx, grn_obj *table, grn_ts_str str, grn_rc rc; grn_ts_str rest; grn_ts_expr *expr; - rest = grn_ts_str_trim_left(str); + rest = grn_ts_str_trim_score_assignment(str); if (!rest.size) { return GRN_SUCCESS; } - /* If a string starts with "_score =", skip it. */ - if (grn_ts_str_starts_with(str, (grn_ts_str){ "_score", 6 })) { - rest = grn_ts_str_trim_left((grn_ts_str){ rest.ptr + 6, rest.size - 6 }); - if (!rest.size) { - return GRN_SUCCESS; - } - if ((rest.size >= 2) && (rest.ptr[0] == '=') && (rest.ptr[1] != '=')) { - /* Use the rest of a string. */ - rest.ptr += 1; - rest.size -= 1; - } else { - /* Use the whole string. */ - rest = str; - } - } rc = grn_ts_expr_parse(ctx, table, rest, &expr); if (rc != GRN_SUCCESS) { return rc; Modified: lib/ts/ts_str.c (+20 -0) =================================================================== --- lib/ts/ts_str.c 2015-11-26 11:13:40 +0900 (efc17fb) +++ lib/ts/ts_str.c 2015-11-26 11:37:29 +0900 (6a8792e) @@ -72,6 +72,26 @@ grn_ts_str_trim_left(grn_ts_str str) return str; } +grn_ts_str +grn_ts_str_trim_score_assignment(grn_ts_str str) +{ + grn_ts_str rest; + str = grn_ts_str_trim_left(str); + if (!grn_ts_str_starts_with(str, (grn_ts_str){ "_score", 6 })) { + return str; + } + rest.ptr = str.ptr + 6; + rest.size = str.size - 6; + rest = grn_ts_str_trim_left(rest); + if (!rest.size || (rest.ptr[0] != '=') || + ((rest.size >= 2) && (rest.ptr[1] == '='))) { + return str; + } + rest.ptr++; + rest.size--; + return grn_ts_str_trim_left(rest); +} + grn_ts_bool grn_ts_str_has_number_prefix(grn_ts_str str) { Modified: lib/ts/ts_str.h (+8 -1) =================================================================== --- lib/ts/ts_str.h 2015-11-26 11:13:40 +0900 (5def7d6) +++ lib/ts/ts_str.h 2015-11-26 11:37:29 +0900 (08acfb5) @@ -52,10 +52,17 @@ typedef struct { /* grn_ts_str_has_prefix() returns whether or not str starts with prefix. */ grn_ts_bool grn_ts_str_starts_with(grn_ts_str str, grn_ts_str prefix); -/* grn_ts_str_trim_left() returns a string without the leading white-spaces. */ +/* grn_ts_str_trim_left() returns a string without leading white-spaces. */ grn_ts_str grn_ts_str_trim_left(grn_ts_str str); /* + * grn_ts_str_trim_score_assignment() returns a string without leading + * white-spaces and an assignment to _score. If `str` does not start with + * an assignment, this function returns `grn_ts_str_trim_left(str)`. + */ +grn_ts_str grn_ts_str_trim_score_assignment(grn_ts_str str); + +/* * grn_ts_str_has_number_prefix() returns whether or not a string starts with a * number or not. */ -------------- next part -------------- HTML����������������������������...Download