feat(ADM-018): completed feature
This commit is contained in:
47
project/migrations/010_catalog_search_fts.js
Normal file
47
project/migrations/010_catalog_search_fts.js
Normal file
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* PostgreSQL full-text search support for catalog products.
|
||||
*/
|
||||
|
||||
/** @param {import('node-pg-migrate').MigrationBuilder} pgm */
|
||||
export const up = (pgm) => {
|
||||
pgm.sql(`
|
||||
CREATE INDEX catalog_products_fts_idx
|
||||
ON catalog_products USING gin (
|
||||
(
|
||||
setweight(to_tsvector('spanish', COALESCE(name, '')), 'A') ||
|
||||
setweight(to_tsvector('spanish', COALESCE(description, '')), 'B') ||
|
||||
setweight(to_tsvector('spanish', COALESCE(seo_title, '')), 'B') ||
|
||||
setweight(to_tsvector('spanish', COALESCE(seo_description, '')), 'C')
|
||||
)
|
||||
)
|
||||
`);
|
||||
pgm.sql(`
|
||||
CREATE INDEX brands_brands_fts_idx
|
||||
ON brands_brands USING gin (
|
||||
(
|
||||
setweight(to_tsvector('spanish', COALESCE(name, '')), 'A') ||
|
||||
setweight(to_tsvector('spanish', COALESCE(slug, '')), 'B') ||
|
||||
setweight(to_tsvector('spanish', COALESCE(seo_title, '')), 'B') ||
|
||||
setweight(to_tsvector('spanish', COALESCE(seo_description, '')), 'C')
|
||||
)
|
||||
)
|
||||
`);
|
||||
pgm.sql(`
|
||||
CREATE INDEX categories_categories_fts_idx
|
||||
ON categories_categories USING gin (
|
||||
(
|
||||
setweight(to_tsvector('spanish', COALESCE(name, '')), 'A') ||
|
||||
setweight(to_tsvector('spanish', COALESCE(slug, '')), 'B') ||
|
||||
setweight(to_tsvector('spanish', COALESCE(seo_title, '')), 'B') ||
|
||||
setweight(to_tsvector('spanish', COALESCE(seo_description, '')), 'C')
|
||||
)
|
||||
)
|
||||
`);
|
||||
};
|
||||
|
||||
/** @param {import('node-pg-migrate').MigrationBuilder} pgm */
|
||||
export const down = (pgm) => {
|
||||
pgm.sql('DROP INDEX IF EXISTS categories_categories_fts_idx');
|
||||
pgm.sql('DROP INDEX IF EXISTS brands_brands_fts_idx');
|
||||
pgm.sql('DROP INDEX IF EXISTS catalog_products_fts_idx');
|
||||
};
|
||||
Reference in New Issue
Block a user