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

Index experiment #4470

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions backend/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def get_categories() -> list[str]:
@router.get("/category/{category}", tags=["app"])
def get_category(
category: schemas.MainCategory,
filter_subcategories: list[str] = Query(None),
exclude_subcategories: list[str] = Query(None),
page: int | None = None,
per_page: int | None = None,
locale: str = "en",
Expand All @@ -35,7 +35,7 @@ def get_category(
return response

result = search.get_by_selected_categories(
[category], filter_subcategories, page, per_page, locale
[category], exclude_subcategories, page, per_page, locale
)

return result
Expand All @@ -45,7 +45,7 @@ def get_category(
def get_subcategory(
category: schemas.MainCategory,
subcategory: str,
filter_subcategories: list[str] = Query(None),
exclude_subcategories: list[str] = Query(None),
page: int | None = None,
per_page: int | None = None,
locale: str = "en",
Expand All @@ -58,7 +58,7 @@ def get_subcategory(
return response

result = search.get_by_selected_category_and_subcategory(
category, subcategory, filter_subcategories, page, per_page, locale
category, subcategory, exclude_subcategories, page, per_page, locale
)

return result
Expand Down
29 changes: 17 additions & 12 deletions backend/app/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def delete_apps(app_id_list):

def get_by_selected_categories(
selected_categories: list[schemas.MainCategory],
filter_subcategories: list[str],
exclude_subcategories: list[str],
page: int | None,
hits_per_page: int | None,
locale: str,
Expand All @@ -105,18 +105,20 @@ def get_by_selected_categories(
f"categories = {category.value}" for category in selected_categories
]

exclude_subcategories_list = [
f"sub_categories NOT IN [{exclude_subcategory}]"
for exclude_subcategory in exclude_subcategories
if exclude_subcategory is not None
]

return _translate_name_and_summary(
locale,
client.index("apps").search(
"",
{
"filter": [
category_list,
(
f"sub_categories NOT IN {filter_subcategories}"
if filter_subcategories is not None
else ""
),
exclude_subcategories_list,
"type IN [console-application, desktop-application]",
"NOT icon IS NULL",
],
Expand All @@ -131,11 +133,18 @@ def get_by_selected_categories(
def get_by_selected_category_and_subcategory(
selected_category: schemas.MainCategory,
selected_subcategory: str,
filter_subcategories: list[str],
exclude_subcategories: list[str],
page: int | None,
hits_per_page: int | None,
locale: str,
):

exclude_subcategories_list = [
f"sub_categories NOT IN [{exclude_subcategory}]"
for exclude_subcategory in exclude_subcategories
if exclude_subcategory is not None
]

return _translate_name_and_summary(
locale,
client.index("apps").search(
Expand All @@ -144,11 +153,7 @@ def get_by_selected_category_and_subcategory(
"filter": [
f"main_categories = {selected_category.value}",
f"sub_categories = {selected_subcategory}",
(
f"sub_categories NOT IN {filter_subcategories}"
if filter_subcategories is not None
else ""
),
exclude_subcategories_list,
"type IN [console-application, desktop-application]",
"NOT icon IS NULL",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import Breadcrumbs from "src/components/Breadcrumbs"
import ApplicationCollection from "../../../../../../src/components/application/Collection"
import { fetchSubcategory } from "../../../../../../src/fetchers"
import {
Category,
categoryToName,
subcategoryToName,
} from "../../../../../../src/types/Category"
Expand All @@ -17,6 +16,7 @@ import {
MeilisearchResponse,
mapAppsIndexToAppstreamListItem,
} from "src/meilisearch"
import { MainCategory } from "src/codegen"

const ApplicationCategory = ({
applications,
Expand All @@ -25,7 +25,7 @@ const ApplicationCategory = ({
}) => {
const { t } = useTranslation()
const router = useRouter()
const category = router.query.category as Category
const category = router.query.category as MainCategory
let categoryName = categoryToName(category, t)
const subcategory = router.query.subcategory as string
let subcategoryName = subcategoryToName(category, subcategory, t)
Expand Down Expand Up @@ -75,7 +75,7 @@ export const getStaticProps: GetStaticProps = async ({ locale, params }) => {
}

const applications = await fetchSubcategory(
params.category as keyof typeof Category,
params.category as keyof typeof MainCategory,
params.subcategory as string,
locale,
params.page as unknown as number,
Expand Down
Loading