Skip to content

Commit

Permalink
impr: fuzzy - allow null input for phonetic hash functions
Browse files Browse the repository at this point in the history
  • Loading branch information
nalgeon committed Nov 20, 2021
1 parent 88df4ab commit 76244e6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
2 changes: 0 additions & 2 deletions src/sqlite3-fuzzy.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ static void sqlite3_soundex(sqlite3_context* context, int argc, sqlite3_value**
assert(argc == 1);
const unsigned char* source = sqlite3_value_text(argv[0]);
if (source == 0) {
sqlite3_result_error(context, "argument should not be NULL", -1);
return;
}
if (!is_ascii(source)) {
Expand All @@ -129,7 +128,6 @@ static void sqlite3_rsoundex(sqlite3_context* context, int argc, sqlite3_value**
assert(argc == 1);
const unsigned char* source = sqlite3_value_text(argv[0]);
if (source == 0) {
sqlite3_result_error(context, "argument should not be NULL", -1);
return;
}
if (!is_ascii(source)) {
Expand Down
27 changes: 15 additions & 12 deletions test/fuzzy.sql
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,22 @@ select '66', edit_distance('abc', 'acb') = 110;
select '67', edit_distance('abc', 'ca') = 225;

-- Spellcheck phonetic code
select '101', phonetic_hash('') = '';
select '102', phonetic_hash('phonetics') = 'BAMADAC';
select '103', phonetic_hash('is') = 'AC';
select '104', phonetic_hash('awesome') = 'ABACAMA';
select '101', phonetic_hash(null) is null;
select '102', phonetic_hash('') = '';
select '103', phonetic_hash('phonetics') = 'BAMADAC';
select '104', phonetic_hash('is') = 'AC';
select '105', phonetic_hash('awesome') = 'ABACAMA';

-- Soundex code
select '111', soundex('') = '';
select '112', soundex('phonetics') = 'P532';
select '113', soundex('is') = 'I200';
select '114', soundex('awesome') = 'A250';
select '111', soundex(null) is null;
select '112', soundex('') = '';
select '113', soundex('phonetics') = 'P532';
select '114', soundex('is') = 'I200';
select '115', soundex('awesome') = 'A250';

-- Refined Soundex code
select '121', rsoundex('') = '';
select '122', rsoundex('phonetics') = 'P1080603';
select '123', rsoundex('is') = 'I03';
select '124', rsoundex('awesome') = 'A03080';
select '121', rsoundex(null) is null;
select '122', rsoundex('') = '';
select '123', rsoundex('phonetics') = 'P1080603';
select '124', rsoundex('is') = 'I03';
select '125', rsoundex('awesome') = 'A03080';

0 comments on commit 76244e6

Please sign in to comment.