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

Allow search to show other types when asked #4309

Merged
merged 1 commit into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 13 additions & 26 deletions backend/app/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ class AppType(str, Enum):


def add_to_search(app_id: str, app: dict, apps_locale: dict) -> dict:
search_description = re.sub(clean_html_re, "", app["description"])
search_description = (
re.sub(clean_html_re, "", app["description"])
if app and app.get("description")
else ""
)

search_keywords = app.get("keywords")

Expand Down Expand Up @@ -100,22 +104,6 @@ def add_to_search(app_id: str, app: dict, apps_locale: dict) -> dict:
}


# keep in sync with db.is_appid_for_frontend
def show_in_frontend(app: dict) -> bool:
# this is executed before we normalize the desktop type to desktop-application
if app.get("type") in ("desktop-application", "desktop"):
return True

if (
app.get("type") == "console-application"
and app.get("icon")
and app.get("screenshots")
):
return True

return False


def load_appstream(sqldb) -> None:
apps = utils.appstream2dict()

Expand All @@ -130,17 +118,16 @@ def load_appstream(sqldb) -> None:
for app_id in apps:
redis_key = f"apps:{app_id}"

if show_in_frontend(apps[app_id]):
search_apps.append(
add_to_search(
app_id,
apps[app_id],
apps[app_id]["locales"],
)
search_apps.append(
add_to_search(
app_id,
apps[app_id],
apps[app_id]["locales"],
)
)

if developer_name := apps[app_id].get("developer_name"):
p.sadd("developers:index", developer_name)
if developer_name := apps[app_id].get("developer_name"):
p.sadd("developers:index", developer_name)

if type := apps[app_id].get("type"):
# "desktop" dates back to appstream-glib, need to handle that for backwards compat
Expand Down
65 changes: 57 additions & 8 deletions backend/app/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class SearchQuery(BaseModel):
"runtime",
"type",
"arches",
"icon",
]
)

