Add words from query to highlighting; fix #7205

This commit is contained in:
Charles Lindsay 2013-09-24 17:48:35 -07:00
parent b93a6b3729
commit 20ac1078f6
5 changed files with 28 additions and 13 deletions

View file

@ -120,7 +120,7 @@ public abstract class Geary.AbstractAccount : BaseObject, Geary.Account {
int limit = 100, int offset = 0, Gee.Collection<Geary.FolderPath?>? folder_blacklist = null,
Gee.Collection<Geary.EmailIdentifier>? search_ids = null, Cancellable? cancellable = null) throws Error;
public abstract async Gee.Collection<string>? get_search_matches_async(
public abstract async Gee.Collection<string>? get_search_matches_async(string query,
Gee.Collection<Geary.EmailIdentifier> ids, Cancellable? cancellable = null) throws Error;
public abstract async Gee.MultiMap<Geary.EmailIdentifier, Geary.FolderPath>? get_containing_folders_async(

View file

@ -317,10 +317,9 @@ public interface Geary.Account : BaseObject {
Gee.Collection<Geary.EmailIdentifier>? 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<string>? get_search_matches_async(
public abstract async Gee.Collection<string>? get_search_matches_async(string query,
Gee.Collection<Geary.EmailIdentifier> ids, Cancellable? cancellable = null) throws Error;
/**

View file

@ -435,7 +435,7 @@ public class Geary.SearchFolder : Geary.AbstractLocalFolder, Geary.FolderSupport
Gee.Collection<Geary.EmailIdentifier> 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) {

View file

@ -779,7 +779,24 @@ private class Geary.ImapDB.Account : BaseObject {
return (search_results.size == 0 ? null : search_results);
}
public async Gee.Collection<string>? 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<string> 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<string>? get_search_matches_async(string raw_query, string prepared_query,
Gee.Collection<ImapDB.EmailIdentifier> 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);
}

View file

@ -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<string>? get_search_matches_async(
public override async Gee.Collection<string>? get_search_matches_async(string query,
Gee.Collection<Geary.EmailIdentifier> 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<Geary.EmailIdentifier, Geary.FolderPath>? get_containing_folders_async(