Skip to content

Commit

Permalink
fix(core): Ensure Sqlite search order by name case insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
hans-rollingridges-dev committed Nov 22, 2023
1 parent 62f410d commit c2a688e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
6 changes: 3 additions & 3 deletions packages/core/e2e/default-search-plugin.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1849,6 +1849,7 @@ describe('Default search plugin', () => {
'Instant Camera',
'Laptop en', // fallback language en
'Orchid',
'product en', // fallback language en
'Road Bike',
'Running Shoe',
'Skipping Rope',
Expand All @@ -1858,7 +1859,6 @@ describe('Default search plugin', () => {
'Tent',
'Tripod',
'USB Cable',
'product en', // fallback language en
];

expect(search.items.map(i => i.productName)).toEqual(productNames);
Expand All @@ -1878,6 +1878,7 @@ describe('Default search plugin', () => {
'Instant Camera',
'Laptop de', // language de
'Orchid',
'product de', // language de
'Road Bike',
'Running Shoe',
'Skipping Rope',
Expand All @@ -1887,7 +1888,6 @@ describe('Default search plugin', () => {
'Tent',
'Tripod',
'USB Cable',
'product de', // language de
];

expect(search.items.map(i => i.productName)).toEqual(productNames);
Expand All @@ -1907,6 +1907,7 @@ describe('Default search plugin', () => {
'Instant Camera',
'Laptop zh', // language zh
'Orchid',
'product en', // fallback language en
'Road Bike',
'Running Shoe',
'Skipping Rope',
Expand All @@ -1916,7 +1917,6 @@ describe('Default search plugin', () => {
'Tent',
'Tripod',
'USB Cable',
'product en', // fallback language en
];

expect(search.items.map(i => i.productName)).toEqual(productNames);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ export class MysqlSearchStrategy implements SearchStrategy {

applyLanguageConstraints(qb, ctx.languageCode, ctx.channel.defaultLanguageCode);
qb.andWhere('si.channelId = :channelId', { channelId: ctx.channelId });

if (input.groupByProduct === true) {
qb.groupBy('si.productId');
qb.addSelect('BIT_OR(si.enabled)', 'productEnabled');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,11 @@ export class PostgresSearchStrategy implements SearchStrategy {

applyLanguageConstraints(qb, ctx.languageCode, ctx.channel.defaultLanguageCode);
qb.andWhere('si.channelId = :channelId', { channelId: ctx.channelId });

if (input.groupByProduct === true) {
qb.groupBy('si.productId');
}

return qb;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ export class SqliteSearchStrategy implements SearchStrategy {
}
if (sort) {
if (sort.name) {
qb.addOrderBy('si.productName', sort.name);
// TODO: v3 - set the collation on the SearchIndexItem entity
qb.addOrderBy('si.productName COLLATE NOCASE', sort.name);
}
if (sort.price) {
qb.addOrderBy('si.price', sort.price);
Expand Down

0 comments on commit c2a688e

Please sign in to comment.