From d2d75b25bf592d2b62d8dd3d14c6c36626688506 Mon Sep 17 00:00:00 2001 From: dakkar Date: Fri, 12 Jan 2024 16:28:49 +0000 Subject: [PATCH] emoji search: show closest match first #338 --- .../src/server/api/endpoints/admin/emoji/list-remote.ts | 5 +++-- .../backend/src/server/api/endpoints/admin/emoji/list.ts | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/admin/emoji/list-remote.ts b/packages/backend/src/server/api/endpoints/admin/emoji/list-remote.ts index f3e0c1ef1..be4d16589 100644 --- a/packages/backend/src/server/api/endpoints/admin/emoji/list-remote.ts +++ b/packages/backend/src/server/api/endpoints/admin/emoji/list-remote.ts @@ -98,11 +98,12 @@ export default class extends Endpoint { // eslint- } if (ps.query) { - q.andWhere('emoji.name like :query', { query: '%' + sqlLikeEscape(ps.query) + '%' }); + q.andWhere('emoji.name like :query', { query: '%' + sqlLikeEscape(ps.query) + '%' }) + .orderBy('length(emoji.name)', 'ASC'); } const emojis = await q - .orderBy('emoji.id', 'DESC') + .addOrderBy('emoji.id', 'DESC') .limit(ps.limit) .getMany(); diff --git a/packages/backend/src/server/api/endpoints/admin/emoji/list.ts b/packages/backend/src/server/api/endpoints/admin/emoji/list.ts index 59e87253f..26b70587a 100644 --- a/packages/backend/src/server/api/endpoints/admin/emoji/list.ts +++ b/packages/backend/src/server/api/endpoints/admin/emoji/list.ts @@ -91,7 +91,7 @@ export default class extends Endpoint { // eslint- //q.andWhere('emoji.name ILIKE :q', { q: `%${ sqlLikeEscape(ps.query) }%` }); //const emojis = await q.limit(ps.limit).getMany(); - emojis = await q.getMany(); + emojis = await q.orderBy('length(emoji.name)', 'ASC').getMany(); const queryarry = ps.query.match(/\:([a-z0-9_]*)\:/g); if (queryarry) {