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

Boost service discovery (tile) results based on boosted category. #1392

Merged
merged 2 commits into from
Aug 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
33 changes: 23 additions & 10 deletions app/pages/ServiceDiscoveryResults/ServiceDiscoveryResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Sidebar from "components/search/Sidebar/Sidebar";
import { Header } from "components/search/Header/Header";
import { Category } from "models/Meta";

import whitelabel from "utils/whitelabel";
import {
useEligibilitiesForCategory,
useSubcategoriesForCategory,
Expand All @@ -26,6 +27,7 @@ import styles from "./ServiceDiscoveryResults.module.scss";
type MatchParams = { categorySlug: string };
type RouterLocation = RouteComponentProps["location"];
type SearchState = {
refinementList?: { categories?: string[] };
configure?: {
aroundRadius?: string;
};
Expand Down Expand Up @@ -148,6 +150,26 @@ const InnerServiceDiscoveryResults = ({
sortAlgoliaSubcategoryRefinements,
} = category;

const configureProps: Record<string, any> = {
filters: `categories:'${algoliaCategoryName}'`,
};
if (!category.disableGeoLocation) {
Object.assign(configureProps, {
aroundLatLng: `${location.lat}, ${location.lng}`,
aroundRadius: searchRadius,
aroundPrecision: 1600,
});
}
if (whitelabel.useBoostedCategories) {
const selectedSubcategories = searchState.refinementList?.categories ?? [];
configureProps.optionalFilters = subcategoryNames
.filter((x) => selectedSubcategories.includes(x))
.map((x) => `boosted_category:${x}`)
// Our Algolia plan only allows for up to one optional filter, so just
// drop all but the first.
.slice(0, 1);
}

return (
<div className={styles.container}>
<Helmet>
Expand All @@ -169,16 +191,7 @@ const InnerServiceDiscoveryResults = ({
searchState={searchState}
onSearchStateChange={onSearchStateChange}
>
{category.disableGeoLocation ? (
<Configure filters={`categories:'${algoliaCategoryName}'`} />
) : (
<Configure
filters={`categories:'${algoliaCategoryName}'`}
aroundLatLng={`${location.lat}, ${location.lng}`}
aroundRadius={searchRadius}
aroundPrecision={1600}
/>
)}
<Configure {...configureProps} />
<div className={styles.flexContainer}>
<Sidebar
setSearchRadius={setSearchRadius}
Expand Down
4 changes: 4 additions & 0 deletions app/utils/whitelabel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ interface WhiteLabelSite {
siteNavStyle: string;
siteUrl: string;
title: string;
useBoostedCategories: boolean;
userWay: boolean;
weGlot?: {
apiKey: string;
Expand Down Expand Up @@ -120,6 +121,7 @@ services and re-entry programs.`,
showSearch: true,
showReportCrisis: false,
siteNavStyle: styles.siteNav,
useBoostedCategories: false,
userWay: false,
} as const;

Expand Down Expand Up @@ -177,6 +179,7 @@ const SFServiceGuide: WhiteLabelSite = {
showBreakingNews: true,
title: "SF Service Guide",
showReportCrisis: true,
useBoostedCategories: true,
} as const;

const LinkSF: WhiteLabelSite = {
Expand Down Expand Up @@ -205,6 +208,7 @@ const defaultWhiteLabel: WhiteLabelSite = {
showBreakingNews: true,
title: "SF Service Guide",
showReportCrisis: true,
useBoostedCategories: true,
} as const;

const Ucsf: WhiteLabelSite = {
Expand Down
Loading