[gnome-builder] plugins/menu-search: use strcasestr for search



commit 79f3d0a09184d064ac2f5849f22afb2205f3e7d0
Author: Christian Hergert <chergert redhat com>
Date:   Tue Jul 19 15:03:55 2022 -0700

    plugins/menu-search: use strcasestr for search
    
    We don't really want to use fuzzy search for these, just case-insensitive
    search. Doing fuzzy results in really odd search results we likely don't
    want to have prioritized.

 src/plugins/menu-search/gbp-menu-search-provider.c |  5 ++---
 src/plugins/menu-search/gbp-menu-search-result.c   | 12 ++++++++++++
 2 files changed, 14 insertions(+), 3 deletions(-)
---
diff --git a/src/plugins/menu-search/gbp-menu-search-provider.c 
b/src/plugins/menu-search/gbp-menu-search-provider.c
index a6ab38d4c..c0ef1b649 100644
--- a/src/plugins/menu-search/gbp-menu-search-provider.c
+++ b/src/plugins/menu-search/gbp-menu-search-provider.c
@@ -58,15 +58,14 @@ populate_from_menu_model (GListStore *store,
       g_autofree char *icon_name = NULL;
       g_autofree char *description = NULL;
       g_autofree char *action = NULL;
-      guint prio = 0;
 
       if (!g_menu_model_get_item_attribute (menu, i, "label", "s", &label) ||
           !g_menu_model_get_item_attribute (menu, i, "action", "s", &action) ||
           !g_menu_model_get_item_attribute (menu, i, "description", "s", &description))
         continue;
 
-      if (!gtk_source_completion_fuzzy_match (label, query, &prio) &&
-          !gtk_source_completion_fuzzy_match (description, query, &prio))
+      if (strcasestr (label, query) == NULL &&
+          strcasestr (description, query) == NULL)
         continue;
 
       result = g_object_new (GBP_TYPE_MENU_SEARCH_RESULT,
diff --git a/src/plugins/menu-search/gbp-menu-search-result.c 
b/src/plugins/menu-search/gbp-menu-search-result.c
index 8192324a4..6692b3f7d 100644
--- a/src/plugins/menu-search/gbp-menu-search-result.c
+++ b/src/plugins/menu-search/gbp-menu-search-result.c
@@ -54,6 +54,17 @@ gbp_menu_search_result_activate (IdeSearchResult *result,
   IDE_EXIT;
 }
 
+static gboolean
+gbp_menu_search_result_matches (IdeSearchResult *result,
+                                const char      *query)
+{
+  const char *title = ide_search_result_get_title (result);
+  const char *subtitle = ide_search_result_get_subtitle (result);
+
+  return (title && strcasestr (title, query) != NULL) ||
+         (subtitle && strcasestr (subtitle, query) != NULL);
+}
+
 static void
 gbp_menu_search_result_dispose (GObject *object)
 {
@@ -74,6 +85,7 @@ gbp_menu_search_result_class_init (GbpMenuSearchResultClass *klass)
   object_class->dispose = gbp_menu_search_result_dispose;
 
   search_result_class->activate = gbp_menu_search_result_activate;
+  search_result_class->matches = gbp_menu_search_result_matches;
 }
 
 static void


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