[feat] rework card number to be int32 for sorting
This commit is contained in:
@@ -62,7 +62,8 @@ export const createCardCollection = async (log: Logger = defaultLogger) => {
|
|||||||
{ name: 'setCode', type: 'string' },
|
{ name: 'setCode', type: 'string' },
|
||||||
{ name: 'cardType', type: 'string', facet: true },
|
{ name: 'cardType', type: 'string', facet: true },
|
||||||
{ name: 'energyType', type: 'string', facet: true },
|
{ name: 'energyType', type: 'string', facet: true },
|
||||||
{ name: 'number', type: 'string', sort: true },
|
{ name: 'number', type: 'string' },
|
||||||
|
{ name: 'inumber', type: 'int32', optional: true, sort: true },
|
||||||
{ name: 'Artist', type: 'string' },
|
{ name: 'Artist', type: 'string' },
|
||||||
{ name: 'sealed', type: 'bool' },
|
{ name: 'sealed', type: 'bool' },
|
||||||
{ name: 'releaseDate', type: 'int32' },
|
{ name: 'releaseDate', type: 'int32' },
|
||||||
@@ -152,6 +153,7 @@ export const upsertCardCollection = async (db:DBInstance, log: Logger = defaultL
|
|||||||
cardType: card.cardType || "",
|
cardType: card.cardType || "",
|
||||||
energyType: card.energyType || "",
|
energyType: card.energyType || "",
|
||||||
number: card.number,
|
number: card.number,
|
||||||
|
inumber: (card.number !== null) ? parseInt(card.number) : undefined,
|
||||||
Artist: card.artist || "",
|
Artist: card.artist || "",
|
||||||
sealed: card.sealed,
|
sealed: card.sealed,
|
||||||
content: [card.productName, card.productLineName, card.set?.setName || "", card.set?.setCode || "", card.number, card.rarityName, card.artist || ""].join(' '),
|
content: [card.productName, card.productLineName, card.set?.setName || "", card.set?.setCode || "", card.number, card.rarityName, card.artist || ""].join(' '),
|
||||||
@@ -212,14 +214,16 @@ export const UpdateVariants = async (db:DBInstance, log: Logger = (m) => console
|
|||||||
const updates = await db.execute(sql`update cards as c
|
const updates = await db.execute(sql`update cards as c
|
||||||
set
|
set
|
||||||
product_name = a.product_name, product_line_name = a.product_line_name, product_url_name = a.product_url_name, rarity_name = a.rarity_name,
|
product_name = a.product_name, product_line_name = a.product_line_name, product_url_name = a.product_url_name, rarity_name = a.rarity_name,
|
||||||
sealed = a.sealed, set_id = a.set_id, card_type = a.card_type, energy_type = a.energy_type, number = a.number, artist = a.artist
|
sealed = a.sealed, set_id = a.set_id, card_type = a.card_type, energy_type = a.energy_type, number = a.number, inumber = a.inumber, artist = a.artist
|
||||||
from (
|
from (
|
||||||
select t.product_id, b.variant,
|
select t.product_id, b.variant,
|
||||||
coalesce(o.product_name, regexp_replace(regexp_replace(coalesce(nullif(t.product_name, ''), t.product_url_name),' \\\\(.*\\\\)',''),' - .*$','')) as product_name,
|
coalesce(o.product_name, regexp_replace(regexp_replace(coalesce(nullif(t.product_name, ''), t.product_url_name),' \\\\(.*\\\\)',''),' - .*$','')) as product_name,
|
||||||
coalesce(o.product_line_name, t.product_line_name) as product_line_name, coalesce(o.product_url_name, t.product_url_name) as product_url_name,
|
coalesce(o.product_line_name, t.product_line_name) as product_line_name, coalesce(o.product_url_name, t.product_url_name) as product_url_name,
|
||||||
coalesce(o.rarity_name, t.rarity_name) as rarity_name, coalesce(o.sealed, t.sealed) as sealed, coalesce(o.set_id, t.set_id) as set_id,
|
coalesce(o.rarity_name, t.rarity_name) as rarity_name, coalesce(o.sealed, t.sealed) as sealed, coalesce(o.set_id, t.set_id) as set_id,
|
||||||
coalesce(o.card_type, t.card_type) as card_type, coalesce(o.energy_type, t.energy_type) as energy_type,
|
coalesce(o.card_type, t.card_type) as card_type, coalesce(o.energy_type, t.energy_type) as energy_type,
|
||||||
coalesce(o.number, regexp_replace(t.number,'^0+','')) as number, coalesce(o.artist, t.artist) as artist
|
coalesce(o.number, regexp_replace(t.number,'^0+','')) as number,
|
||||||
|
nullif(regexp_replace(regexp_replace(coalesce(o.number,t.number),'/.*',''),'[^0-9]','','g'),'')::integer as inumber,
|
||||||
|
coalesce(o.artist, t.artist) as artist
|
||||||
from tcg_cards t
|
from tcg_cards t
|
||||||
join (select distinct product_id, variant from skus) b on t.product_id = b.product_id
|
join (select distinct product_id, variant from skus) b on t.product_id = b.product_id
|
||||||
left join tcg_overrides o on t.product_id = o.product_id
|
left join tcg_overrides o on t.product_id = o.product_id
|
||||||
@@ -234,12 +238,13 @@ where c.product_id = a.product_id and c.variant = a.variant and
|
|||||||
`);
|
`);
|
||||||
log(`Updated ${updates.rowCount} rows in cards table`);
|
log(`Updated ${updates.rowCount} rows in cards table`);
|
||||||
|
|
||||||
const inserts = await db.execute(sql`insert into cards (product_id, variant, product_name, product_line_name, product_url_name, rarity_name, sealed, set_id, card_type, energy_type, "number", artist)
|
const inserts = await db.execute(sql`insert into cards (product_id, variant, product_name, product_line_name, product_url_name, rarity_name, sealed, set_id, card_type, energy_type, "number", inumber, artist)
|
||||||
select t.product_id, b.variant,
|
select t.product_id, b.variant,
|
||||||
coalesce(o.product_name, regexp_replace(regexp_replace(coalesce(nullif(t.product_name, ''), t.product_url_name),' \\\\(.*\\\\)',''),' - .*$','')) as product_name,
|
coalesce(o.product_name, regexp_replace(regexp_replace(coalesce(nullif(t.product_name, ''), t.product_url_name),' \\\\(.*\\\\)',''),' - .*$','')) as product_name,
|
||||||
coalesce(o.product_line_name, t.product_line_name) as product_line_name, coalesce(o.product_url_name, t.product_url_name) as product_url_name, coalesce(o.rarity_name, t.rarity_name) as rarity_name,
|
coalesce(o.product_line_name, t.product_line_name) as product_line_name, coalesce(o.product_url_name, t.product_url_name) as product_url_name, coalesce(o.rarity_name, t.rarity_name) as rarity_name,
|
||||||
coalesce(o.sealed, t.sealed) as sealed, coalesce(o.set_id, t.set_id) as set_id, coalesce(o.card_type, t.card_type) as card_type,
|
coalesce(o.sealed, t.sealed) as sealed, coalesce(o.set_id, t.set_id) as set_id, coalesce(o.card_type, t.card_type) as card_type,
|
||||||
coalesce(o.energy_type, t.energy_type) as energy_type, coalesce(o.number, regexp_replace(t.number,'^0+','')) as number, coalesce(o.artist, t.artist) as artist
|
coalesce(o.energy_type, t.energy_type) as energy_type, coalesce(o.number, regexp_replace(t.number,'^0+','')) as number,
|
||||||
|
nullif(regexp_replace(regexp_replace(coalesce(o.number,t.number),'/.*',''),'[^0-9]','','g'),'')::integer as inumber, coalesce(o.artist, t.artist) as artist
|
||||||
from tcg_cards t
|
from tcg_cards t
|
||||||
join (select distinct product_id, variant from skus) b on t.product_id = b.product_id
|
join (select distinct product_id, variant from skus) b on t.product_id = b.product_id
|
||||||
left join tcg_overrides o on t.product_id = o.product_id
|
left join tcg_overrides o on t.product_id = o.product_id
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ export const cards = pokeSchema.table('cards', {
|
|||||||
cardType: varchar({ length: 100 }),
|
cardType: varchar({ length: 100 }),
|
||||||
energyType: varchar({ length: 100 }),
|
energyType: varchar({ length: 100 }),
|
||||||
number: varchar({ length: 50 }),
|
number: varchar({ length: 50 }),
|
||||||
|
inumber: integer(),
|
||||||
artist: varchar({ length: 255 }),
|
artist: varchar({ length: 255 }),
|
||||||
},
|
},
|
||||||
(table) => [
|
(table) => [
|
||||||
|
|||||||
@@ -22,14 +22,14 @@ const facetFields:any = {
|
|||||||
|
|
||||||
// ── Allowed sort values ───────────────────────────────────────────────────
|
// ── Allowed sort values ───────────────────────────────────────────────────
|
||||||
const sortMap: Record<string, string> = {
|
const sortMap: Record<string, string> = {
|
||||||
'releaseDate:desc,number:asc': '_text_match:asc,releaseDate:desc,number:asc',
|
'releaseDate:desc,number:asc': '_text_match:asc,releaseDate:desc,inumber(missing_values:last):asc',
|
||||||
'releaseDate:asc,number:asc': '_text_match:asc,releaseDate:asc,number:asc',
|
'releaseDate:asc,number:asc': '_text_match:asc,releaseDate:asc,inumber(missing_values:last):asc',
|
||||||
'marketPrice:desc': 'marketPrice:desc,releaseDate:desc,number:asc',
|
'marketPrice:desc': 'marketPrice:desc,releaseDate:desc,inumber(missing_values:last):asc',
|
||||||
'marketPrice:asc': 'marketPrice:asc,releaseDate:desc,number:asc',
|
'marketPrice:asc': 'marketPrice:asc,releaseDate:desc,inumber(missing_values:last):asc',
|
||||||
'number:asc': '_text_match:asc,number:asc',
|
'number:asc': '_text_match:asc,inumber(missing_values:last):asc',
|
||||||
'number:desc': '_text_match:asc,number:desc',
|
'number:desc': '_text_match:asc,inumber(missing_values:last):desc',
|
||||||
};
|
};
|
||||||
const DEFAULT_SORT = '_text_match:asc,releaseDate:desc,number:asc';
|
const DEFAULT_SORT = '_text_match:asc,releaseDate:desc,inumber(missing_values:last):asc';
|
||||||
|
|
||||||
// get the query from post request using form data
|
// get the query from post request using form data
|
||||||
const formData = await Astro.request.formData();
|
const formData = await Astro.request.formData();
|
||||||
|
|||||||
Reference in New Issue
Block a user