From 2fa0be9d2356da697b72430c5eec9715924779ce Mon Sep 17 00:00:00 2001 From: Thad Miller Date: Thu, 5 Mar 2026 16:08:58 -0500 Subject: [PATCH] [bugfix] combine all search terms to a single indexed field --- scripts/reindex.ts | 2 ++ src/pages/partials/cards.astro | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/scripts/reindex.ts b/scripts/reindex.ts index 78f9144..def98f4 100644 --- a/scripts/reindex.ts +++ b/scripts/reindex.ts @@ -42,6 +42,7 @@ async function createCollection(client: Client) { { name: 'Artist', type: 'string' }, { name: 'sealed', type: 'bool' }, { name: 'releaseDate', type: 'int32'}, + { name: 'content', type: 'string', token_separators: ['/'] }, { name: 'sku_id', type: 'string[]', optional: true, reference: 'skus.id', async_reference: true } ], //default_sorting_field: 'productId', @@ -96,6 +97,7 @@ async function preloadSearchIndex() { number: card.number, Artist: card.Artist || "", sealed: card.sealed, + content: [card.productName,card.productLineName,card.set?.setName || "",card.number,card.rarityName,card.Artist || ""].join(' '), releaseDate: card.tcgdata?.releaseDate ? Math.floor(new Date(card.tcgdata.releaseDate).getTime() / 1000) : 0, sku_id: card.prices.map(price => price.skuId.toString()) })), { action: 'upsert' }); diff --git a/src/pages/partials/cards.astro b/src/pages/partials/cards.astro index 67b3e26..59f8d99 100644 --- a/src/pages/partials/cards.astro +++ b/src/pages/partials/cards.astro @@ -4,6 +4,9 @@ import RarityIcon from '../../components/RarityIcon.astro'; export const prerender = false; +import * as util from 'util'; + + // all the facet fields we want to use for filtering const facetFields:any = { "productLineName": "Product Line", @@ -77,13 +80,18 @@ if (start === 0) { const searchRequests = { searches: searchArray }; const commonSearchParams = { q: query, - query_by: 'productLineName,productName,setName,number,rarityName,Artist', + // query_by: 'productLineName,productName,setName,number,rarityName,Artist', + query_by: 'content' }; // use typesense to search for cards matching the query and return the productIds of the results const searchResults = await client.multiSearch.perform(searchRequests, commonSearchParams); const cardResults = searchResults.results[0] as any; +//console.log(util.inspect(cardResults.hits.map((c:any) => { return { productLineName:c.document.productLineName, productName:c.document.productName, setName:c.document.setName, number:c.document.number, rarityName:c.document.rarityName, Artist:c.document.Artist, text_match:c.text_match, text_match_info:c.text_match_info }; }), { showHidden: true, depth: null })); +//console.log(cardResults); + + const pokemon = cardResults.hits?.map((hit: any) => hit.document) ?? []; const totalHits = cardResults?.found;