Skip to content
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
21 changes: 10 additions & 11 deletions backend/src/queryBuilders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ const escapeRegex = (s: string) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
// Filter values come in as "full_sun", the database has "full sun"
const normalize = (s: string) => escapeRegex(s.replace(/_/g, " ").trim());

// The values each filter can have, from low to high. Must match PLANT_FILTERS in
// frontend/src/components/plantSearchForm/plantFilters.ts
export const FILTER_OPTIONS: Record<FilterParam, string[]> = {
watering: ["minimum", "average", "frequent"],
sunlight: ["full_sun", "part_shade", "filtered_shade"],
careLevel: ["low", "medium", "high"],
};

// Sorted by name A–Z, with _id as a tie-breaker so the order is stable.
// Uses the index from indexes.ts.
const BY_NAME = { commonName: 1, _id: 1 } as const;
Expand Down Expand Up @@ -149,15 +157,6 @@ export const buildPlantFilter = (args: PlantFilterArgs): Filter<PlantDoc> => {
return filter;
};

// The values each filter can have, from low to high, so the watering and
// care level sort orders use them too. Must match PLANT_FILTERS in
// frontend/src/components/plantSearchForm/plantFilters.ts
export const FILTER_OPTIONS: Record<FilterParam, string[]> = {
watering: ["minimum", "average", "frequent"],
sunlight: ["full_sun", "part_shade", "filtered_shade"],
careLevel: ["low", "medium", "high"],
};

// The name of one count in the $facet result, e.g. "watering:minimum"
const facetKey = (param: string, value: string) => `${param}:${value}`;

Expand Down Expand Up @@ -223,8 +222,8 @@ const sunlightIncludes = (text: string): Document => ({
});

// How each preference id maps to the plant attributes. Must match
// frontend/src/components/plantPreferenceChips/PlantPreferenceChips.tsx
// and the preference ids in frontend/src/pages/profile/ProfilePage.tsx.
// PREFERENCE_IDS in frontend/src/types/Preference.ts and getPlantPreferences
// in frontend/src/components/plantCard/plantTraits.ts.
// The data uses "Low" for easy care and both "Medium" and "Moderate".
export const PREFERENCE_MATCHERS: Record<string, Document> = {
minimumWater: { $eq: [lower("$watering"), "minimum"] },
Expand Down
Loading
Loading