[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) {
|
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 {
|
try {
|
||||||
await client.collections('cards').retrieve();
|
await client.collections('cards').retrieve();
|
||||||
console.log(chalk.yellow('Collection "cards" already exists.'));
|
console.log(chalk.yellow('Collection "cards" already exists.'));
|
||||||
@@ -15,11 +24,11 @@ async function createCollection(client: Client) {
|
|||||||
fields: [
|
fields: [
|
||||||
{ name: 'productId', type: 'int32' },
|
{ name: 'productId', type: 'int32' },
|
||||||
{ name: 'productName', type: 'string' },
|
{ name: 'productName', type: 'string' },
|
||||||
{ name: 'productLineName', type: 'string' },
|
{ name: 'productLineName', type: 'string', facet: true },
|
||||||
{ name: 'rarityName', type: 'string' },
|
{ name: 'rarityName', type: 'string', facet: true },
|
||||||
{ name: 'setName', type: 'string' },
|
{ name: 'setName', type: 'string', facet: true },
|
||||||
{ name: 'cardType', type: 'string' },
|
{ name: 'cardType', type: 'string', facet: true },
|
||||||
{ name: 'energyType', type: 'string' },
|
{ name: 'energyType', type: 'string', facet: true },
|
||||||
{ name: 'number', type: 'string' },
|
{ name: 'number', type: 'string' },
|
||||||
],
|
],
|
||||||
default_sorting_field: 'productId',
|
default_sorting_field: 'productId',
|
||||||
@@ -35,11 +44,7 @@ async function createCollection(client: Client) {
|
|||||||
|
|
||||||
async function preloadSearchIndex() {
|
async function preloadSearchIndex() {
|
||||||
const pokemon = await db.query.cards.findMany({
|
const pokemon = await db.query.cards.findMany({
|
||||||
where: { productLineName: "pokemon" },
|
with: { set: true, }
|
||||||
//limit: 320,
|
|
||||||
with: {
|
|
||||||
set: true,
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Ensure the collection exists before importing documents
|
// 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',
|
query_by: 'productLineName,productName,setName,number,rarityName',
|
||||||
per_page: 250,
|
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
|
// 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({
|
const pokemon = await db.query.cards.findMany({
|
||||||
|
|||||||
Reference in New Issue
Block a user