[feat] moved search to components

This commit is contained in:
2026-02-17 13:42:00 -05:00
parent 85fbaf267f
commit 8918a040b6
2 changed files with 16 additions and 11 deletions

View File

@@ -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