Expand Down Expand Up @@ -106,7 +107,11 @@ def get_by_selected_categories(
client.index("apps").search(
"",
{
"filter": [category_list],
"filter": [
category_list,
"type IN [console-application, desktop-application]",
"NOT icon IS NULL",
],
"sort": ["installs_last_month:desc"],
"hitsPerPage": hits_per_page or 250,
"page": page or 1,
Expand All @@ -130,6 +135,8 @@ def get_by_selected_category_and_subcategory(
"filter": [
f"main_categories = {selected_category.value}",
f"sub_categories = {selected_subcategory}",
"type IN [console-application, desktop-application]",
"NOT icon IS NULL",
],
"sort": ["installs_last_month:desc"],
"hitsPerPage": hits_per_page or 250,
Expand All @@ -150,6 +157,10 @@ def get_by_installs_last_month(
"sort": ["installs_last_month:desc"],
"hitsPerPage": hits_per_page or 250,
"page": page or 1,
"filter": [
"type IN [console-application, desktop-application]",
"NOT icon IS NULL",
],
},
),
)
Expand All @@ -164,6 +175,10 @@ def get_by_trending(page: int | None, hits_per_page: int | None, locale: str):
"sort": ["trending:desc"],
"hitsPerPage": hits_per_page or 250,
"page": page or 1,
"filter": [
"type IN [console-application, desktop-application]",
"NOT icon IS NULL",
],
},
),
)
Expand All @@ -178,6 +193,10 @@ def get_by_added_at(page: int | None, hits_per_page: int | None, locale: str):
"sort": ["added_at:desc"],
"hitsPerPage": hits_per_page or 250,
"page": page or 1,
"filter": [
"type IN [console-application, desktop-application]",
"NOT icon IS NULL",
],
},
),
)
Expand All @@ -192,6 +211,10 @@ def get_by_updated_at(page: int | None, hits_per_page: int | None, locale: str):
"sort": ["updated_at:desc"],
"hitsPerPage": hits_per_page or 250,
"page": page or 1,
"filter": [
"type IN [console-application, desktop-application]",
"NOT icon IS NULL",
],
},
),
)
Expand All @@ -203,7 +226,11 @@ def get_by_verified(page: int | None, hits_per_page: int | None, locale: str):
client.index("apps").search(
"",
{
"filter": ["verification_verified = true"],
"filter": [
"verification_verified = true",
"type IN [console-application, desktop-application]",
"NOT icon IS NULL",
],
"sort": ["verification_timestamp:desc"],
"hitsPerPage": hits_per_page or 250,
"page": page or 1,
Expand All @@ -224,7 +251,11 @@ def get_by_developer(
client.index("apps").search(
"",
{
"filter": [f"developer_name = '{escaped_developer}'"],
"filter": [
f"developer_name = '{escaped_developer}'",
"type IN [console-application, desktop-application]",
"NOT icon IS NULL",
],
"sort": ["installs_last_month:desc"],
"hitsPerPage": hits_per_page or 250,
"page": page or 1,
Expand All @@ -237,25 +268,43 @@ def get_by_developer(
def search_apps(query: str, locale: str, free_software_only: bool = False):
query = unquote(query)

filters = ["type in desktop-application, console-application"]

if free_software_only:
filters.append("is_free_license = true")

return _translate_name_and_summary(
locale,
client.index("apps").search(
query,
{
"limit": 250,
"sort": ["installs_last_month:desc"],
"filter": ["is_free_license = true"] if free_software_only else None,
},
{"limit": 250, "sort": ["installs_last_month:desc"], "filter": filters},
),
)


def search_apps_post(searchquery: SearchQuery, locale: str):
filters = []

filteringForType = False
filteringForDesktopOrConsole = False

for filter in searchquery.filters or []:
if filter.filterType == "type":
filteringForType = True

if filter.value == "desktop-application":
filteringForDesktopOrConsole = True
elif filter.value == "console-application":
filteringForDesktopOrConsole = True

filters.append(f"{filter.filterType} = '{filter.value}'")

if not filteringForType and not filteringForDesktopOrConsole:
filters.append("type IN [desktop-application, console-application]")

if not (filteringForType and not filteringForDesktopOrConsole):
filters.append("NOT icon IS NULL")

filterString = " AND ".join(filters)

return _translate_name_and_summary(
Expand Down
4 changes: 0 additions & 4 deletions backend/app/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,6 @@ def update(sqldb) -> None:
if app_id not in current_apps:
continue

if not db.is_appid_for_frontend(app_id):
continue

updated.append(
{
"id": utils.get_clean_app_id(app_id),
Expand All @@ -233,7 +230,6 @@ def update(sqldb) -> None:
"arches": list(summary_dict[app_id]["arches"]),
}
for app_id in summary_dict
if db.is_appid_for_frontend(app_id)
]
)

Expand Down
6 changes: 0 additions & 6 deletions backend/app/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ def update():
apps_created_at = {}

for app_id in current_apps:
if not db.is_appid_for_frontend(app_id):
continue

with WorkerDB() as sqldb:
created_at = (
sqldb.session.query(models.Apps.initial_release_at)
Expand Down Expand Up @@ -109,9 +106,6 @@ def update():
if app_id not in current_apps:
continue

if not db.is_appid_for_frontend(app_id):
continue

search_added_at.append(
{
"id": utils.get_clean_app_id(app_id),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
<summary>WPS Office Suite</summary>
<developer_name>Kingsoft Office Corporation</developer_name>
<description><p>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.</p><p>NOTE: This wrapper is not verified by, affiliated with, or supported by Kingsoft Office Corporation</p></description>
<icon type="remote">https://www.wps.com/assets/mediahub/WPS-Office-Mobile.png</icon>
<icon type="cached" height="128" width="128">com.wps.Office.png</icon>
<categories>
<category>Office</category>
</categories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"project_license": "LicenseRef-proprietary=http://wps-community.org/license.md",
"is_free_license": false,
"app_id": "com.wps.Office",
"icon": null,
"icon": "https://dl.flathub.org/repo/appstream/x86_64/icons/128x128/com.wps.Office.png",
"categories": [
"Office"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"project_license": "LicenseRef-proprietary=http://wps-community.org/license.md",
"is_free_license": false,
"app_id": "com.wps.Office",
"icon": null,
"icon": "https://dl.flathub.org/repo/appstream/x86_64/icons/128x128/com.wps.Office.png",
"categories": [
"Office"
],
Expand Down Expand Up @@ -119,4 +119,4 @@
"page": 1,
"totalPages": 1,
"totalHits": 3
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"project_license": "LicenseRef-proprietary=http://wps-community.org/license.md",
"is_free_license": false,
"app_id": "com.wps.Office",
"icon": null,
"icon": "https://dl.flathub.org/repo/appstream/x86_64/icons/128x128/com.wps.Office.png",
"categories": [
"Office"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"project_license": "LicenseRef-proprietary=http://wps-community.org/license.md",
"is_free_license": false,
"app_id": "com.wps.Office",
"icon": null,
"icon": "https://dl.flathub.org/repo/appstream/x86_64/icons/128x128/com.wps.Office.png",
"categories": [
"Office"
],
Expand Down Expand Up @@ -119,4 +119,4 @@
"page": 1,
"totalPages": 1,
"totalHits": 3
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"project_license": "LicenseRef-proprietary=http://wps-community.org/license.md",
"is_free_license": false,
"app_id": "com.wps.Office",
"icon": null,
"icon": "https://dl.flathub.org/repo/appstream/x86_64/icons/128x128/com.wps.Office.png",
"categories": [
"Office"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"project_license": "LicenseRef-proprietary=http://wps-community.org/license.md",
"is_free_license": false,
"app_id": "com.wps.Office",
"icon": null,
"icon": "https://dl.flathub.org/repo/appstream/x86_64/icons/128x128/com.wps.Office.png",
"categories": [
"Office"
],
Expand Down Expand Up @@ -119,4 +119,4 @@
"page": 1,
"totalPages": 1,
"totalHits": 3
}
}
7 changes: 7 additions & 0 deletions frontend/pages/apps/search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ export default function Search({ locale }) {
})
}

if (query.type) {
filtersFromQuery.push({
filterType: "type",
value: query.type as string,
})
}

const [selectedFilters, setSelectedFilters] = useState<
{
filterType: string
Expand Down
Loading
Loading