[gnome-software] Perform an 'AND' search when using multiple keywords, not an 'OR' search
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Perform an 'AND' search when using multiple keywords, not an 'OR' search
- Date: Wed, 30 Oct 2013 15:07:41 +0000 (UTC)
commit b5f27518bbcbed1f7686b86d48b9627591d9a03e
Author: Richard Hughes <richard hughsie com>
Date: Wed Oct 30 14:37:46 2013 +0000
Perform an 'AND' search when using multiple keywords, not an 'OR' search
src/gs-plugin-loader.c | 6 +++-
src/gs-plugin.h | 4 +-
src/plugins/gs-plugin-appstream.c | 22 ++++++++++++++++-
src/plugins/gs-plugin-dummy.c | 2 +-
src/plugins/gs-plugin-epiphany.c | 36 ++++++++++++++++++++++++++--
src/plugins/gs-plugin-packagekit-search.c | 6 +---
6 files changed, 62 insertions(+), 14 deletions(-)
---
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index e9bf466..113c29d 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -1340,9 +1340,11 @@ gs_plugin_loader_search_thread_cb (GSimpleAsyncResult *res,
GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (object);
GsPlugin *plugin;
GsPluginSearchFunc plugin_func = NULL;
+ gchar **values;
guint i;
/* run each plugin */
+ values = g_str_tokenize_and_fold (state->value, NULL, NULL);
for (i = 0; i < plugin_loader->priv->plugins->len; i++) {
plugin = g_ptr_array_index (plugin_loader->priv->plugins, i);
if (!plugin->enabled)
@@ -1361,7 +1363,7 @@ gs_plugin_loader_search_thread_cb (GSimpleAsyncResult *res,
profile_id = g_strdup_printf ("GsPlugin::%s(%s)",
plugin->name, function_name);
gs_profile_start (plugin_loader->priv->profile, profile_id);
- ret = plugin_func (plugin, state->value, &state->list, cancellable, &error);
+ ret = plugin_func (plugin, values, &state->list, cancellable, &error);
if (!ret) {
gs_plugin_loader_get_all_state_finish (state, error);
g_error_free (error);
@@ -1409,7 +1411,7 @@ gs_plugin_loader_search_thread_cb (GSimpleAsyncResult *res,
state->ret = TRUE;
gs_plugin_loader_get_all_state_finish (state, NULL);
out:
- return;
+ g_strfreev (values);
}
/**
diff --git a/src/gs-plugin.h b/src/gs-plugin.h
index c04e6db..1e0761d 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -102,7 +102,7 @@ typedef const gchar *(*GsPluginGetNameFunc) (void);
typedef gdouble (*GsPluginGetPriorityFunc) (GsPlugin *plugin);
typedef void (*GsPluginFunc) (GsPlugin *plugin);
typedef gboolean (*GsPluginSearchFunc) (GsPlugin *plugin,
- const gchar *value,
+ gchar **value,
GList **list,
GCancellable *cancellable,
GError **error);
@@ -145,7 +145,7 @@ void gs_plugin_status_update (GsPlugin *plugin,
void gs_plugin_updates_changed (GsPlugin *plugin);
const gchar *gs_plugin_status_to_string (GsPluginStatus status);
gboolean gs_plugin_add_search (GsPlugin *plugin,
- const gchar *value,
+ gchar **values,
GList **list,
GCancellable *cancellable,
GError **error);
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index a3bd35a..c2206df 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -709,11 +709,29 @@ out:
}
/**
+ * gs_plugin_appstream_match_item:
+ */
+static gboolean
+gs_plugin_appstream_match_item (AppstreamApp *item, gchar **values)
+{
+ gboolean matches = FALSE;
+ guint i;
+
+ /* does the GsApp match *all* search keywords */
+ for (i = 0; values[i] != NULL; i++) {
+ matches = appstream_app_search_matches (item, values[i]);
+ if (!matches)
+ break;
+ }
+ return matches;
+}
+
+/**
* gs_plugin_add_search:
*/
gboolean
gs_plugin_add_search (GsPlugin *plugin,
- const gchar *value,
+ gchar **values,
GList **list,
GCancellable *cancellable,
GError **error)
@@ -736,7 +754,7 @@ gs_plugin_add_search (GsPlugin *plugin,
array = appstream_cache_get_items (plugin->priv->cache);
for (i = 0; i < array->len; i++) {
item = g_ptr_array_index (array, i);
- if (appstream_app_search_matches (item, value)) {
+ if (gs_plugin_appstream_match_item (item, values)) {
app = gs_app_new (appstream_app_get_id (item));
ret = gs_plugin_refine_item (plugin, app, item, error);
if (!ret)
diff --git a/src/plugins/gs-plugin-dummy.c b/src/plugins/gs-plugin-dummy.c
index 97b569b..81bc6a5 100644
--- a/src/plugins/gs-plugin-dummy.c
+++ b/src/plugins/gs-plugin-dummy.c
@@ -75,7 +75,7 @@ gs_plugin_destroy (GsPlugin *plugin)
*/
gboolean
gs_plugin_add_search (GsPlugin *plugin,
- const gchar *value,
+ gchar **values,
GList **list,
GCancellable *cancellable,
GError **error)
diff --git a/src/plugins/gs-plugin-epiphany.c b/src/plugins/gs-plugin-epiphany.c
index d69a6db..3b6fdb7 100644
--- a/src/plugins/gs-plugin-epiphany.c
+++ b/src/plugins/gs-plugin-epiphany.c
@@ -247,11 +247,42 @@ out:
}
/**
+ * gs_plugin_epiphany_match_app_value:
+ */
+static gboolean
+gs_plugin_epiphany_match_app_value (GsApp *app, const gchar *value)
+{
+ if (strcasestr (gs_app_get_name (app), value) != NULL)
+ return TRUE;
+ if (strcasestr (gs_app_get_summary (app), value) != NULL)
+ return TRUE;
+ return FALSE;
+}
+
+/**
+ * gs_plugin_epiphany_match_app:
+ */
+static gboolean
+gs_plugin_epiphany_match_app (GsApp *app, gchar **values)
+{
+ gboolean matches = FALSE;
+ guint i;
+
+ /* does the GsApp match *all* search keywords */
+ for (i = 0; values[i] != NULL; i++) {
+ matches = gs_plugin_epiphany_match_app_value (app, values[i]);
+ if (!matches)
+ break;
+ }
+ return matches;
+}
+
+/**
* gs_plugin_add_search:
*/
gboolean
gs_plugin_add_search (GsPlugin *plugin,
- const gchar *value,
+ gchar **values,
GList **list,
GCancellable *cancellable,
GError **error)
@@ -271,8 +302,7 @@ gs_plugin_add_search (GsPlugin *plugin,
/* add any matching apps */
for (l = plugin->priv->list; l != NULL; l = l->next) {
app = GS_APP (l->data);
- if (strcasestr (gs_app_get_name (app), value) != NULL ||
- strcasestr (gs_app_get_summary (app), value) != NULL)
+ if (gs_plugin_epiphany_match_app (app, values))
gs_plugin_add_app (list, app);
}
out:
diff --git a/src/plugins/gs-plugin-packagekit-search.c b/src/plugins/gs-plugin-packagekit-search.c
index 77ff5ec..f9cf87a 100644
--- a/src/plugins/gs-plugin-packagekit-search.c
+++ b/src/plugins/gs-plugin-packagekit-search.c
@@ -115,12 +115,11 @@ gs_plugin_packagekit_progress_cb (PkProgress *progress,
*/
gboolean
gs_plugin_add_search (GsPlugin *plugin,
- const gchar *value,
+ gchar **values,
GList **list,
GCancellable *cancellable,
GError **error)
{
- const gchar *values[2] = { NULL, NULL };
gboolean ret = TRUE;
PkBitfield filter;
PkResults *results;
@@ -134,10 +133,9 @@ gs_plugin_add_search (GsPlugin *plugin,
PK_FILTER_ENUM_APPLICATION,
PK_FILTER_ENUM_NOT_COLLECTIONS,
-1);
- values[0] = value;
results = pk_client_search_details (plugin->priv->client,
filter,
- (gchar **) values,
+ values,
cancellable,
gs_plugin_packagekit_progress_cb, plugin,
error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]