[geary/wip/720361-stemming] [archive* OR archiv*] => [archiv*]



commit eb60edd6fcbec9bb0db8401f015f476b067f8162
Author: Jim Nelson <jim yorba org>
Date:   Thu Dec 11 16:33:56 2014 -0800

    [archive* OR archiv*] => [archiv*]

 src/engine/imap-db/imap-db-account.vala     |   19 +++++++++++++++++--
 src/engine/imap-db/imap-db-search-term.vala |   22 ++++++----------------
 2 files changed, 23 insertions(+), 18 deletions(-)
---
diff --git a/src/engine/imap-db/imap-db-account.vala b/src/engine/imap-db/imap-db-account.vala
index 7eb74e5..8515fa6 100644
--- a/src/engine/imap-db/imap-db-account.vala
+++ b/src/engine/imap-db/imap-db-account.vala
@@ -846,7 +846,7 @@ private class Geary.ImapDB.Account : BaseObject {
                 // HACK: this helps prevent a syntax error when the user types
                 // something like from:"somebody".  If we ever properly support
                 // quotes after : we can get rid of this.
-                term = new SearchTerm(s, s, null, str => str.replace(":", " "));
+                term = new SearchTerm(s, s, null, s.replace(":", " "), null);
             } else {
                 string original = s;
                 
@@ -878,7 +878,22 @@ private class Geary.ImapDB.Account : BaseObject {
                 if (parts.length > 1)
                     field = extract_field_from_token(parts, ref s);
                 
-                term = new SearchTerm(original, s, stem_search_term(query, s), str => "%s*".printf(str));
+                // SQL MATCH syntax for parsed term
+                string? sql_s = "%s*".printf(s);
+                
+                // stem the word, but if stemmed and stem is simply shorter version of original
+                // term, only prefix-match search for it (i.e. avoid searching for
+                // [archive* OR archiv*] when that's the same as [archiv*]), otherwise search for
+                // both
+                string? stemmed = stem_search_term(query, s);
+                string? sql_stemmed = null;
+                if (stemmed != null) {
+                    sql_stemmed = "%s*".printf(stemmed);
+                    if (s.has_prefix(stemmed))
+                        sql_s = null;
+                }
+                
+                term = new SearchTerm(original, s, stemmed, sql_s, sql_stemmed);
             }
             
             if (in_quote && quotes % 2 != 0)
diff --git a/src/engine/imap-db/imap-db-search-term.vala b/src/engine/imap-db/imap-db-search-term.vala
index 4cf83a5..c56a047 100644
--- a/src/engine/imap-db/imap-db-search-term.vala
+++ b/src/engine/imap-db/imap-db-search-term.vala
@@ -10,13 +10,6 @@
 
 private class Geary.ImapDB.SearchTerm : BaseObject {
     /**
-     * Convert search term text into SQL for SQLite's MATCH operator.
-     *
-     * If null or an empty string is returned, the text will be dropped.
-     */
-    public delegate string? TextToMatch(string text);
-    
-    /**
      * The original tokenized search term with minimal other processing performed.
      *
      * For example, punctuation might be removed, but no casefolding has occurred.
@@ -52,21 +45,18 @@ private class Geary.ImapDB.SearchTerm : BaseObject {
      */
     public bool is_exact { get { return parsed.has_prefix("\"") && stemmed == null; } }
     
-    public SearchTerm(string original, string parsed, string? stemmed, TextToMatch text_to_match) {
+    public SearchTerm(string original, string parsed, string? stemmed, string? sql_parsed, string? 
sql_stemmed) {
         this.original = original;
         this.parsed = parsed;
         this.stemmed = stemmed;
         
         // for now, only two variations: the parsed string and the stemmed; since stem is usually
         // shorter (and will be first in the OR statement), include it first
-        if (stemmed != null)
-            add_sql(text_to_match(stemmed));
-        add_sql(text_to_match(parsed));
-    }
-    
-    private void add_sql(string? match_term) {
-        if (!String.is_empty(match_term))
-            sql.add(match_term);
+        if (!String.is_empty(sql_stemmed))
+            sql.add(sql_stemmed);
+        
+        if (!String.is_empty(sql_parsed))
+            sql.add(sql_parsed);
     }
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]