static void scoreFunc( sqlite3_context *context, int argc, sqlite3_value **argv ) { const char* needle = sqlite3_value_text(argv[0]); const char* haystack = sqlite3_value_text(argv[1]); int match1 = -1, match1_len, needle_len; match_fuzzy(needle, haystack, &match1, &match1_len, &needle_len); if (match1 == -1) { sqlite3_result_int(context, 0); return; } if (needle_len == match1_len) { // exact match sqlite3_result_int(context, score_exact( match1, match1_len, haystack )); return; } int best = score_fuzzy(match1, match1_len, haystack); int last_index_of_dot = -1, i; for (i = 0; haystack[i] != 0; ++i) { if (haystack[i] == '.') last_index_of_dot = i; } if (last_index_of_dot != -1) { int match2 = -1, match2_len; match_fuzzy( needle, haystack + last_index_of_dot + 1, &match2, &match2_len, 0 ); if (match2 != -1) { best = max(best, score_fuzzy(match2, match2_len, haystack + last_index_of_dot + 1) ); } } sqlite3_result_int(context, best); }
void match(void) { if(fuzzy) match_fuzzy(); else match_tokens(); }