mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 04:04:21 -04:00
wip: Replace tsvector with trigram search
This commit is contained in:
parent
59aca6d520
commit
eaec881594
@ -295,15 +295,8 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] })
|
|||||||
isAvailable: sql<boolean>`${videoQ.showPk} is not null`.as(
|
isAvailable: sql<boolean>`${videoQ.showPk} is not null`.as(
|
||||||
"isAvailable",
|
"isAvailable",
|
||||||
),
|
),
|
||||||
rank: sql<number>`ts_rank_cd(${transQ.search}, query)`.as("rank"),
|
|
||||||
})
|
})
|
||||||
.from(shows)
|
.from(shows)
|
||||||
// TODO: change `simple` to `transQ.language`
|
|
||||||
// yes drizzle doesn't support crossJoin so we do a fullJoin on true T-T
|
|
||||||
.fullJoin(
|
|
||||||
sql`websearch_to_tsquery('simple', ${query}) as query`,
|
|
||||||
sql`true`,
|
|
||||||
)
|
|
||||||
.innerJoin(transQ, eq(shows.pk, transQ.pk))
|
.innerJoin(transQ, eq(shows.pk, transQ.pk))
|
||||||
.leftJoin(
|
.leftJoin(
|
||||||
showTranslations,
|
showTranslations,
|
||||||
@ -318,12 +311,14 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] })
|
|||||||
.where(
|
.where(
|
||||||
and(
|
and(
|
||||||
filter,
|
filter,
|
||||||
query ? sql`query @@ ${transQ.search}` : undefined,
|
query ? sql`${query}::text %> ${showTranslations.name}` : undefined,
|
||||||
keysetPaginate({ table: shows, after, sort }),
|
keysetPaginate({ table: shows, after, sort }),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.orderBy(
|
.orderBy(
|
||||||
...(query ? [sql`rank`] : []),
|
...(query
|
||||||
|
? [sql`word_similarity(${query}::text, ${showTranslations.name})`]
|
||||||
|
: []),
|
||||||
...(sort.random
|
...(sort.random
|
||||||
? [sql`md5(${sort.random.seed} || ${shows.pk})`]
|
? [sql`md5(${sort.random.seed} || ${shows.pk})`]
|
||||||
: []),
|
: []),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user