diff --git a/src/components/Card.astro b/src/components/Card.astro index 7ec40ae..a95f59f 100644 --- a/src/components/Card.astro +++ b/src/components/Card.astro @@ -1,16 +1,22 @@ --- //import { eq } from 'drizzle-orm'; import { isConditionalExpression } from 'typescript'; +import { client } from '../db/typesense.ts'; import { db } from '../db'; import RarityIcon from './RarityIcon.astro'; //import * as schema from '../db/schema.ts'; -// Get some sample Pokemon data from the database -//const pokemon = await db.select().from(schema.cards).where(eq(schema.cards.productLineName, "pokemon")).limit(256); +const { query } = Astro.props; +const searchResults = await client.collections('cards').documents().search({ + q: query, + query_by: 'productLineName,productName,setName,number,rarityName', + per_page: 250, +}); +const productIds = searchResults.hits?.map(hit => hit.document.productId) ?? []; + +// get pokemon data with prices and set info using searchResults and then query the database for each card to get the prices and set info const pokemon = await db.query.cards.findMany({ - where: { productLineName: "pokemon", }, - orderBy: (cards, { desc }) => [desc(cards.marketPrice)], - limit: 320, + where: { productId: { in: productIds, }, }, with: { prices: true, set: true, diff --git a/src/components/CardGrid.astro b/src/components/CardGrid.astro index 93d37ed..17a228f 100644 --- a/src/components/CardGrid.astro +++ b/src/components/CardGrid.astro @@ -1,6 +1,18 @@ +--- +const { query } = Astro.props; +--- +