diff options
author | Richard Hughes <richard@hughsie.com> | 2014-04-08 10:23:21 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2014-04-08 10:23:21 +0100 |
commit | 7741ba78f85492c95a0f515af4c98881a5b8e6de (patch) | |
tree | 3d55b03209c604087ad5f5d2ece7cf9f491e0557 | |
parent | 0e6c11a9dbd683d0361bd961246bb1505938e152 (diff) | |
download | appstream-glib-7741ba78f85492c95a0f515af4c98881a5b8e6de.tar.gz |
Add as_app_search_matches_all()
This allows us to search for all the tokens in a specific AsApp.
-rw-r--r-- | libappstream-glib/as-app.c | 29 | ||||
-rw-r--r-- | libappstream-glib/as-app.h | 2 | ||||
-rw-r--r-- | libappstream-glib/as-self-test.c | 4 |
3 files changed, 35 insertions, 0 deletions
diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c index d917b2b..fdf393b 100644 --- a/libappstream-glib/as-app.c +++ b/libappstream-glib/as-app.c @@ -1750,6 +1750,35 @@ as_app_search_matches (AsApp *app, const gchar *search) } /** + * as_app_search_matches_all: + * @app: a #AsApp instance. + * @search: the search terms. + * + * Searches application data for all the specific keywords. + * + * Returns: a match scrore, where 0 is no match and larger numbers are better + * matches. + * + * Since: 0.1.3 + */ +guint +as_app_search_matches_all (AsApp *app, gchar **values) +{ + guint i; + guint matches_sum = 0; + guint tmp; + + /* do *all* search keywords match */ + for (i = 0; values[i] != NULL; i++) { + tmp = as_app_search_matches (app, values[i]); + if (tmp == 0) + return 0; + matches_sum += tmp; + } + return matches_sum; +} + +/** * as_app_desktop_key_get_locale: */ static gchar * diff --git a/libappstream-glib/as-app.h b/libappstream-glib/as-app.h index 9af0ceb..35a99db 100644 --- a/libappstream-glib/as-app.h +++ b/libappstream-glib/as-app.h @@ -203,6 +203,8 @@ void as_app_remove_metadata (AsApp *app, /* object methods */ void as_app_subsume (AsApp *app, AsApp *donor); +guint as_app_search_matches_all (AsApp *app, + gchar **values); guint as_app_search_matches (AsApp *app, const gchar *search); gboolean as_app_parse_file (AsApp *app, diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c index b863769..e6510d8 100644 --- a/libappstream-glib/as-self-test.c +++ b/libappstream-glib/as-self-test.c @@ -681,6 +681,8 @@ static void ch_test_app_search_func (void) { AsApp *app; + const gchar *all[] = { "gnome", "install", "software", NULL }; + const gchar *none[] = { "gnome", "xxx", "software", NULL }; app = as_app_new (); as_app_set_name (app, NULL, "GNOME Software", -1); @@ -689,6 +691,8 @@ ch_test_app_search_func (void) g_assert_cmpint (as_app_search_matches (app, "software"), ==, 80); g_assert_cmpint (as_app_search_matches (app, "soft"), ==, 80); g_assert_cmpint (as_app_search_matches (app, "install"), ==, 60); + g_assert_cmpint (as_app_search_matches_all (app, (gchar**) all), ==, 220); + g_assert_cmpint (as_app_search_matches_all (app, (gchar**) none), ==, 0); g_object_unref (app); } |