From 538416c22a6ee528fd9fbecea15578c03bcf9b58 Mon Sep 17 00:00:00 2001 From: Thad Miller Date: Thu, 26 Feb 2026 20:44:10 -0500 Subject: [PATCH 1/2] [bugfix] fixed lowestPrice and highestPrice field names in sync-prices --- scripts/sync-prices.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/sync-prices.ts b/scripts/sync-prices.ts index fad6e63..3fb17db 100644 --- a/scripts/sync-prices.ts +++ b/scripts/sync-prices.ts @@ -53,8 +53,8 @@ async function syncPrices() { await db.update(skus) .set({ marketPrice: sku.marketPrice, - lowestPrice: sku.lowPrice, - highestPrice: sku.highPrice, + lowestPrice: sku.lowestPrice, + highestPrice: sku.highestPrice, priceCount: sku.priceCount, calculatedAt: sku.calculatedAt ? new Date(sku.calculatedAt) : null, }) From 2a827fd4f661cf0f0e23b861cd01bde0c1f393cd Mon Sep 17 00:00:00 2001 From: Thad Miller Date: Fri, 27 Feb 2026 09:29:47 -0500 Subject: [PATCH 2/2] [feat] tweaking sort and facet matching --- scripts/reindex.ts | 11 ++++++++--- src/db/relations.ts | 7 +++++++ src/pages/partials/cards.astro | 8 +++++--- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/scripts/reindex.ts b/scripts/reindex.ts index bf28137..7f0fa74 100644 --- a/scripts/reindex.ts +++ b/scripts/reindex.ts @@ -2,6 +2,7 @@ import { Client } from 'typesense'; import chalk from 'chalk'; import { db, poolConnection } from '../src/db/index.ts'; import { client } from '../src/db/typesense.ts'; +import { release } from 'node:os'; async function createCollection(client: Client) { @@ -22,9 +23,10 @@ async function createCollection(client: Client) { await client.collections().create({ name: 'cards', fields: [ + { name: 'cardId', type: 'int32' }, { name: 'productId', type: 'int32' }, - { name: 'variant', type: 'string' }, - { name: 'productName', type: 'string' }, + { name: 'variant', type: 'string', facet: true }, + { name: 'productName', type: 'string', sort: true }, { name: 'productLineName', type: 'string', facet: true }, { name: 'rarityName', type: 'string', facet: true }, { name: 'setName', type: 'string', facet: true }, @@ -33,6 +35,7 @@ async function createCollection(client: Client) { { name: 'number', type: 'string' }, { name: 'Artist', type: 'string' }, { name: 'sealed', type: 'bool' }, + { name: 'releaseDate', type: 'int32'}, ], //default_sorting_field: 'productId', }); @@ -47,13 +50,14 @@ async function createCollection(client: Client) { async function preloadSearchIndex() { const pokemon = await db.query.cards.findMany({ - with: { set: true, } + with: { set: true, tcgdata: true }, }); // Ensure the collection exists before importing documents await createCollection(client); await client.collections('cards').documents().import(pokemon.map(card => ({ + cardId: card.cardId, productId: card.productId, variant: card.variant, productName: card.productName, @@ -65,6 +69,7 @@ async function preloadSearchIndex() { number: card.number, Artist: card.Artist || "", sealed: card.sealed, + releaseDate: card.tcgdata?.releaseDate ? Math.floor(new Date(card.tcgdata.releaseDate).getTime() / 1000) : 0, })), { action: 'upsert' }); console.log(chalk.green('Search index preloaded with Pokémon cards.')); diff --git a/src/db/relations.ts b/src/db/relations.ts index a674e80..73c0bf6 100644 --- a/src/db/relations.ts +++ b/src/db/relations.ts @@ -14,9 +14,16 @@ export const relations = defineRelations(schema, (r) => ({ from: r.cards.setId, to: r.sets.setId, }), + tcgdata: r.one.tcgcards({ + from: r.cards.productId, + to: r.tcgcards.productId, + }), }, sets: { cards: r.many.cards(), }, + tcgcards: { + cards: r.many.cards(), + }, })); diff --git a/src/pages/partials/cards.astro b/src/pages/partials/cards.astro index 419cc01..a1c6efa 100644 --- a/src/pages/partials/cards.astro +++ b/src/pages/partials/cards.astro @@ -33,16 +33,17 @@ const searchResults = await client.collections('cards').documents().search({ filter_by: `sealed:false${filterBy ? ` && ${filterBy}` : ''}`, query_by: 'productLineName,productName,setName,number,rarityName,Artist', per_page: 20, - facet_by: 'productLineName,setName,rarityName,cardType,energyType', + facet_by: 'productLineName,setName,variant,rarityName,cardType,energyType', page: Math.floor(start / 20) + 1, + sort_by: '_text_match:asc, releaseDate:desc, productName:asc', }); -const productIds = searchResults.hits?.map((hit: any) => hit.document.productId) ?? []; +const cardIds = searchResults.hits?.map((hit: any) => hit.document.cardId) ?? []; const totalHits = searchResults.found; const facets = searchResults.facet_counts; // 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: { productId: { in: productIds, }, }, + where: { cardId: { in: cardIds, }, }, with: { prices: true, set: true, @@ -74,6 +75,7 @@ const facetNames = (name:string) => { return { "productLineName": "Product Line", "setName": "Set", + "variant": "Variant", "rarityName": "Rarity", "cardType": "Card Type", "energyType": "Energy Type"