[gnote] Accumulate search results in match count order



commit 36258758950e3ec593e3de55e4d7a21f1b043cb8
Author: Casey Harkins <caseyharkins gmail com>
Date:   Mon Nov 21 22:32:36 2011 +0200

    Accumulate search results in match count order
    
    * Replace map with multimap (to allow duplicate keys) and swap order
    of template arguments to use match count as key and note as value.
    * Use of search results in remotecontrol.cpp and recentchanges.cpp
    updated to reflect reversal of key/value. Also switch to reverse
    iterators to start with highest match count notes first.
    
    Fixes bug 662246.

 src/dbus/remotecontrol.cpp |    6 +++---
 src/recentchanges.cpp      |    6 +++---
 src/search.cpp             |    4 ++--
 src/search.hpp             |    2 +-
 4 files changed, 9 insertions(+), 9 deletions(-)
---
diff --git a/src/dbus/remotecontrol.cpp b/src/dbus/remotecontrol.cpp
index 44c6b5a..099311c 100644
--- a/src/dbus/remotecontrol.cpp
+++ b/src/dbus/remotecontrol.cpp
@@ -328,10 +328,10 @@ std::vector< std::string > RemoteControl::SearchNotes(const std::string& query,
   Search::ResultsPtr results =
     search.search_notes(query, case_sensitive, notebooks::Notebook::Ptr());
 
-  for(Search::Results::const_iterator iter = results->begin();
-      iter != results->end(); ++iter) {
+  for(Search::Results::const_reverse_iterator iter = results->rbegin();
+      iter != results->rend(); iter++) {
 
-    list.push_back(iter->first->uri());
+    list.push_back(iter->second->uri());
   }
 
   return list;
diff --git a/src/recentchanges.cpp b/src/recentchanges.cpp
index a36df1e..e96bc40 100644
--- a/src/recentchanges.cpp
+++ b/src/recentchanges.cpp
@@ -558,9 +558,9 @@ namespace gnote {
         no_matches_found_action();
       }
       else {
-        for(Search::Results::const_iterator iter = results->begin();
-            iter != results->end(); ++iter) {
-          m_current_matches[iter->first->uri()] = iter->second;
+        for(Search::Results::const_reverse_iterator iter = results->rbegin();
+            iter != results->rend(); iter++) {
+          m_current_matches[iter->second->uri()] = iter->first;
         }
       
         add_matches_column ();
diff --git a/src/search.cpp b/src/search.cpp
index 42d7754..d5864ad 100644
--- a/src/search.cpp
+++ b/src/search.cpp
@@ -76,7 +76,7 @@ namespace gnote {
       if (0 < find_match_count_in_note (note->get_title(),
                                         words,
                                         case_sensitive)) {
-        temp_matches->insert(std::make_pair(note, INT_MAX));
+        temp_matches->insert(std::make_pair(INT_MAX, note));
       }
       else if (check_note_has_match (note, encoded_words,
                                 case_sensitive)) {
@@ -85,7 +85,7 @@ namespace gnote {
                                     words, case_sensitive);
         if (match_count > 0) {
           // TODO: Improve note.GetHashCode()
-          temp_matches->insert(std::make_pair(note, match_count));
+          temp_matches->insert(std::make_pair(match_count, note));
         }
       }
     }
diff --git a/src/search.hpp b/src/search.hpp
index b2cf871..3e992b0 100644
--- a/src/search.hpp
+++ b/src/search.hpp
@@ -41,7 +41,7 @@ namespace gnote {
 class Search 
 {
 public:
-  typedef std::map<Note::Ptr,int> Results;
+  typedef std::multimap<int,Note::Ptr> Results;
   typedef std::tr1::shared_ptr<Results> ResultsPtr;
 
   template<typename T>



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