Kouhei Sutou
null+****@clear*****
Thu Nov 12 17:20:25 JST 2015
Kouhei Sutou 2015-11-12 17:20:25 +0900 (Thu, 12 Nov 2015) New Revision: 4ae204767398742b00e7767fbf897768c923c36a https://github.com/groonga/groonga/commit/4ae204767398742b00e7767fbf897768c923c36a Message: Fix a bug that "@" for sequential search doesn't match "test" wasn't matched to "ttest". Added files: test/command/suite/select/filter/no_index/match/leading_same_char.expected test/command/suite/select/filter/no_index/match/leading_same_char.test Modified files: lib/operator.c Modified: lib/operator.c (+43 -6) =================================================================== --- lib/operator.c 2015-11-12 14:09:09 +0900 (581a6c2) +++ lib/operator.c 2015-11-12 17:20:25 +0900 (fc5155b) @@ -672,18 +672,55 @@ string_have_sub_text(grn_ctx *ctx, { /* TODO: Use more fast algorithm such as Boyer-Moore algorithm that * is used in snip.c. */ + const char *text_current = text; const char *text_end = text + text_len; - unsigned int sub_text_current = 0; + const char *sub_text_current = sub_text; + const char *sub_text_end = sub_text + sub_text_len; + int sub_text_start_char_len; + int sub_text_char_len; - for (; text < text_end; text++) { - if (text[0] == sub_text[sub_text_current]) { - sub_text_current++; - if (sub_text_current == sub_text_len) { + if (sub_text_len == 0) { + return GRN_FALSE; + } + + if (sub_text_len > text_len) { + return GRN_FALSE; + } + + sub_text_start_char_len = grn_charlen(ctx, sub_text, sub_text_end); + if (sub_text_start_char_len == 0) { + return GRN_FALSE; + } + sub_text_char_len = sub_text_start_char_len; + + while (text_current < text_end) { + int text_char_len; + + text_char_len = grn_charlen(ctx, text_current, text_end); + if (text_char_len == 0) { + return GRN_FALSE; + } + + if (text_char_len == sub_text_char_len && + memcmp(text_current, sub_text_current, text_char_len) == 0) { + sub_text_current += sub_text_char_len; + if (sub_text_current == sub_text_end) { return GRN_TRUE; } + + sub_text_char_len = grn_charlen(ctx, sub_text_current, sub_text_end); + if (sub_text_char_len == 0) { + return GRN_FALSE; + } } else { - sub_text_current = 0; + if (sub_text_current != sub_text) { + sub_text_current = sub_text; + sub_text_char_len = sub_text_start_char_len; + continue; + } } + + text_current += text_char_len; } return GRN_FALSE; Added: test/command/suite/select/filter/no_index/match/leading_same_char.expected (+11 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/filter/no_index/match/leading_same_char.expected 2015-11-12 17:20:25 +0900 (7d79704) @@ -0,0 +1,11 @@ +table_create Memos TABLE_NO_KEY +[[0,0.0,0.0],true] +column_create Memos content COLUMN_SCALAR Text +[[0,0.0,0.0],true] +load --table Memos +[ +{"content": "ggroonga"} +] +[[0,0.0,0.0],1] +select Memos --filter 'content @ "groonga"' +[[0,0.0,0.0],[[[1],[["_id","UInt32"],["content","Text"]],[1,"ggroonga"]]]] Added: test/command/suite/select/filter/no_index/match/leading_same_char.test (+9 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/filter/no_index/match/leading_same_char.test 2015-11-12 17:20:25 +0900 (bf2329e) @@ -0,0 +1,9 @@ +table_create Memos TABLE_NO_KEY +column_create Memos content COLUMN_SCALAR Text + +load --table Memos +[ +{"content": "ggroonga"} +] + +select Memos --filter 'content @ "groonga"' -------------- next part -------------- HTML����������������������������...다운로드