[gnote] Make shell search provider search only in titles



commit f173071c50aff34d9287f30520681661d6907ec5
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Wed Sep 7 13:34:16 2016 +0300

    Make shell search provider search only in titles
    
    Fixes Bug 765894.

 src/dbus/searchprovider.cpp |   26 +++++++++++++++-----------
 1 files changed, 15 insertions(+), 11 deletions(-)
---
diff --git a/src/dbus/searchprovider.cpp b/src/dbus/searchprovider.cpp
index 9328eea..8f706d6 100644
--- a/src/dbus/searchprovider.cpp
+++ b/src/dbus/searchprovider.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2013-2014 Aurimas Cernius
+ * Copyright (C) 2013-2014,2016 Aurimas Cernius
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -26,7 +26,6 @@
 #include "debug.hpp"
 #include "iconmanager.hpp"
 #include "ignote.hpp"
-#include "search.hpp"
 #include "searchprovider.hpp"
 
 
@@ -87,19 +86,24 @@ void SearchProvider::on_method_call(const Glib::RefPtr<Gio::DBus::Connection> &,
 
 std::vector<Glib::ustring> SearchProvider::GetInitialResultSet(const std::vector<Glib::ustring> & terms)
 {
-  std::set<gnote::Note::Ptr> final_result;
-  gnote::Search search(m_manager);
-  gnote::notebooks::Notebook::Ptr notebook;
-  for(std::vector<Glib::ustring>::const_iterator query = terms.begin(); query != terms.end(); ++query) {
-    gnote::Search::ResultsPtr results = search.search_notes(*query, false, notebook);
-    for(gnote::Search::Results::iterator iter = results->begin(); iter != results->end(); ++iter) {
-      final_result.insert(iter->second);
+  std::set<gnote::NoteBase::Ptr> final_result;
+  std::vector<Glib::ustring> search_terms;
+  search_terms.reserve(terms.size());
+  for(auto & term : terms) {
+    search_terms.push_back(term.casefold());
+  }
+  for(auto note : m_manager.get_notes()) {
+    auto title = note->get_title().casefold();
+    for(auto term : search_terms) {
+      if(title.find(term) != Glib::ustring::npos) {
+        final_result.insert(note);
+      }
     }
   }
 
   std::vector<Glib::ustring> ret;
-  for(std::set<gnote::Note::Ptr>::iterator iter = final_result.begin(); iter != final_result.end(); ++iter) {
-    ret.push_back((*iter)->uri());
+  for(auto note : final_result) {
+    ret.push_back(note->uri());
   }
 
   return ret;


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