[geary/wip/720361-stemming] Allow for search strategy to be configured in GSettings
- From: Jim Nelson <jnelson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/720361-stemming] Allow for search strategy to be configured in GSettings
- Date: Fri, 12 Dec 2014 01:09:51 +0000 (UTC)
commit 2281d7c996fb6f762962e28821ba3452f0cdfae7
Author: Jim Nelson <jim yorba org>
Date: Thu Dec 11 17:09:31 2014 -0800
Allow for search strategy to be configured in GSettings
desktop/org.yorba.geary.gschema.xml | 7 ++++
src/client/application/geary-config.vala | 38 ++++++++++++++++++++
src/client/application/geary-controller.vala | 2 +-
src/engine/abstract/geary-abstract-account.vala | 2 +-
src/engine/api/geary-account.vala | 4 +-
src/engine/api/geary-search-folder.vala | 8 ++--
src/engine/api/geary-search-query.vala | 14 ++++----
src/engine/imap-db/imap-db-account.vala | 9 ++++-
src/engine/imap-db/imap-db-search-query.vala | 14 ++++----
.../imap-engine/imap-engine-generic-account.vala | 4 +-
10 files changed, 76 insertions(+), 26 deletions(-)
---
diff --git a/desktop/org.yorba.geary.gschema.xml b/desktop/org.yorba.geary.gschema.xml
index b619d13..3e5bb33 100644
--- a/desktop/org.yorba.geary.gschema.xml
+++ b/desktop/org.yorba.geary.gschema.xml
@@ -74,6 +74,13 @@
<summary>whether to compose emails in HTML</summary>
<description>True to compose emails in HTML; false for plain text.</description>
</key>
+
+ <key name="search-strategy" type="s">
+ <default>"conservative"</default>
+ <summary>Advisory strategy for full-text searching</summary>
+ <description>Acceptable values are EXACT, CONSERVATIVE, AGGRESSIVE, and HORIZON.</description>
+ </key>
+
</schema>
</schemalist>
diff --git a/src/client/application/geary-config.vala b/src/client/application/geary-config.vala
index 2e84304..7976167 100644
--- a/src/client/application/geary-config.vala
+++ b/src/client/application/geary-config.vala
@@ -135,5 +135,43 @@ public class Configuration {
if (!settings.set_boolean(name, value))
message("Unable to set configuration value %s = %s", name, value.to_string());
}
+
+ public Geary.SearchQuery.Strategy get_search_strategy() {
+ switch (settings.get_string("search-strategy").down()) {
+ case "exact":
+ return Geary.SearchQuery.Strategy.EXACT;
+
+ case "aggressive":
+ return Geary.SearchQuery.Strategy.AGGRESSIVE;
+
+ case "horizon":
+ return Geary.SearchQuery.Strategy.HORIZON;
+
+ case "conservative":
+ default:
+ return Geary.SearchQuery.Strategy.CONSERVATIVE;
+ }
+ }
+
+ public void set_search_strategy(Geary.SearchQuery.Strategy strategy) {
+ switch (strategy) {
+ case Geary.SearchQuery.Strategy.EXACT:
+ settings.set_string("search-strategy", "exact");
+ break;
+
+ case Geary.SearchQuery.Strategy.AGGRESSIVE:
+ settings.set_string("search-strategy", "aggressive");
+ break;
+
+ case Geary.SearchQuery.Strategy.HORIZON:
+ settings.set_string("search-strategy", "horizon");
+ break;
+
+ case Geary.SearchQuery.Strategy.CONSERVATIVE:
+ default:
+ settings.set_string("search-strategy", "conservative");
+ break;
+ }
+ }
}
diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala
index 4bb7083..97bbeec 100644
--- a/src/client/application/geary-controller.vala
+++ b/src/client/application/geary-controller.vala
@@ -2512,7 +2512,7 @@ public class GearyController : Geary.BaseObject {
cancel_search(); // Stop any search in progress.
- folder.set_search_query(search_text, Geary.SearchQuery.Matching.CONSERVATIVE,
+ folder.set_search_query(search_text, GearyApplication.instance.config.get_search_strategy(),
cancellable_search);
main_window.folder_list.set_search(folder);
diff --git a/src/engine/abstract/geary-abstract-account.vala b/src/engine/abstract/geary-abstract-account.vala
index c56b9aa..4a224ca 100644
--- a/src/engine/abstract/geary-abstract-account.vala
+++ b/src/engine/abstract/geary-abstract-account.vala
@@ -118,7 +118,7 @@ public abstract class Geary.AbstractAccount : BaseObject, Geary.Account {
public abstract async Geary.Email local_fetch_email_async(Geary.EmailIdentifier email_id,
Geary.Email.Field required_fields, Cancellable? cancellable = null) throws Error;
- public abstract Geary.SearchQuery open_search(string query, Geary.SearchQuery.Matching matching);
+ public abstract Geary.SearchQuery open_search(string query, Geary.SearchQuery.Strategy strategy);
public abstract async Gee.Collection<Geary.EmailIdentifier>? local_search_async(Geary.SearchQuery query,
int limit = 100, int offset = 0, Gee.Collection<Geary.FolderPath?>? folder_blacklist = null,
diff --git a/src/engine/api/geary-account.vala b/src/engine/api/geary-account.vala
index 6b26097..c579461 100644
--- a/src/engine/api/geary-account.vala
+++ b/src/engine/api/geary-account.vala
@@ -325,7 +325,7 @@ public interface Geary.Account : BaseObject {
/**
* Create a new { link SearchQuery} for this { link Account}.
*
- * See { link Geary.SearchQuery.Matching} for more information about how its interpreted by the
+ * See { link Geary.SearchQuery.Strategy} for more information about how its interpreted by the
* Engine. In particular, note that it's an advisory parameter only and may have no effect,
* especially on server searches. However, it may also have a dramatic effect on what search
* results are returned and so should be used with some caution. Whether this parameter is
@@ -337,7 +337,7 @@ public interface Geary.Account : BaseObject {
*
* Dropping the last reference to the SearchQuery will close it.
*/
- public abstract Geary.SearchQuery open_search(string query, Geary.SearchQuery.Matching matching);
+ public abstract Geary.SearchQuery open_search(string query, Geary.SearchQuery.Strategy strategy);
/**
* Performs a search with the given query. Optionally, a list of folders not to search
diff --git a/src/engine/api/geary-search-folder.vala b/src/engine/api/geary-search-folder.vala
index e7246a7..4f51e43 100644
--- a/src/engine/api/geary-search-folder.vala
+++ b/src/engine/api/geary-search-folder.vala
@@ -203,8 +203,8 @@ public class Geary.SearchFolder : Geary.AbstractLocalFolder, Geary.FolderSupport
/**
* Sets the keyword string for this search.
*/
- public void set_search_query(string query, SearchQuery.Matching matching, Cancellable? cancellable =
null) {
- set_search_query_async.begin(query, matching, cancellable, on_set_search_query_complete);
+ public void set_search_query(string query, SearchQuery.Strategy strategy, Cancellable? cancellable =
null) {
+ set_search_query_async.begin(query, strategy, cancellable, on_set_search_query_complete);
}
private void on_set_search_query_complete(Object? source, AsyncResult result) {
@@ -215,9 +215,9 @@ public class Geary.SearchFolder : Geary.AbstractLocalFolder, Geary.FolderSupport
}
}
- private async void set_search_query_async(string query, SearchQuery.Matching matching,
+ private async void set_search_query_async(string query, SearchQuery.Strategy strategy,
Cancellable? cancellable) throws Error {
- Geary.SearchQuery search_query = account.open_search(query, matching);
+ Geary.SearchQuery search_query = account.open_search(query, strategy);
int result_mutex_token = yield result_mutex.claim_async();
diff --git a/src/engine/api/geary-search-query.vala b/src/engine/api/geary-search-query.vala
index adfc99b..da9e187 100644
--- a/src/engine/api/geary-search-query.vala
+++ b/src/engine/api/geary-search-query.vala
@@ -16,17 +16,17 @@
public abstract class Geary.SearchQuery : BaseObject {
/**
- * An advisory parameter regarding search quality and scope.
+ * An advisory parameter regarding search quality, scope, and breadth.
*
* The Engine can perform searches based on (unspecified, uncontracted) textual variations of
* a query's search terms. Some of those variations may produce undesirable results due to
- * "greedy" matching of terms. The Matching parameter allows for an advisory to the Engine
+ * "greedy" matching of terms. The Strategy parameter allows for an advisory to the Engine
* about how to use those textual variants, if any at all.
*
* This may be respected or ignored by the Engine. In particular, there's no guarantee it will
* have any effect on server search.
*/
- public enum Matching {
+ public enum Strategy {
/**
* Only return exact matches, perform no searches for textual variants.
*
@@ -56,13 +56,13 @@ public abstract class Geary.SearchQuery : BaseObject {
public string raw { get; private set; }
/**
- * The selected { link Matching} quality.
+ * The selected { link Strategy} quality.
*/
- public Matching matching { get; private set; }
+ public Strategy strategy { get; private set; }
- protected SearchQuery(string raw, Matching matching) {
+ protected SearchQuery(string raw, Strategy strategy) {
this.raw = raw;
- this.matching = matching;
+ this.strategy = strategy;
}
}
diff --git a/src/engine/imap-db/imap-db-account.vala b/src/engine/imap-db/imap-db-account.vala
index 8515fa6..ac20f8d 100644
--- a/src/engine/imap-db/imap-db-account.vala
+++ b/src/engine/imap-db/imap-db-account.vala
@@ -1085,9 +1085,14 @@ private class Geary.ImapDB.Account : BaseObject {
if (search_results.size == 0)
return null;
+ // HORIZON strategy is configured in such a way to allow all stemmed variants to match,
+ // so don't do any stripping in that case
+ if (query.strategy == Geary.SearchQuery.Strategy.HORIZON)
+ return search_results;
+
// if any of the search terms is exact-match (no prefix matching) or none have stemmed
- // variants, then don't do stripping of "greedy" stemmed variants (as in both cases, there
- // are none)
+ // variants, then don't do stripping of "greedy" stemmed matching (because in both cases,
+ // there are none)
if (traverse<SearchTerm>(query.get_all_terms()).any(term => term.stemmed == null || term.is_exact))
return search_results;
diff --git a/src/engine/imap-db/imap-db-search-query.vala b/src/engine/imap-db/imap-db-search-query.vala
index eea1f68..1c7fbf9 100644
--- a/src/engine/imap-db/imap-db-search-query.vala
+++ b/src/engine/imap-db/imap-db-search-query.vala
@@ -59,34 +59,34 @@ private class Geary.ImapDB.SearchQuery : Geary.SearchQuery {
= new Gee.HashMap<string?, Gee.ArrayList<SearchTerm>>();
private Gee.ArrayList<SearchTerm> all = new Gee.ArrayList<SearchTerm>();
- public SearchQuery(ImapDB.Account account, string query, Geary.SearchQuery.Matching matching) {
- base (query, matching);
+ public SearchQuery(ImapDB.Account account, string query, Geary.SearchQuery.Strategy strategy) {
+ base (query, strategy);
this.account = account;
- switch (matching) {
- case Matching.EXACT:
+ switch (strategy) {
+ case Strategy.EXACT:
allow_stemming = false;
min_term_length_for_stemming = int.MAX;
max_difference_term_stem_lengths = 0;
max_difference_match_stem_lengths = 0;
break;
- case Matching.CONSERVATIVE:
+ case Strategy.CONSERVATIVE:
allow_stemming = true;
min_term_length_for_stemming = 6;
max_difference_term_stem_lengths = 2;
max_difference_match_stem_lengths = 2;
break;
- case Matching.AGGRESSIVE:
+ case Strategy.AGGRESSIVE:
allow_stemming = true;
min_term_length_for_stemming = 4;
max_difference_term_stem_lengths = 4;
max_difference_match_stem_lengths = 3;
break;
- case Matching.HORIZON:
+ case Strategy.HORIZON:
allow_stemming = true;
min_term_length_for_stemming = 0;
max_difference_term_stem_lengths = int.MAX;
diff --git a/src/engine/imap-engine/imap-engine-generic-account.vala
b/src/engine/imap-engine/imap-engine-generic-account.vala
index f59af5a..3e6911d 100644
--- a/src/engine/imap-engine/imap-engine-generic-account.vala
+++ b/src/engine/imap-engine/imap-engine-generic-account.vala
@@ -824,8 +824,8 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.AbstractAccount {
return yield local.fetch_email_async(check_id(email_id), required_fields, cancellable);
}
- public override Geary.SearchQuery open_search(string query, SearchQuery.Matching matching) {
- return new ImapDB.SearchQuery(local, query, matching);
+ public override Geary.SearchQuery open_search(string query, SearchQuery.Strategy strategy) {
+ return new ImapDB.SearchQuery(local, query, strategy);
}
public override async Gee.Collection<Geary.EmailIdentifier>? local_search_async(Geary.SearchQuery query,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]