[gnome-builder] plugins/shellcmd: score shellcmd search results



commit 4330939c5db0c7448809d342529dc20095202193
Author: Christian Hergert <chergert redhat com>
Date:   Fri Jul 15 16:22:22 2022 -0700

    plugins/shellcmd: score shellcmd search results

 src/plugins/shellcmd/gbp-shellcmd-search-provider.c | 14 ++++++++++++--
 src/plugins/shellcmd/gbp-shellcmd-search-result.c   |  6 +++++-
 src/plugins/shellcmd/gbp-shellcmd-search-result.h   |  3 ++-
 3 files changed, 19 insertions(+), 4 deletions(-)
---
diff --git a/src/plugins/shellcmd/gbp-shellcmd-search-provider.c 
b/src/plugins/shellcmd/gbp-shellcmd-search-provider.c
index 878f46358..0e6950f55 100644
--- a/src/plugins/shellcmd/gbp-shellcmd-search-provider.c
+++ b/src/plugins/shellcmd/gbp-shellcmd-search-provider.c
@@ -62,7 +62,14 @@ static gpointer
 map_func (gpointer item,
           gpointer user_data)
 {
-  return gbp_shellcmd_search_result_new (item, result_icon);
+  GbpShellcmdRunCommand *run_command = item;
+  const char *keywords = gbp_shellcmd_run_command_get_keywords (run_command);
+  const char *query = user_data;
+  guint prio = 0;
+
+  gtk_source_completion_fuzzy_match (keywords, query, &prio);
+
+  return gbp_shellcmd_search_result_new (item, result_icon, prio);
 }
 
 static void
@@ -92,7 +99,10 @@ gbp_shellcmd_search_provider_search_async (IdeSearchProvider   *provider,
   filter = gtk_custom_filter_new (filter_func, g_strdup (query), g_free);
   list = gtk_filter_list_model_new (g_object_ref (G_LIST_MODEL (self->commands)),
                                     g_object_ref (GTK_FILTER (filter)));
-  map = gtk_map_list_model_new (g_object_ref (G_LIST_MODEL (list)), map_func, NULL, NULL);
+  map = gtk_map_list_model_new (g_object_ref (G_LIST_MODEL (list)),
+                                map_func,
+                                g_strdup (query),
+                                g_free);
 
   ide_task_return_pointer (task, g_steal_pointer (&map), g_object_unref);
 
diff --git a/src/plugins/shellcmd/gbp-shellcmd-search-result.c 
b/src/plugins/shellcmd/gbp-shellcmd-search-result.c
index bd1a411d1..a22600af2 100644
--- a/src/plugins/shellcmd/gbp-shellcmd-search-result.c
+++ b/src/plugins/shellcmd/gbp-shellcmd-search-result.c
@@ -115,12 +115,15 @@ gbp_shellcmd_search_result_init (GbpShellcmdSearchResult *self)
 /**
  * gbp_shellcmd_search_result_new:
  * @run_command: (transfer full): a #GbpShellcmdRunCommand
+ * @gicon: the icon to use
+ * @prio: the score of the match
  *
  * Returns: (transfer full): a new GbpShellcmdSearchResult
  */
 GbpShellcmdSearchResult *
 gbp_shellcmd_search_result_new (GbpShellcmdRunCommand *run_command,
-                                GIcon                 *gicon)
+                                GIcon                 *gicon,
+                                guint                  prio)
 {
   GbpShellcmdSearchResult *self;
   g_autofree char *subtitle = NULL;
@@ -133,6 +136,7 @@ gbp_shellcmd_search_result_new (GbpShellcmdRunCommand *run_command,
                        "title", ide_run_command_get_display_name (IDE_RUN_COMMAND (run_command)),
                        "subtitle", subtitle,
                        "gicon", gicon,
+                       "score", (float)(prio > 0 ? 1. / prio : 0.),
                        NULL);
 
   self->run_command = g_steal_pointer (&run_command);
diff --git a/src/plugins/shellcmd/gbp-shellcmd-search-result.h 
b/src/plugins/shellcmd/gbp-shellcmd-search-result.h
index 67345d335..4ebe618bc 100644
--- a/src/plugins/shellcmd/gbp-shellcmd-search-result.h
+++ b/src/plugins/shellcmd/gbp-shellcmd-search-result.h
@@ -31,6 +31,7 @@ G_BEGIN_DECLS
 G_DECLARE_FINAL_TYPE (GbpShellcmdSearchResult, gbp_shellcmd_search_result, GBP, SHELLCMD_SEARCH_RESULT, 
IdeSearchResult)
 
 GbpShellcmdSearchResult *gbp_shellcmd_search_result_new (GbpShellcmdRunCommand *run_command,
-                                                         GIcon                 *gicon);
+                                                         GIcon                 *gicon,
+                                                         guint                  prio);
 
 G_END_DECLS


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