[gnote] Change search to prioritize note titles



commit cf12c1a400ab5fd6a839abd01d084e6ce425f964
Author: Aurimas Äernius <aurisc4 gmail com>
Date:   Mon Aug 15 14:55:20 2011 +0300

    Change search to prioritize note titles
    
    Ported Tomboy feature (Tomboy bug 637239).

 src/recentchanges.cpp |    6 +++++-
 src/search.cpp        |   15 +++++++++++----
 src/search.hpp        |   10 +++++++---
 3 files changed, 23 insertions(+), 8 deletions(-)
---
diff --git a/src/recentchanges.cpp b/src/recentchanges.cpp
index ad65b6c..c30fcbb 100644
--- a/src/recentchanges.cpp
+++ b/src/recentchanges.cpp
@@ -570,7 +570,11 @@ namespace gnote {
         = m_current_matches.find(note->uri());
       if (miter != m_current_matches.end()) {
         match_count = miter->second;
-        if (match_count > 0) {
+        if(match_count == INT_MAX) {
+          //TRANSLATORS: search found a match in note title
+          match_str = _("Title match");
+        }
+        else if (match_count > 0) {
           const char * fmt;
           fmt = ngettext("%1% match", "%1% matches", match_count);
           match_str = str(boost::format(fmt) % match_count);
diff --git a/src/search.cpp b/src/search.cpp
index d8c380d..1d39439 100644
--- a/src/search.cpp
+++ b/src/search.cpp
@@ -1,6 +1,7 @@
 /*
  * gnote
  *
+ * Copyright (C) 2011 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -63,10 +64,16 @@ namespace gnote {
       if (selected_notebook && !selected_notebook->contains_note (note))
         continue;
         
-      // Check the note's raw XML for at least one
-      // match, to avoid deserializing Buffers
-      // unnecessarily.
-      if (check_note_has_match (note, encoded_words,
+      // First check the note's title for a match,
+      // if there is no match check the note's raw
+      // XML for at least one match, to avoid
+      // deserializing Buffers unnecessarily.
+      if (0 < find_match_count_in_note (note->get_title(),
+                                        words,
+                                        case_sensitive)) {
+        temp_matches->insert(std::make_pair(note, INT_MAX));
+      }
+      else if (check_note_has_match (note, encoded_words,
                                 case_sensitive)) {
         int match_count =
           find_match_count_in_note (note->text_content(),
diff --git a/src/search.hpp b/src/search.hpp
index 8ae741a..b2cf871 100644
--- a/src/search.hpp
+++ b/src/search.hpp
@@ -1,6 +1,7 @@
 /*
  * gnote
  *
+ * Copyright (C) 2011 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -50,8 +51,9 @@ public:
   Search(NoteManager &);
 
     
-  /// <summary>
-  /// Search the notes!
+  /// Search the notes! A match number of
+  /// INT_MAX indicates that the note
+  /// title contains the search term.
   /// </summary>
   /// <param name="query">
   /// A <see cref="System.String"/>
@@ -65,7 +67,9 @@ public:
   /// be searched.
   /// </param>
   /// <returns>
-  /// A <see cref="IDictionary`2"/>
+  /// A <see cref="IDictionary`2"/> with the relevant Notes
+  /// and a match number. If the search term is in the title,
+  /// number will be INT_MAX.
   /// </returns>  
   ResultsPtr search_notes(const std::string &, bool, 
                           const notebooks::Notebook::Ptr & );



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