Skip to content

Commit

Permalink
feat: enable filtering by price
Browse files Browse the repository at this point in the history
  • Loading branch information
bmstefanski committed Feb 19, 2024
1 parent 5ef02ce commit 193f9da
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
20 changes: 18 additions & 2 deletions apps/web/views/Search/Facets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,27 @@ export function Facets({ facetDistribution }: any) {
<div className="grid gap-2">
<Label>
Min price
<input className="ml-2 inline-flex" type="number" value={minPrice || undefined} onChange={(e) => setMinPrice(+e.target.value)} />
<input
className="ml-2 inline-flex"
type="number"
value={minPrice || undefined}
onChange={(e) => {
setMinPrice(+e.target.value)
setPage(1)
}}
/>
</Label>
<Label>
Max price
<input className="ml-2 inline-flex" type="number" value={maxPrice || undefined} onChange={(e) => setMaxPrice(+e.target.value)} />
<input
className="ml-2 inline-flex"
type="number"
value={maxPrice || undefined}
onChange={(e) => {
setMaxPrice(+e.target.value)
setPage(1)
}}
/>
</Label>
</div>
</AccordionContent>
Expand Down
4 changes: 1 addition & 3 deletions apps/web/views/Search/SearchView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,11 @@ export async function SearchView({ searchParams }: { searchParams: Record<string
filter.and().where("minPrice", ComparisonOperators.LessThan, parsedSearchParams.maxPrice)
}

console.log(filter.build())

const meilisearchResults = await index.search(parsedSearchParams.q, {
sort: parsedSearchParams.sortBy ? [parsedSearchParams.sortBy] : undefined,
hitsPerPage: 25,
facets: ["collections.title", "tags", "vendor", "variants.availableForSale", "flatOptions.Size", "flatOptions.Color", "minPrice"],
// filter: "minPrice < 94.0",
filter: filter.build(),
page: parsedSearchParams.page,
})

Expand Down

0 comments on commit 193f9da

Please sign in to comment.