From 8fc4bd23c314638e3c629f88aa5bdc34b62a2bac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Thu, 24 Nov 2022 12:00:41 +0100 Subject: [PATCH] skip index and use the correct lowercasing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- ...1109192547_search_add_original_value_column.js | 15 +++++++++++++-- .../src/service/DefaultEntitiesCatalog.ts | 6 ++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/plugins/catalog-backend/migrations/20221109192547_search_add_original_value_column.js b/plugins/catalog-backend/migrations/20221109192547_search_add_original_value_column.js index 394591bd63..258af5ef06 100644 --- a/plugins/catalog-backend/migrations/20221109192547_search_add_original_value_column.js +++ b/plugins/catalog-backend/migrations/20221109192547_search_add_original_value_column.js @@ -18,13 +18,25 @@ * @param { import("knex").Knex } knex */ exports.up = async function up(knex) { + // Start out with an original_value column that's equal to the value column await knex.schema.alterTable('search', table => { table .string('original_value') .nullable() .comment('Holds the corresponding original case sensitive value'); - table.index(['original_value'], 'search_original_value_idx'); }); + await knex('search').update({ original_value: knex.ref('value') }); + + // Make sure to reprocess everything, to make sure that the original_value + // column is populated with values with the proper casing. It's unfortunately + // not enough to just reset the final_entities hash, since stitching is driven + // only by processing resulting in data that isn't matching the refresh_state + // hash. + await knex('refresh_state').update({ + result_hash: '', + next_update_at: knex.fn.now(), + }); + await knex('final_entities').update({ hash: '' }); }; /** @@ -32,7 +44,6 @@ exports.up = async function up(knex) { */ exports.down = async function down(knex) { await knex.schema.alterTable('search', table => { - table.dropIndex([], 'search_original_value_idx'); table.dropColumn('original_value'); }); }; diff --git a/plugins/catalog-backend/src/service/DefaultEntitiesCatalog.ts b/plugins/catalog-backend/src/service/DefaultEntitiesCatalog.ts index 11e4b37f63..c82a17cb6f 100644 --- a/plugins/catalog-backend/src/service/DefaultEntitiesCatalog.ts +++ b/plugins/catalog-backend/src/service/DefaultEntitiesCatalog.ts @@ -403,11 +403,9 @@ export class DefaultEntitiesCatalog implements EntitiesCatalog { for (const facet of request.facets) { const dbQuery = db('search') .join('final_entities', 'search.entity_id', 'final_entities.entity_id') - .where('search.key', facet.toLowerCase()) + .where('search.key', facet.toLocaleLowerCase('en-US')) .count('search.entity_id as count') - .select({ - value: 'search.original_value', - }) + .select({ value: 'search.original_value' }) .groupBy('search.original_value'); if (request?.filter) {