[gnome-software/1364-implement-other-apps-by-author-section-in-app-details-page: 8/15] gs-appstream: Add a helper function to search for other apps
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/1364-implement-other-apps-by-author-section-in-app-details-page: 8/15] gs-appstream: Add a helper function to search for other apps
- Date: Wed, 16 Mar 2022 17:34:41 +0000 (UTC)
commit e8558dde6462b676f884ffac76151b739173c7fc
Author: Milan Crha <mcrha redhat com>
Date: Tue Mar 15 18:16:26 2022 +0100
gs-appstream: Add a helper function to search for other apps
This will be used by the plugins to search in its silo.
lib/gs-appstream.c | 74 ++++++++++++++++++++++++++++++++++++++----------------
lib/gs-appstream.h | 6 +++++
2 files changed, 59 insertions(+), 21 deletions(-)
---
diff --git a/lib/gs-appstream.c b/lib/gs-appstream.c
index 4188c8581..ce9cd4825 100644
--- a/lib/gs-appstream.c
+++ b/lib/gs-appstream.c
@@ -1348,32 +1348,24 @@ gs_appstream_silo_search_component (GPtrArray *array, XbNode *component, const g
return matches_sum;
}
-gboolean
-gs_appstream_search (GsPlugin *plugin,
- XbSilo *silo,
- const gchar * const *values,
- GsAppList *list,
- GCancellable *cancellable,
- GError **error)
+typedef struct _Query {
+ AsSearchTokenMatch match_value;
+ const gchar *xpath;
+} Query;
+
+static gboolean
+gs_appstream_do_search (GsPlugin *plugin,
+ XbSilo *silo,
+ const gchar * const *values,
+ const Query queries[],
+ GsAppList *list,
+ GCancellable *cancellable,
+ GError **error)
{
g_autoptr(GError) error_local = NULL;
g_autoptr(GPtrArray) array = g_ptr_array_new_with_free_func ((GDestroyNotify)
gs_appstream_search_helper_free);
g_autoptr(GPtrArray) components = NULL;
g_autoptr(GTimer) timer = g_timer_new ();
- const struct {
- AsSearchTokenMatch match_value;
- const gchar *xpath;
- } queries[] = {
- { AS_SEARCH_TOKEN_MATCH_MIMETYPE, "mimetypes/mimetype[text()~=stem(?)]" },
- { AS_SEARCH_TOKEN_MATCH_PKGNAME, "pkgname[text()~=stem(?)]" },
- { AS_SEARCH_TOKEN_MATCH_SUMMARY, "summary[text()~=stem(?)]" },
- { AS_SEARCH_TOKEN_MATCH_NAME, "name[text()~=stem(?)]" },
- { AS_SEARCH_TOKEN_MATCH_KEYWORD, "keywords/keyword[text()~=stem(?)]" },
- { AS_SEARCH_TOKEN_MATCH_ID, "id[text()~=stem(?)]" },
- { AS_SEARCH_TOKEN_MATCH_ID, "launchable[text()~=stem(?)]" },
- { AS_SEARCH_TOKEN_MATCH_ORIGIN, "../components[@origin~=stem(?)]" },
- { AS_SEARCH_TOKEN_MATCH_NONE, NULL }
- };
/* add some weighted queries */
for (guint i = 0; queries[i].xpath != NULL; i++) {
@@ -1443,6 +1435,46 @@ gs_appstream_search (GsPlugin *plugin,
return TRUE;
}
+gboolean
+gs_appstream_search (GsPlugin *plugin,
+ XbSilo *silo,
+ const gchar * const *values,
+ GsAppList *list,
+ GCancellable *cancellable,
+ GError **error)
+{
+ const Query queries[] = {
+ { AS_SEARCH_TOKEN_MATCH_MIMETYPE, "mimetypes/mimetype[text()~=stem(?)]" },
+ { AS_SEARCH_TOKEN_MATCH_PKGNAME, "pkgname[text()~=stem(?)]" },
+ { AS_SEARCH_TOKEN_MATCH_SUMMARY, "summary[text()~=stem(?)]" },
+ { AS_SEARCH_TOKEN_MATCH_NAME, "name[text()~=stem(?)]" },
+ { AS_SEARCH_TOKEN_MATCH_KEYWORD, "keywords/keyword[text()~=stem(?)]" },
+ { AS_SEARCH_TOKEN_MATCH_ID, "id[text()~=stem(?)]" },
+ { AS_SEARCH_TOKEN_MATCH_ID, "launchable[text()~=stem(?)]" },
+ { AS_SEARCH_TOKEN_MATCH_ORIGIN, "../components[@origin~=stem(?)]" },
+ { AS_SEARCH_TOKEN_MATCH_NONE, NULL }
+ };
+
+ return gs_appstream_do_search (plugin, silo, values, queries, list, cancellable, error);
+}
+
+gboolean
+gs_appstream_search_other_apps (GsPlugin *plugin,
+ XbSilo *silo,
+ const gchar * const *values,
+ GsAppList *list,
+ GCancellable *cancellable,
+ GError **error)
+{
+ const Query queries[] = {
+ { AS_SEARCH_TOKEN_MATCH_PKGNAME, "developer_name[text()~=stem(?)]" },
+ { AS_SEARCH_TOKEN_MATCH_SUMMARY, "project_group[text()~=stem(?)]" },
+ { AS_SEARCH_TOKEN_MATCH_NONE, NULL }
+ };
+
+ return gs_appstream_do_search (plugin, silo, values, queries, list, cancellable, error);
+}
+
gboolean
gs_appstream_add_category_apps (XbSilo *silo,
GsCategory *category,
diff --git a/lib/gs-appstream.h b/lib/gs-appstream.h
index fbc68a1a4..1264a07b2 100644
--- a/lib/gs-appstream.h
+++ b/lib/gs-appstream.h
@@ -29,6 +29,12 @@ gboolean gs_appstream_search (GsPlugin *plugin,
GsAppList *list,
GCancellable *cancellable,
GError **error);
+gboolean gs_appstream_search_other_apps (GsPlugin *plugin,
+ XbSilo *silo,
+ const gchar * const *values,
+ GsAppList *list,
+ GCancellable *cancellable,
+ GError **error);
gboolean gs_appstream_add_categories (XbSilo *silo,
GPtrArray *list,
GCancellable *cancellable,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]