mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-09 18:54:04 +02:00
Merge branch 'prefix_match_more_prominence' into 'main'
GDesktopAppInfo: prioritize match_type over match_category when searching apps Closes #3082 See merge request GNOME/glib!3592
This commit is contained in:
@@ -458,7 +458,9 @@ const gchar desktop_key_match_category[N_DESKTOP_KEYS] = {
|
|||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
/* Lower numbers have higher priority.
|
/* Lower numbers have higher priority.
|
||||||
* Prefix match should put before substring match.
|
* Prefix match should put before substring match, independently of
|
||||||
|
* category relevance, i.e. a prefix match in 'Keyword' category will
|
||||||
|
* come before a substring match in a more relevant category like 'Name'.
|
||||||
*/
|
*/
|
||||||
MATCH_TYPE_PREFIX = 1,
|
MATCH_TYPE_PREFIX = 1,
|
||||||
MATCH_TYPE_SUBSTRING = 2
|
MATCH_TYPE_SUBSTRING = 2
|
||||||
@@ -576,7 +578,10 @@ compare_results (gconstpointer a,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (ra->category == rb->category)
|
/* We prioritize prefix matches over category relevance e.g. a prefix match in 'Keyword'
|
||||||
|
* category is better than a substring match in a more relevance category like 'Name'.
|
||||||
|
*/
|
||||||
|
if (ra->match_type != rb->match_type)
|
||||||
return ra->match_type - rb->match_type;
|
return ra->match_type - rb->match_type;
|
||||||
|
|
||||||
return ra->category - rb->category;
|
return ra->category - rb->category;
|
||||||
@@ -590,10 +595,10 @@ compare_categories (gconstpointer a,
|
|||||||
const struct search_result *ra = a;
|
const struct search_result *ra = a;
|
||||||
const struct search_result *rb = b;
|
const struct search_result *rb = b;
|
||||||
|
|
||||||
/* Also compare match types so we can put prefix match in a group while
|
/* We prioritize prefix matches over category relevance e.g. a prefix match in 'Keyword'
|
||||||
* substring match in another group.
|
* category is better than a substring match in a more relevance category like 'Name'.
|
||||||
*/
|
*/
|
||||||
if (ra->category == rb->category)
|
if (ra->match_type != rb->match_type)
|
||||||
return ra->match_type - rb->match_type;
|
return ra->match_type - rb->match_type;
|
||||||
|
|
||||||
return ra->category - rb->category;
|
return ra->category - rb->category;
|
||||||
|
@@ -33,8 +33,28 @@ main (int argc, char **argv)
|
|||||||
{
|
{
|
||||||
setlocale (LC_ALL, "");
|
setlocale (LC_ALL, "");
|
||||||
|
|
||||||
if (argv[1] == NULL)
|
if (argv[1] == NULL || g_str_equal (argv[1], "--help"))
|
||||||
;
|
g_print ("Usage:\n"
|
||||||
|
" apps --help\n"
|
||||||
|
" apps COMMAND [COMMAND_OPTIONS]\n"
|
||||||
|
"\n"
|
||||||
|
"COMMANDS:\n"
|
||||||
|
" list\n"
|
||||||
|
" search [--should-show-only] TEXT_TO_SEARCH\n"
|
||||||
|
" implementations INTERFACE_NAME\n"
|
||||||
|
" show-info DESKTOP_FILE\n"
|
||||||
|
" default-for-type MIME_TYPE\n"
|
||||||
|
" recommended-for-type MIME_TYPE\n"
|
||||||
|
" all-for-type MIME_TYPE\n"
|
||||||
|
" fallback-for-type MIME_TYPE\n"
|
||||||
|
" should-show DESKTOP_FILE\n"
|
||||||
|
" monitor\n"
|
||||||
|
"\n"
|
||||||
|
"Examples:\n"
|
||||||
|
" apps search --should-show-only ter\n"
|
||||||
|
" apps show-info org.gnome.Nautilus.desktop\n"
|
||||||
|
" apps default-for-type image/png\n"
|
||||||
|
"\n");
|
||||||
else if (g_str_equal (argv[1], "list"))
|
else if (g_str_equal (argv[1], "list"))
|
||||||
{
|
{
|
||||||
GList *all, *i;
|
GList *all, *i;
|
||||||
@@ -47,13 +67,31 @@ main (int argc, char **argv)
|
|||||||
else if (g_str_equal (argv[1], "search"))
|
else if (g_str_equal (argv[1], "search"))
|
||||||
{
|
{
|
||||||
gchar ***results;
|
gchar ***results;
|
||||||
|
gboolean should_show_only;
|
||||||
gint i, j;
|
gint i, j;
|
||||||
|
|
||||||
results = g_desktop_app_info_search (argv[2]);
|
should_show_only = argc > 3 && g_str_equal (argv[2], "--should-show-only");
|
||||||
|
results = g_desktop_app_info_search (argv[ should_show_only ? 3 : 2 ]);
|
||||||
for (i = 0; results[i]; i++)
|
for (i = 0; results[i]; i++)
|
||||||
{
|
{
|
||||||
for (j = 0; results[i][j]; j++)
|
for (j = 0; results[i][j]; j++)
|
||||||
g_print ("%s%s", j ? " " : "", results[i][j]);
|
{
|
||||||
|
if (should_show_only)
|
||||||
|
{
|
||||||
|
GDesktopAppInfo *info;
|
||||||
|
gboolean should_show;
|
||||||
|
|
||||||
|
info = g_desktop_app_info_new (results[i][j]);
|
||||||
|
if (info)
|
||||||
|
{
|
||||||
|
should_show = g_app_info_should_show (G_APP_INFO (info));
|
||||||
|
g_object_unref (info);
|
||||||
|
if (!should_show)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g_print ("%s%s", j ? " " : "", results[i][j]);
|
||||||
|
}
|
||||||
g_print ("\n");
|
g_print ("\n");
|
||||||
g_strfreev (results[i]);
|
g_strfreev (results[i]);
|
||||||
}
|
}
|
||||||
|
@@ -888,11 +888,12 @@ test_search (void)
|
|||||||
"gedit.desktop\n", TRUE, TRUE, NULL, NULL);
|
"gedit.desktop\n", TRUE, TRUE, NULL, NULL);
|
||||||
|
|
||||||
/* "con" will match "connect" and "contacts" on name with prefix match in
|
/* "con" will match "connect" and "contacts" on name with prefix match in
|
||||||
* first group, then match "Dconf Editor" and "Desktop Icons" with substring
|
* first group, then second group is a Keyword prefix match for "configuration" in dconf-editor.desktop
|
||||||
* match in next group.
|
* and third group is a substring match for "Desktop Icons" in Name of nautilus-classic.desktop.
|
||||||
*/
|
*/
|
||||||
assert_search ("con", "gnome-contacts.desktop nautilus-connect-server.desktop\n"
|
assert_search ("con", "gnome-contacts.desktop nautilus-connect-server.desktop\n"
|
||||||
"dconf-editor.desktop nautilus-classic.desktop\n", TRUE, TRUE, NULL, NULL);
|
"dconf-editor.desktop\n"
|
||||||
|
"nautilus-classic.desktop\n", TRUE, TRUE, NULL, NULL);
|
||||||
|
|
||||||
/* "gnome" will match "eye of gnome" from the user's directory, plus
|
/* "gnome" will match "eye of gnome" from the user's directory, plus
|
||||||
* matching "GNOME Clocks" X-GNOME-FullName. It's only a comment on
|
* matching "GNOME Clocks" X-GNOME-FullName. It's only a comment on
|
||||||
|
Reference in New Issue
Block a user