mirror of
https://github.com/vercel/commerce.git
synced 2025-05-19 16:07:01 +00:00
implements Orama sorting API
This commit is contained in:
parent
0d801c1ea1
commit
fdf0dbad66
@ -1,6 +1,6 @@
|
||||
import Grid from 'components/grid';
|
||||
import ProductGridItems from 'components/layout/product-grid-items';
|
||||
import { orama } from 'lib/orama';
|
||||
import { orama, parseSorting } from 'lib/orama';
|
||||
import { Product } from 'lib/shopify/types';
|
||||
|
||||
export const runtime = 'edge';
|
||||
@ -16,12 +16,13 @@ export default async function SearchPage({
|
||||
searchParams?: { [key: string]: string | string[] | undefined };
|
||||
}) {
|
||||
const { sort, q: searchValue } = searchParams as { [key: string]: string };
|
||||
// const { sortKey, reverse } = sorting.find((item) => item.slug === sort) || defaultSort;
|
||||
|
||||
const products = await orama.search({
|
||||
term: searchValue,
|
||||
boost: {
|
||||
title: 2
|
||||
},
|
||||
sortBy: parseSorting(sort),
|
||||
limit: 50,
|
||||
})
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
import type { SorterParams } from '@orama/orama'
|
||||
import { OramaClient } from '@oramacloud/client'
|
||||
|
||||
const ORAMA_API_KEY = process.env.NEXT_PUBLIC_ORAMA_API_KEY!
|
||||
@ -13,4 +14,21 @@ export function trimDescription(description: string, maxSize = 80) {
|
||||
return `${description.substring(0, maxSize)}...`
|
||||
}
|
||||
return description
|
||||
}
|
||||
|
||||
export function parseSorting(sorting: string | undefined): SorterParams<any> | undefined {
|
||||
switch (sorting) {
|
||||
case 'price-asc':
|
||||
return {
|
||||
property: 'priceRange.max',
|
||||
order: 'ASC'
|
||||
}
|
||||
case 'price-desc':
|
||||
return {
|
||||
property: 'priceRange.max',
|
||||
order: 'DESC'
|
||||
}
|
||||
default:
|
||||
return undefined
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user