From 20ac1078f6cacb44e1352767ed94f9c5420a165f Mon Sep 17 00:00:00 2001 From: Charles Lindsay Date: Tue, 24 Sep 2013 17:48:35 -0700 Subject: [PATCH] Add words from query to highlighting; fix #7205 --- .../abstract/geary-abstract-account.vala | 2 +- src/engine/api/geary-account.vala | 5 ++--- src/engine/api/geary-search-folder.vala | 2 +- src/engine/imap-db/imap-db-account.vala | 21 ++++++++++++++++++- .../imap-engine-generic-account.vala | 11 ++++------ 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/engine/abstract/geary-abstract-account.vala b/src/engine/abstract/geary-abstract-account.vala index b3335266..f9ca8140 100644 --- a/src/engine/abstract/geary-abstract-account.vala +++ b/src/engine/abstract/geary-abstract-account.vala @@ -120,7 +120,7 @@ public abstract class Geary.AbstractAccount : BaseObject, Geary.Account { int limit = 100, int offset = 0, Gee.Collection? folder_blacklist = null, Gee.Collection? search_ids = null, Cancellable? cancellable = null) throws Error; - public abstract async Gee.Collection? get_search_matches_async( + public abstract async Gee.Collection? get_search_matches_async(string query, Gee.Collection ids, Cancellable? cancellable = null) throws Error; public abstract async Gee.MultiMap? get_containing_folders_async( diff --git a/src/engine/api/geary-account.vala b/src/engine/api/geary-account.vala index 36c40808..38b0c399 100644 --- a/src/engine/api/geary-account.vala +++ b/src/engine/api/geary-account.vala @@ -317,10 +317,9 @@ public interface Geary.Account : BaseObject { Gee.Collection? search_ids = null, Cancellable? cancellable = null) throws Error; /** - * Given a list of mail IDs, returns a list of words that match for the - * last run local_search_async() query. + * Given a list of mail IDs, returns a list of words that match the given query string. */ - public abstract async Gee.Collection? get_search_matches_async( + public abstract async Gee.Collection? get_search_matches_async(string query, Gee.Collection ids, Cancellable? cancellable = null) throws Error; /** diff --git a/src/engine/api/geary-search-folder.vala b/src/engine/api/geary-search-folder.vala index 8db2377f..11187e0e 100644 --- a/src/engine/api/geary-search-folder.vala +++ b/src/engine/api/geary-search-folder.vala @@ -435,7 +435,7 @@ public class Geary.SearchFolder : Geary.AbstractLocalFolder, Geary.FolderSupport Gee.Collection ids, Cancellable? cancellable = null) throws Error { if (search_query == null) return null; - return yield account.get_search_matches_async(ids, cancellable); + return yield account.get_search_matches_async(search_query, ids, cancellable); } private void exclude_folder(Geary.Folder folder) { diff --git a/src/engine/imap-db/imap-db-account.vala b/src/engine/imap-db/imap-db-account.vala index 4db21b09..3ae67ca1 100644 --- a/src/engine/imap-db/imap-db-account.vala +++ b/src/engine/imap-db/imap-db-account.vala @@ -779,7 +779,24 @@ private class Geary.ImapDB.Account : BaseObject { return (search_results.size == 0 ? null : search_results); } - public async Gee.Collection? get_search_matches_async(string prepared_query, + // This applies a fudge-factor set of matches when the database results + // aren't entirely satisfactory, such as when you search for an email + // address and the database tokenizes out the @ and ., etc. It's not meant + // to be comprehensive, just a little extra highlighting applied to make + // the results look a little closer to what you typed. + private void add_literal_matches(string raw_query, Gee.Set search_matches) { + foreach (string word in raw_query.split(" ")) { + if (word.has_suffix("\"")) + word = word.substring(0, word.length - 1); + if (word.has_prefix("\"")) + word = word.substring(1); + + if (!String.is_empty_or_whitespace(word)) + search_matches.add(word); + } + } + + public async Gee.Collection? get_search_matches_async(string raw_query, string prepared_query, Gee.Collection ids, Cancellable? cancellable = null) throws Error { check_open(); @@ -830,6 +847,8 @@ private class Geary.ImapDB.Account : BaseObject { return Db.TransactionOutcome.DONE; }, cancellable); + add_literal_matches(raw_query, search_matches); + return (search_matches.size == 0 ? null : search_matches); } diff --git a/src/engine/imap-engine/imap-engine-generic-account.vala b/src/engine/imap-engine/imap-engine-generic-account.vala index 9992caf2..66740f4f 100644 --- a/src/engine/imap-engine/imap-engine-generic-account.vala +++ b/src/engine/imap-engine/imap-engine-generic-account.vala @@ -19,7 +19,6 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.AbstractAccount { private uint refresh_folder_timeout_id = 0; private bool in_refresh_enumerate = false; private Cancellable refresh_cancellable = new Cancellable(); - private string previous_prepared_search_query = ""; private bool awaiting_credentials = false; public GenericAccount(string name, Geary.AccountInformation information, Imap.Account remote, @@ -579,16 +578,14 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.AbstractAccount { if (offset < 0) throw new EngineError.BAD_PARAMETERS("Offset must not be negative"); - previous_prepared_search_query = local.prepare_search_query(query); - - return yield local.search_async(previous_prepared_search_query, + return yield local.search_async(local.prepare_search_query(query), limit, offset, folder_blacklist, search_ids, cancellable); } - public override async Gee.Collection? get_search_matches_async( + public override async Gee.Collection? get_search_matches_async(string query, Gee.Collection ids, Cancellable? cancellable = null) throws Error { - return yield local.get_search_matches_async(previous_prepared_search_query, check_ids(ids), - cancellable); + return yield local.get_search_matches_async(query, local.prepare_search_query(query), + check_ids(ids), cancellable); } public override async Gee.MultiMap? get_containing_folders_async(