emoji search: show closest match first #338

This commit is contained in:
dakkar 2024-01-12 16:28:49 +00:00
parent bbdc4e7789
commit d2d75b25bf
2 changed files with 4 additions and 3 deletions

View file

@ -98,11 +98,12 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // 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();

View file

@ -91,7 +91,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // 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) {