diff options
author | Christian Dywan <christian@twotoasts.de> | 2018-09-10 14:55:59 +0200 |
---|---|---|
committer | Christian Dywan <christian@twotoasts.de> | 2018-09-10 14:55:59 +0200 |
commit | 5e704712dfc6da0793e8c44da8c5c89f60f1e5b7 (patch) | |
tree | 68aae4efd722c955e6937fd27099077ac45f5fdf | |
parent | 2e94e9866b42e2ccf7cd0fa7677b7ecb11de151f (diff) | |
download | midori-git-fuzzy-match.tar.gz |
Implement fuzzy MATCH functionfuzzy-match
-rw-r--r-- | core/database.vala | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/core/database.vala b/core/database.vala index 748f54c3..f5e14ba6 100644 --- a/core/database.vala +++ b/core/database.vala @@ -265,6 +265,11 @@ namespace Midori { } set_data<unowned Sqlite.Database> ("db", db); + // Note: Sqlite.DETERMINISTIC = 0x800 + if (db.create_function ("MATCH", 2, Sqlite.UTF8 | 0x800, null, fuzzy_compare, null, null) != Sqlite.OK) { + throw new DatabaseError.COMPILE ("Failed to add MATCH function: %s".printf (errmsg)); + } + if (logging) { debug ("Tracing %s", path); db.profile ((sql, nanoseconds) => { @@ -312,6 +317,21 @@ namespace Midori { return true; } + /* + * Match string or strings separated by whitepace + */ + static void fuzzy_compare (Sqlite.Context context, Sqlite.Value[] values) { + string[] needles = values[0].to_text ().split (" "); + string haystack = values[1].to_text (); + foreach (string needle in needles) { + if (needle in haystack) { + context.result_int (-1); + return; + } + } + context.result_int (0); + } + public bool exists (string path) { return FileUtils.test (path, FileTest.EXISTS); } |