[bugfix] combine all search terms to a single indexed field
This commit is contained in:
@@ -42,6 +42,7 @@ async function createCollection(client: Client) {
|
|||||||
{ name: 'Artist', type: 'string' },
|
{ name: 'Artist', type: 'string' },
|
||||||
{ name: 'sealed', type: 'bool' },
|
{ name: 'sealed', type: 'bool' },
|
||||||
{ name: 'releaseDate', type: 'int32'},
|
{ name: 'releaseDate', type: 'int32'},
|
||||||
|
{ name: 'content', type: 'string', token_separators: ['/'] },
|
||||||
{ name: 'sku_id', type: 'string[]', optional: true, reference: 'skus.id', async_reference: true }
|
{ name: 'sku_id', type: 'string[]', optional: true, reference: 'skus.id', async_reference: true }
|
||||||
],
|
],
|
||||||
//default_sorting_field: 'productId',
|
//default_sorting_field: 'productId',
|
||||||
@@ -96,6 +97,7 @@ async function preloadSearchIndex() {
|
|||||||
number: card.number,
|
number: card.number,
|
||||||
Artist: card.Artist || "",
|
Artist: card.Artist || "",
|
||||||
sealed: card.sealed,
|
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,
|
releaseDate: card.tcgdata?.releaseDate ? Math.floor(new Date(card.tcgdata.releaseDate).getTime() / 1000) : 0,
|
||||||
sku_id: card.prices.map(price => price.skuId.toString())
|
sku_id: card.prices.map(price => price.skuId.toString())
|
||||||
})), { action: 'upsert' });
|
})), { action: 'upsert' });
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ import RarityIcon from '../../components/RarityIcon.astro';
|
|||||||
|
|
||||||
export const prerender = false;
|
export const prerender = false;
|
||||||
|
|
||||||
|
import * as util from 'util';
|
||||||
|
|
||||||
|
|
||||||
// all the facet fields we want to use for filtering
|
// all the facet fields we want to use for filtering
|
||||||
const facetFields:any = {
|
const facetFields:any = {
|
||||||
"productLineName": "Product Line",
|
"productLineName": "Product Line",
|
||||||
@@ -77,13 +80,18 @@ if (start === 0) {
|
|||||||
const searchRequests = { searches: searchArray };
|
const searchRequests = { searches: searchArray };
|
||||||
const commonSearchParams = {
|
const commonSearchParams = {
|
||||||
q: query,
|
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
|
// 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 searchResults = await client.multiSearch.perform(searchRequests, commonSearchParams);
|
||||||
const cardResults = searchResults.results[0] as any;
|
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 pokemon = cardResults.hits?.map((hit: any) => hit.document) ?? [];
|
||||||
const totalHits = cardResults?.found;
|
const totalHits = cardResults?.found;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user