Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter search page for Free Software only #1409

Merged
merged 10 commits into from
May 1, 2023
11 changes: 11 additions & 0 deletions backend/app/apps.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import json
import re

import gi
from gi.repository import AppStream

from . import db, search, utils

gi.require_version("AppStream", "1.0")


def load_appstream():
apps = utils.appstream2dict("repo")
Expand All @@ -24,13 +29,19 @@ def load_appstream():

search_keywords = apps[appid].get("keywords")

project_license = apps[appid].get("project_license", "")

# order of the dict is important for attritbute ranking
search_apps.append(
{
"id": utils.get_clean_app_id(appid),
"name": apps[appid]["name"],
"summary": apps[appid]["summary"],
"keywords": search_keywords,
"project_license": project_license,
"is_free_license": AppStream.license_is_free_license(
project_license
),
"app_id": appid,
"description": search_description,
"icon": apps[appid]["icon"],
Expand Down
4 changes: 2 additions & 2 deletions backend/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ def get_appstream(appid: str, response: Response):


@app.get("/search/{userquery}")
def get_search(userquery: str):
return search.search_apps(userquery)
def get_search(userquery: str, free_software_only: bool = False):
return search.search_apps(userquery, free_software_only)


@app.get("/collection/recently-updated")
Expand Down
17 changes: 14 additions & 3 deletions backend/app/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
["name", "summary", "keywords", "description", "id"]
)
client.index("apps").update_filterable_attributes(
["categories", "developer_name", "project_group", "verification_verified"]
[
"categories",
"developer_name",
"project_group",
"verification_verified",
"is_free_license",
]
)


Expand Down Expand Up @@ -124,9 +130,14 @@ def get_by_project_group(project_group: str, page: int, hits_per_page: int):
)


def search_apps(query: str):
def search_apps(query: str, free_software_only: bool = False):
query = unquote(query)

