From 40ca59307b00b2bc0ec63df8fdbd36095e53aeb9 Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Thu, 19 Sep 2024 15:09:44 -0300 Subject: [PATCH] feat: order search by followers count also --- src/utils/search.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/utils/search.ts b/src/utils/search.ts index 5ca43417..31b31e90 100644 --- a/src/utils/search.ts +++ b/src/utils/search.ts @@ -11,19 +11,22 @@ export async function getPubkeysBySearch( let query = kysely .selectFrom('author_search') + .leftJoin('author_stats', 'author_stats.pubkey', 'author_search.pubkey') .select((eb) => [ - 'pubkey', + 'author_search.pubkey', 'search', eb.fn('word_similarity', [sql`${q}`, 'search']).as('sml'), + eb.fn.coalesce('author_stats.followers_count', sql`0`).as('followers_count'), ]) .where(() => sql`${q} <% search`) + .orderBy(['followers_count desc']) .orderBy(['sml desc', 'search']) .limit(limit); const pubkeys = new Set((await query.execute()).map(({ pubkey }) => pubkey)); if (followedPubkeys.size > 0) { - query = query.where('pubkey', 'in', [...followedPubkeys]); + query = query.where('author_search.pubkey', 'in', [...followedPubkeys]); } const followingPubkeys = new Set((await query.execute()).map(({ pubkey }) => pubkey));