susumu.yata
null+****@clear*****
Thu Nov 12 22:43:40 JST 2015
susumu.yata 2015-11-12 22:43:40 +0900 (Thu, 12 Nov 2015) New Revision: ac70ab2822741e973bb114d2f46c708886969047 https://github.com/groonga/groonga/commit/ac70ab2822741e973bb114d2f46c708886969047 Message: grn_ts: skip "_score =" GitHub: #428 Modified files: lib/ts.c lib/ts/ts_str.c lib/ts/ts_str.h Modified: lib/ts.c (+19 -0) =================================================================== --- lib/ts.c 2015-11-12 22:15:04 +0900 (9ebfce3) +++ lib/ts.c 2015-11-12 22:43:40 +0900 (3385ae7) @@ -722,6 +722,25 @@ grn_ts_select_filter(grn_ctx *ctx, grn_obj *table, grn_ts_str str, static grn_rc grn_ts_select_scorer(grn_ctx *ctx, grn_obj *table, grn_ts_str str, grn_ts_record *records, size_t n_records) { + grn_ts_str rest = grn_ts_str_trim_left(str); + if (!rest.size) { + return GRN_SUCCESS; + } + /* If a string starts with "_scorer =", 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; + } + } // TODO return GRN_SUCCESS; } Modified: lib/ts/ts_str.c (+62 -45) =================================================================== --- lib/ts/ts_str.c 2015-11-12 22:15:04 +0900 (fdc5600) +++ lib/ts/ts_str.c 2015-11-12 22:43:40 +0900 (efc17fb) @@ -21,6 +21,10 @@ #include <ctype.h> #include <string.h> +/*------------------------------------------------------------- + * Byte. + */ + grn_ts_bool grn_ts_byte_is_decimal(uint8_t byte) { @@ -41,6 +45,19 @@ grn_ts_byte_is_name_char(uint8_t byte) return GRN_FALSE; } +/*------------------------------------------------------------- + * String. + */ + +grn_ts_bool +grn_ts_str_starts_with(grn_ts_str str, grn_ts_str prefix) +{ + if (str.size < prefix.size) { + return GRN_FALSE; + } + return !memcmp(str.ptr, prefix.ptr, prefix.size); +} + grn_ts_str grn_ts_str_trim_left(grn_ts_str str) { @@ -56,21 +73,34 @@ grn_ts_str_trim_left(grn_ts_str str) } grn_ts_bool -grn_ts_str_is_true(grn_ts_str str) -{ - return (str.size == 4) && !memcmp(str.ptr, "true", 4); -} - -grn_ts_bool -grn_ts_str_is_false(grn_ts_str str) -{ - return (str.size == 5) && !memcmp(str.ptr, "false", 5); -} - -grn_ts_bool -grn_ts_str_is_bool(grn_ts_str str) +grn_ts_str_has_number_prefix(grn_ts_str str) { - return grn_ts_str_is_true(str) || grn_ts_str_is_false(str); + if (!str.size) { + return GRN_FALSE; + } + if (grn_ts_byte_is_decimal(str.ptr[0])) { + return GRN_TRUE; + } + if (str.size == 1) { + return GRN_FALSE; + } + switch (str.ptr[0]) { + case '+': case '-': { + if (grn_ts_byte_is_decimal(str.ptr[1])) { + return GRN_TRUE; + } + if (str.size == 2) { + return GRN_FALSE; + } + return (str.ptr[1] == '.') && grn_ts_byte_is_decimal(str.ptr[2]); + } + case '.': { + return grn_ts_byte_is_decimal(str.ptr[1]); + } + default: { + return GRN_FALSE; + } + } } grn_ts_bool @@ -95,6 +125,24 @@ grn_ts_str_is_name(grn_ts_str str) } grn_ts_bool +grn_ts_str_is_true(grn_ts_str str) +{ + return (str.size == 4) && !memcmp(str.ptr, "true", 4); +} + +grn_ts_bool +grn_ts_str_is_false(grn_ts_str str) +{ + return (str.size == 5) && !memcmp(str.ptr, "false", 5); +} + +grn_ts_bool +grn_ts_str_is_bool(grn_ts_str str) +{ + return grn_ts_str_is_true(str) || grn_ts_str_is_false(str); +} + +grn_ts_bool grn_ts_str_is_id_name(grn_ts_str str) { return (str.size == GRN_COLUMN_NAME_ID_LEN) && @@ -121,34 +169,3 @@ grn_ts_str_is_value_name(grn_ts_str str) return (str.size == GRN_COLUMN_NAME_VALUE_LEN) && !memcmp(str.ptr, GRN_COLUMN_NAME_VALUE, GRN_COLUMN_NAME_VALUE_LEN); } - -grn_ts_bool -grn_ts_str_has_number_prefix(grn_ts_str str) -{ - if (!str.size) { - return GRN_FALSE; - } - if (grn_ts_byte_is_decimal(str.ptr[0])) { - return GRN_TRUE; - } - if (str.size == 1) { - return GRN_FALSE; - } - switch (str.ptr[0]) { - case '+': case '-': { - if (grn_ts_byte_is_decimal(str.ptr[1])) { - return GRN_TRUE; - } - if (str.size == 2) { - return GRN_FALSE; - } - return (str.ptr[1] == '.') && grn_ts_byte_is_decimal(str.ptr[2]); - } - case '.': { - return grn_ts_byte_is_decimal(str.ptr[1]); - } - default: { - return GRN_FALSE; - } - } -} Modified: lib/ts/ts_str.h (+29 -18) =================================================================== --- lib/ts/ts_str.h 2015-11-12 22:15:04 +0900 (c425ea1) +++ lib/ts/ts_str.h 2015-11-12 22:43:40 +0900 (4a26aca) @@ -25,10 +25,9 @@ extern "C" { #endif -typedef struct { - const char *ptr; /* The starting address. */ - size_t size; /* The size in bytes. */ -} grn_ts_str; +/*------------------------------------------------------------- + * Byte. + */ /* grn_ts_byte_is_decimal() returns whether or not a byte is decimal. */ grn_ts_bool grn_ts_byte_is_decimal(uint8_t byte); @@ -39,17 +38,26 @@ grn_ts_bool grn_ts_byte_is_decimal(uint8_t byte); */ grn_ts_bool grn_ts_byte_is_name_char(uint8_t byte); -/* grn_ts_str_trim_left() returns a string without the leading white-spaces. */ -grn_ts_str grn_ts_str_trim_left(grn_ts_str str); +/*------------------------------------------------------------- + * String. + */ -/* grn_ts_str_is_true() returns str == "true". */ -grn_ts_bool grn_ts_str_is_true(grn_ts_str str); +typedef struct { + const char *ptr; /* The starting address. */ + size_t size; /* The size in bytes. */ +} grn_ts_str; -/* grn_ts_str_is_false() returns str == "false". */ -grn_ts_bool grn_ts_str_is_false(grn_ts_str str); +/* 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_is_bool() returns (str == "true") || (str == "false"). */ -grn_ts_bool grn_ts_str_is_bool(grn_ts_str str); +/* grn_ts_str_trim_left() returns a string without the leading white-spaces. */ +grn_ts_str grn_ts_str_trim_left(grn_ts_str str); + +/* + * grn_ts_str_has_number_prefix() returns whether or not a string starts with a + * number or not. + */ +grn_ts_bool grn_ts_str_has_number_prefix(grn_ts_str str); /* * grn_ts_str_is_name_prefix() returns whether or not a string is valid as a @@ -63,6 +71,15 @@ grn_ts_bool grn_ts_str_is_name_prefix(grn_ts_str str); */ grn_ts_bool grn_ts_str_is_name(grn_ts_str str); +/* grn_ts_str_is_true() returns str == "true". */ +grn_ts_bool grn_ts_str_is_true(grn_ts_str str); + +/* grn_ts_str_is_false() returns str == "false". */ +grn_ts_bool grn_ts_str_is_false(grn_ts_str str); + +/* grn_ts_str_is_bool() returns (str == "true") || (str == "false"). */ +grn_ts_bool grn_ts_str_is_bool(grn_ts_str str); + /* grn_ts_str_is_id_name() returns str == "_id". */ grn_ts_bool grn_ts_str_is_id_name(grn_ts_str str); @@ -75,12 +92,6 @@ grn_ts_bool grn_ts_str_is_key_name(grn_ts_str str); /* grn_ts_str_is_value_name() returns str == "_value". */ grn_ts_bool grn_ts_str_is_value_name(grn_ts_str str); -/* - * grn_ts_str_has_number_prefix() returns whether or not a string starts with a - * number or not. - */ -grn_ts_bool grn_ts_str_has_number_prefix(grn_ts_str str); - #ifdef __cplusplus } #endif -------------- next part -------------- HTML����������������������������...Download