return client.index("apps").search(
query, {"limit": 250, "sort": ["installs_last_month:desc"]}
query,
{
"limit": 250,
"sort": ["installs_last_month:desc"],
"filter": ["is_free_license = true"] if free_software_only else None,
},
)
2 changes: 2 additions & 0 deletions backend/tests/results/test_apps_by_category.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
"description": "Good at finding your way out of hard situations? Let's see! Try to make your way through an increasingly difficult path.",
"id": "org_sugarlabs_Maze",
"installs_last_month": 467,
"is_free_license": true,
"app_id": "org.sugarlabs.Maze",
"icon": "https://dl.flathub.org/repo/appstream/x86_64/icons/128x128/org.sugarlabs.Maze.png",
"categories": [
"Game"
],
"developer_name": "Sugar Labs Community",
"project_group": "SugarLabs",
"project_license": "GPL-3.0-or-later",
"verification_verified": null,
"verification_method": null,
"verification_login_is_organization": null,
Expand Down
68 changes: 35 additions & 33 deletions backend/tests/results/test_apps_by_developer.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
{
"hits": [
{
"name": "Maze",
"summary": "A simple maze game",
"keywords": null,
"description": "Good at finding your way out of hard situations? Let's see! Try to make your way through an increasingly difficult path.",
"id": "org_sugarlabs_Maze",
"installs_last_month": 467,
"app_id": "org.sugarlabs.Maze",
"icon": "https://dl.flathub.org/repo/appstream/x86_64/icons/128x128/org.sugarlabs.Maze.png",
"categories": [
"Game"
],
"developer_name": "Sugar Labs Community",
"project_group": "SugarLabs",
"verification_verified": null,
"verification_method": null,
"verification_login_is_organization": null,
"verification_login_name": null,
"verification_login_provider": null,
"verification_website": null,
"verification_timestamp": null,
"updated_at": 1610973680,
"added_at": 1610973680
}
],
"query": "",
"processingTimeMs": 0,
"hitsPerPage": 250,
"page": 1,
"totalPages": 1,
"totalHits": 1
}
"hits": [
{
"name": "Maze",
"summary": "A simple maze game",
"keywords": null,
"description": "Good at finding your way out of hard situations? Let's see! Try to make your way through an increasingly difficult path.",
"id": "org_sugarlabs_Maze",
"installs_last_month": 467,
"is_free_license": true,
"app_id": "org.sugarlabs.Maze",
"icon": "https://dl.flathub.org/repo/appstream/x86_64/icons/128x128/org.sugarlabs.Maze.png",
"categories": [
"Game"
],
"developer_name": "Sugar Labs Community",
"project_group": "SugarLabs",
"project_license": "GPL-3.0-or-later",
"verification_verified": null,
"verification_method": null,
"verification_login_is_organization": null,
"verification_login_name": null,
"verification_login_provider": null,
"verification_website": null,
"verification_timestamp": null,
"updated_at": 1610973680,
"added_at": 1610973680
}
],
"query": "",
"processingTimeMs": 0,
"hitsPerPage": 250,
"page": 1,
"totalPages": 1,
"totalHits": 1
}
68 changes: 35 additions & 33 deletions backend/tests/results/test_apps_by_projectgroup.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
{
"hits": [
{
"name": "Maze",
"summary": "A simple maze game",
"keywords": null,
"description": "Good at finding your way out of hard situations? Let's see! Try to make your way through an increasingly difficult path.",
"id": "org_sugarlabs_Maze",
"installs_last_month": 467,
"app_id": "org.sugarlabs.Maze",
"icon": "https://dl.flathub.org/repo/appstream/x86_64/icons/128x128/org.sugarlabs.Maze.png",
"categories": [
"Game"
],
"developer_name": "Sugar Labs Community",
"project_group": "SugarLabs",
"verification_verified": null,
"verification_method": null,
"verification_login_is_organization": null,
"verification_login_name": null,
"verification_login_provider": null,
"verification_website": null,
"verification_timestamp": null,
"updated_at": 1610973680,
"added_at": 1610973680
}
],
"query": "",
"processingTimeMs": 0,
"hitsPerPage": 250,
"page": 1,
"totalPages": 1,
"totalHits": 1
}
"hits": [
{
"name": "Maze",
"summary": "A simple maze game",
"keywords": null,
"description": "Good at finding your way out of hard situations? Let's see! Try to make your way through an increasingly difficult path.",
"id": "org_sugarlabs_Maze",
"installs_last_month": 467,
"is_free_license": true,
"app_id": "org.sugarlabs.Maze",
"icon": "https://dl.flathub.org/repo/appstream/x86_64/icons/128x128/org.sugarlabs.Maze.png",
"categories": [
"Game"
],
"developer_name": "Sugar Labs Community",
"project_group": "SugarLabs",
"project_license": "GPL-3.0-or-later",
"verification_verified": null,
"verification_method": null,
"verification_login_is_organization": null,
"verification_login_name": null,
"verification_login_provider": null,
"verification_website": null,
"verification_timestamp": null,
"updated_at": 1610973680,
"added_at": 1610973680
}
],
"query": "",
"processingTimeMs": 0,
"hitsPerPage": 250,
"page": 1,
"totalPages": 1,
"totalHits": 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
"description": "AnyDesk ensures secure and reliable remote desktop connections for IT professionals and on-the-go individuals alike.NOTE: This wrapper is not verified by, affiliated with, or supported by AnyDesk.",
"id": "com_anydesk_Anydesk",
"installs_last_month": 613,
"is_free_license": false,
"app_id": "com.anydesk.Anydesk",
"icon": "https://dl.flathub.org/repo/appstream/x86_64/icons/128x128/com.anydesk.Anydesk.png",
"categories": [
"Network"
],
"developer_name": "AnyDesk Software GmbH",
"project_group": null,
"project_license": "LicenseRef-proprietary",
"verification_verified": null,
"verification_method": null,
"verification_login_is_organization": null,
Expand All @@ -31,4 +33,4 @@
"page": 1,
"totalPages": 3,
"totalHits": 3
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
"description": "AnyDesk ensures secure and reliable remote desktop connections for IT professionals and on-the-go individuals alike.NOTE: This wrapper is not verified by, affiliated with, or supported by AnyDesk.",
"id": "com_anydesk_Anydesk",
"installs_last_month": 613,
"is_free_license": false,
"app_id": "com.anydesk.Anydesk",
"icon": "https://dl.flathub.org/repo/appstream/x86_64/icons/128x128/com.anydesk.Anydesk.png",
"categories": [
"Network"
],
"developer_name": "AnyDesk Software GmbH",
"project_group": null,
"project_license": "LicenseRef-proprietary",
"verification_verified": null,
"verification_method": null,
"verification_login_is_organization": null,
Expand All @@ -31,13 +33,15 @@
"description": "WPS Office including Writer, Presentation and Spreadsheets, is a powerful office suite, which is able to process word file, produce wonderful slides, and analyze data as well. It is deeply compatible with all of the latest Microsoft Office file formats. It can easily open and read the documents created with Microsoft Office.NOTE: This wrapper is not verified by, affiliated with, or supported by Kingsoft Office Corporation",
"id": "com_wps_Office",
"installs_last_month": 668,
"is_free_license": false,
"app_id": "com.wps.Office",
"icon": "https://www.wps.com/assets/mediahub/WPS-Office-Mobile.png",
"categories": [
"Office"
],
"developer_name": "Kingsoft Office Corporation",
"project_group": null,
"project_license": "LicenseRef-proprietary=http://wps-community.org/license.md",
"verification_verified": null,
"verification_method": null,
"verification_login_is_organization": null,
Expand All @@ -55,13 +59,15 @@
"description": "Good at finding your way out of hard situations? Let's see! Try to make your way through an increasingly difficult path.",
"id": "org_sugarlabs_Maze",
"installs_last_month": 467,
"is_free_license": true,
"app_id": "org.sugarlabs.Maze",
"icon": "https://dl.flathub.org/repo/appstream/x86_64/icons/128x128/org.sugarlabs.Maze.png",
"categories": [
"Game"
],
"developer_name": "Sugar Labs Community",
"project_group": "SugarLabs",
"project_license": "GPL-3.0-or-later",
"verification_verified": null,
"verification_method": null,
"verification_login_is_organization": null,
Expand All @@ -79,4 +85,4 @@
"page": 1,
"totalPages": 1,
"totalHits": 3
}
}
Loading