mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
feat: order search by followers count also
This commit is contained in:
parent
d1f452d87b
commit
40ca59307b
1 changed files with 5 additions and 2 deletions
|
|
@ -11,19 +11,22 @@ export async function getPubkeysBySearch(
|
||||||
|
|
||||||
let query = kysely
|
let query = kysely
|
||||||
.selectFrom('author_search')
|
.selectFrom('author_search')
|
||||||
|
.leftJoin('author_stats', 'author_stats.pubkey', 'author_search.pubkey')
|
||||||
.select((eb) => [
|
.select((eb) => [
|
||||||
'pubkey',
|
'author_search.pubkey',
|
||||||
'search',
|
'search',
|
||||||
eb.fn('word_similarity', [sql`${q}`, 'search']).as('sml'),
|
eb.fn('word_similarity', [sql`${q}`, 'search']).as('sml'),
|
||||||
|
eb.fn.coalesce('author_stats.followers_count', sql<number>`0`).as('followers_count'),
|
||||||
])
|
])
|
||||||
.where(() => sql`${q} <% search`)
|
.where(() => sql`${q} <% search`)
|
||||||
|
.orderBy(['followers_count desc'])
|
||||||
.orderBy(['sml desc', 'search'])
|
.orderBy(['sml desc', 'search'])
|
||||||
.limit(limit);
|
.limit(limit);
|
||||||
|
|
||||||
const pubkeys = new Set((await query.execute()).map(({ pubkey }) => pubkey));
|
const pubkeys = new Set((await query.execute()).map(({ pubkey }) => pubkey));
|
||||||
|
|
||||||
if (followedPubkeys.size > 0) {
|
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));
|
const followingPubkeys = new Set((await query.execute()).map(({ pubkey }) => pubkey));
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue