mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 20:24:27 -04:00
Test & fix search
This commit is contained in:
parent
5bf30af564
commit
9abe7f191a
@ -317,13 +317,13 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] })
|
|||||||
.where(
|
.where(
|
||||||
and(
|
and(
|
||||||
filter,
|
filter,
|
||||||
query ? sql`${query}::text %> ${showTranslations.name}` : undefined,
|
query ? sql`${transQ.name} %> ${query}::text` : undefined,
|
||||||
keysetPaginate({ table: shows, after, sort }),
|
keysetPaginate({ table: shows, after, sort }),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.orderBy(
|
.orderBy(
|
||||||
...(query
|
...(query
|
||||||
? [sql`word_similarity(${query}::text, ${showTranslations.name})`]
|
? [sql`word_similarity(${query}::text, ${transQ.name})`]
|
||||||
: sortToSql(sort, shows)),
|
: sortToSql(sort, shows)),
|
||||||
shows.pk,
|
shows.pk,
|
||||||
)
|
)
|
||||||
|
@ -1,15 +1,30 @@
|
|||||||
|
import { sql } from "drizzle-orm";
|
||||||
import { drizzle } from "drizzle-orm/node-postgres";
|
import { drizzle } from "drizzle-orm/node-postgres";
|
||||||
|
import { migrate as migrateDb } from "drizzle-orm/node-postgres/migrator";
|
||||||
import * as schema from "./schema";
|
import * as schema from "./schema";
|
||||||
|
|
||||||
|
const dbConfig = {
|
||||||
|
user: process.env.POSTGRES_USER ?? "kyoo",
|
||||||
|
password: process.env.POSTGRES_PASSWORD ?? "password",
|
||||||
|
database: process.env.POSTGRES_DB ?? "kyooDB",
|
||||||
|
host: process.env.POSTGRES_SERVER ?? "postgres",
|
||||||
|
port: Number(process.env.POSTGRES_PORT) || 5432,
|
||||||
|
ssl: false,
|
||||||
|
};
|
||||||
export const db = drizzle({
|
export const db = drizzle({
|
||||||
schema,
|
schema,
|
||||||
connection: {
|
connection: dbConfig,
|
||||||
user: process.env.POSTGRES_USER ?? "kyoo",
|
|
||||||
password: process.env.POSTGRES_PASSWORD ?? "password",
|
|
||||||
database: process.env.POSTGRES_DB ?? "kyooDB",
|
|
||||||
host: process.env.POSTGRES_SERVER ?? "postgres",
|
|
||||||
port: Number(process.env.POSTGRES_PORT) || 5432,
|
|
||||||
ssl: false,
|
|
||||||
},
|
|
||||||
casing: "snake_case",
|
casing: "snake_case",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const migrate = async () => {
|
||||||
|
await db.execute(
|
||||||
|
sql.raw(
|
||||||
|
`ALTER DATABASE "${dbConfig.database}" SET pg_trgm.word_similarity_threshold = 0.4;`,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await migrateDb(db, {
|
||||||
|
migrationsSchema: "kyoo",
|
||||||
|
migrationsFolder: "./drizzle",
|
||||||
|
});
|
||||||
|
};
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { customType, jsonb, pgSchema, varchar } from "drizzle-orm/pg-core";
|
import { jsonb, pgSchema, varchar } from "drizzle-orm/pg-core";
|
||||||
|
|
||||||
export const schema = pgSchema("kyoo");
|
export const schema = pgSchema("kyoo");
|
||||||
|
|
||||||
@ -6,10 +6,3 @@ export const language = () => varchar({ length: 255 });
|
|||||||
|
|
||||||
export const image = () =>
|
export const image = () =>
|
||||||
jsonb().$type<{ id: string; source: string; blurhash: string }>();
|
jsonb().$type<{ id: string; source: string; blurhash: string }>();
|
||||||
|
|
||||||
// idk why they didn't implement this one
|
|
||||||
export const tsvector = customType<{ data: string }>({
|
|
||||||
dataType() {
|
|
||||||
return "tsvector";
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import jwt from "@elysiajs/jwt";
|
import jwt from "@elysiajs/jwt";
|
||||||
import { swagger } from "@elysiajs/swagger";
|
import { swagger } from "@elysiajs/swagger";
|
||||||
import { migrate } from "drizzle-orm/node-postgres/migrator";
|
|
||||||
import { Elysia } from "elysia";
|
import { Elysia } from "elysia";
|
||||||
import { base } from "./base";
|
import { base } from "./base";
|
||||||
import { entries } from "./controllers/entries";
|
import { entries } from "./controllers/entries";
|
||||||
@ -9,11 +8,11 @@ import { seasons } from "./controllers/seasons";
|
|||||||
import { seed } from "./controllers/seed";
|
import { seed } from "./controllers/seed";
|
||||||
import { series } from "./controllers/series";
|
import { series } from "./controllers/series";
|
||||||
import { videos } from "./controllers/videos";
|
import { videos } from "./controllers/videos";
|
||||||
import { db } from "./db";
|
import { migrate } from "./db";
|
||||||
import { Image } from "./models/utils";
|
import { Image } from "./models/utils";
|
||||||
import { comment } from "./utils";
|
import { comment } from "./utils";
|
||||||
|
|
||||||
await migrate(db, { migrationsSchema: "kyoo", migrationsFolder: "./drizzle" });
|
await migrate();
|
||||||
|
|
||||||
let secret = process.env.JWT_SECRET;
|
let secret = process.env.JWT_SECRET;
|
||||||
if (!secret) {
|
if (!secret) {
|
||||||
|
@ -280,7 +280,38 @@ describe("Get all movies", () => {
|
|||||||
const [resp, body] = await getMovies({
|
const [resp, body] = await getMovies({
|
||||||
limit: 2,
|
limit: 2,
|
||||||
filter: "tags eq gravity",
|
filter: "tags eq gravity",
|
||||||
preferOriginal: true,
|
});
|
||||||
|
|
||||||
|
expectStatus(resp, body).toBe(200);
|
||||||
|
expect(body.items).toBeArrayOfSize(1);
|
||||||
|
expect(body.items[0].slug).toBe(bubble.slug);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("search", () => {
|
||||||
|
it("Partial match", async () => {
|
||||||
|
const [resp, body] = await getMovies({
|
||||||
|
limit: 2,
|
||||||
|
query: "bub",
|
||||||
|
});
|
||||||
|
|
||||||
|
expectStatus(resp, body).toBe(200);
|
||||||
|
expect(body.items).toBeArrayOfSize(1);
|
||||||
|
expect(body.items[0].slug).toBe(bubble.slug);
|
||||||
|
});
|
||||||
|
it("Invalid search don't match", async () => {
|
||||||
|
const [resp, body] = await getMovies({
|
||||||
|
limit: 2,
|
||||||
|
query: "buboeuoeunhoeu",
|
||||||
|
});
|
||||||
|
|
||||||
|
expectStatus(resp, body).toBe(200);
|
||||||
|
expect(body.items).toBeArrayOfSize(0);
|
||||||
|
});
|
||||||
|
it("Typo match", async () => {
|
||||||
|
const [resp, body] = await getMovies({
|
||||||
|
limit: 2,
|
||||||
|
query: "bobble",
|
||||||
});
|
});
|
||||||
|
|
||||||
expectStatus(resp, body).toBe(200);
|
expectStatus(resp, body).toBe(200);
|
||||||
|
@ -33,6 +33,7 @@ export const getMovies = async ({
|
|||||||
limit?: number;
|
limit?: number;
|
||||||
after?: string;
|
after?: string;
|
||||||
sort?: string | string[];
|
sort?: string | string[];
|
||||||
|
query?: string;
|
||||||
langs?: string;
|
langs?: string;
|
||||||
preferOriginal?: boolean;
|
preferOriginal?: boolean;
|
||||||
}) => {
|
}) => {
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
import { beforeAll } from "bun:test";
|
import { beforeAll } from "bun:test";
|
||||||
import { migrate } from "drizzle-orm/node-postgres/migrator";
|
import { migrate } from "~/db";
|
||||||
import { db } from "~/db";
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await migrate(db, {
|
await migrate();
|
||||||
migrationsSchema: "kyoo",
|
|
||||||
migrationsFolder: "./drizzle",
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user