Skip to content

Commit

Permalink
Hide search engine details from public API
Browse files Browse the repository at this point in the history
We still expose the values, as GNOME Software requires this (and to
simplify porting it to the 1.0 API), but in a much more extensible way,
without leaking internals too much.
  • Loading branch information
ximion committed Sep 15, 2023
1 parent 3d46b0d commit eebb0f8
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 31 deletions.
29 changes: 29 additions & 0 deletions src/as-component-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,35 @@ typedef enum {
AS_ORIGIN_KIND_LAST
} AsOriginKind;

/**
* AsSearchTokenMatch:
* @AS_SEARCH_TOKEN_MATCH_NONE: No token matching
* @AS_SEARCH_TOKEN_MATCH_MEDIATYPE: Use the component mediatypes
* @AS_SEARCH_TOKEN_MATCH_PKGNAME: Use the component package name
* @AS_SEARCH_TOKEN_MATCH_ORIGIN: Use the app origin
* @AS_SEARCH_TOKEN_MATCH_DESCRIPTION: Use the component description
* @AS_SEARCH_TOKEN_MATCH_COMMENT: Use the component comment
* @AS_SEARCH_TOKEN_MATCH_NAME: Use the component name
* @AS_SEARCH_TOKEN_MATCH_KEYWORD: Use the component keyword
* @AS_SEARCH_TOKEN_MATCH_ID: Use the component ID
*
* The token match kind, which we want to be exactly 16 bits for storage
* reasons.
**/
typedef enum /*< skip >*/ __attribute__((__packed__)) {
AS_SEARCH_TOKEN_MATCH_NONE = 0,
AS_SEARCH_TOKEN_MATCH_MEDIATYPE = 1 << 0,
AS_SEARCH_TOKEN_MATCH_PKGNAME = 1 << 1,
AS_SEARCH_TOKEN_MATCH_ORIGIN = 1 << 2,
AS_SEARCH_TOKEN_MATCH_DESCRIPTION = 1 << 3,
AS_SEARCH_TOKEN_MATCH_SUMMARY = 1 << 4,
AS_SEARCH_TOKEN_MATCH_KEYWORD = 1 << 5,
AS_SEARCH_TOKEN_MATCH_NAME = 1 << 6,
AS_SEARCH_TOKEN_MATCH_ID = 1 << 7,
/*< private >*/
AS_SEARCH_TOKEN_MATCH_LAST = 0xffff
} AsSearchTokenMatch;

typedef guint16 AsTokenType; /* big enough for both bitshifts */

void as_component_complete (AsComponent *cpt, GPtrArray *icon_paths);
Expand Down
31 changes: 0 additions & 31 deletions src/as-component.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ typedef enum {
AS_COMPONENT_KIND_LAST
} AsComponentKind;

#define AS_COMPONENT_KIND_INPUTMETHOD AS_COMPONENT_KIND_INPUT_METHOD

const gchar *as_component_kind_to_string (AsComponentKind kind);
AsComponentKind as_component_kind_from_string (const gchar *kind_str);

Expand Down Expand Up @@ -197,35 +195,6 @@ typedef enum {
AS_VALUE_FLAG_NO_TRANSLATION_FALLBACK = 1 << 1
} AsValueFlags;

/**
* AsSearchTokenMatch:
* @AS_SEARCH_TOKEN_MATCH_NONE: No token matching
* @AS_SEARCH_TOKEN_MATCH_MEDIATYPE: Use the component mediatypes
* @AS_SEARCH_TOKEN_MATCH_PKGNAME: Use the component package name
* @AS_SEARCH_TOKEN_MATCH_ORIGIN: Use the app origin
* @AS_SEARCH_TOKEN_MATCH_DESCRIPTION: Use the component description
* @AS_SEARCH_TOKEN_MATCH_COMMENT: Use the component comment
* @AS_SEARCH_TOKEN_MATCH_NAME: Use the component name
* @AS_SEARCH_TOKEN_MATCH_KEYWORD: Use the component keyword
* @AS_SEARCH_TOKEN_MATCH_ID: Use the component ID
*
* The token match kind, which we want to be exactly 16 bits for storage
* reasons.
**/
typedef enum /*< skip >*/ __attribute__((__packed__)) {
AS_SEARCH_TOKEN_MATCH_NONE = 0,
AS_SEARCH_TOKEN_MATCH_MEDIATYPE = 1 << 0,
AS_SEARCH_TOKEN_MATCH_PKGNAME = 1 << 1,
AS_SEARCH_TOKEN_MATCH_ORIGIN = 1 << 2,
AS_SEARCH_TOKEN_MATCH_DESCRIPTION = 1 << 3,
AS_SEARCH_TOKEN_MATCH_SUMMARY = 1 << 4,
AS_SEARCH_TOKEN_MATCH_KEYWORD = 1 << 5,
AS_SEARCH_TOKEN_MATCH_NAME = 1 << 6,
AS_SEARCH_TOKEN_MATCH_ID = 1 << 7,
/*< private >*/
AS_SEARCH_TOKEN_MATCH_LAST = 0xffff
} AsSearchTokenMatch;

/**
* AsReleasesKind:
* @AS_RELEASES_KIND_UNKNOWN: Unknown releases type
Expand Down
33 changes: 33 additions & 0 deletions src/as-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -2676,3 +2676,36 @@ as_utils_guess_scope_from_path (const gchar *path)
return AS_COMPONENT_SCOPE_USER;
return AS_COMPONENT_SCOPE_SYSTEM;
}

/**
* as_utils_component_tag_search_weight:
* @tag_name: A tag name in a component element, e.g. "name" or "summary" or "keyword"
*
* Retrieve the raw search token weight for the given tag name that AppStream uses
* internally for searching.
* This can be used to implement separate, but compatible search logic.
*
* Returns: The tag weight used in (fulltext) searches. 0 for lowest weight/unused.
*/
guint16
as_utils_component_tag_search_weight (const gchar *tag_name)
{
if (as_str_equal0 (tag_name, "id"))
return AS_SEARCH_TOKEN_MATCH_ID;
if (as_str_equal0 (tag_name, "name"))
return AS_SEARCH_TOKEN_MATCH_NAME;
if (as_str_equal0 (tag_name, "keyword"))
return AS_SEARCH_TOKEN_MATCH_KEYWORD;
if (as_str_equal0 (tag_name, "summary"))
return AS_SEARCH_TOKEN_MATCH_SUMMARY;
if (as_str_equal0 (tag_name, "description"))
return AS_SEARCH_TOKEN_MATCH_DESCRIPTION;
if (as_str_equal0 (tag_name, "origin"))
return AS_SEARCH_TOKEN_MATCH_ORIGIN;
if (as_str_equal0 (tag_name, "pkgname"))
return AS_SEARCH_TOKEN_MATCH_PKGNAME;
if (as_str_equal0 (tag_name, "mediatype"))
return AS_SEARCH_TOKEN_MATCH_MEDIATYPE;

return AS_SEARCH_TOKEN_MATCH_NONE;
}
2 changes: 2 additions & 0 deletions src/as-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ gboolean as_utils_install_metadata_file (AsMetadataLocation location,

AsComponentScope as_utils_guess_scope_from_path (const gchar *path);

guint16 as_utils_component_tag_search_weight (const gchar *tag_name);

G_END_DECLS

#endif /* __AS_UTILS_H */

0 comments on commit eebb0f8

Please sign in to comment.