[feat] moved search to components
This commit is contained in:
@@ -5,6 +5,15 @@ import { client } from '../src/db/typesense.ts';
|
||||
|
||||
|
||||
async function createCollection(client: Client) {
|
||||
// Delete the collection if it already exists to ensure a clean slate
|
||||
try {
|
||||
const response = await client.collections('cards').delete();
|
||||
console.log(`Collection "cards" deleted successfully:`, response);
|
||||
} catch (error) {
|
||||
console.error(`Error deleting collection "cards":`, error);
|
||||
}
|
||||
|
||||
// Create the collection with the specified schema
|
||||
try {
|
||||
await client.collections('cards').retrieve();
|
||||
console.log(chalk.yellow('Collection "cards" already exists.'));
|
||||
@@ -15,11 +24,11 @@ async function createCollection(client: Client) {
|
||||
fields: [
|
||||
{ name: 'productId', type: 'int32' },
|
||||
{ name: 'productName', type: 'string' },
|
||||
{ name: 'productLineName', type: 'string' },
|
||||
{ name: 'rarityName', type: 'string' },
|
||||
{ name: 'setName', type: 'string' },
|
||||
{ name: 'cardType', type: 'string' },
|
||||
{ name: 'energyType', type: 'string' },
|
||||
{ name: 'productLineName', type: 'string', facet: true },
|
||||
{ name: 'rarityName', type: 'string', facet: true },
|
||||
{ name: 'setName', type: 'string', facet: true },
|
||||
{ name: 'cardType', type: 'string', facet: true },
|
||||
{ name: 'energyType', type: 'string', facet: true },
|
||||
{ name: 'number', type: 'string' },
|
||||
],
|
||||
default_sorting_field: 'productId',
|
||||
@@ -35,11 +44,7 @@ async function createCollection(client: Client) {
|
||||
|
||||
async function preloadSearchIndex() {
|
||||
const pokemon = await db.query.cards.findMany({
|
||||
where: { productLineName: "pokemon" },
|
||||
//limit: 320,
|
||||
with: {
|
||||
set: true,
|
||||
}
|
||||
with: { set: true, }
|
||||
});
|
||||
|
||||
// Ensure the collection exists before importing documents
|
||||
|
||||
@@ -12,7 +12,7 @@ const searchResults = await client.collections('cards').documents().search({
|
||||
query_by: 'productLineName,productName,setName,number,rarityName',
|
||||
per_page: 250,
|
||||
});
|
||||
const productIds = searchResults.hits?.map(hit => hit.document.productId) ?? [];
|
||||
const productIds = searchResults.hits?.map((hit: any) => 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({
|
||||
|
||||
Reference in New Issue
Block a user