diff --git a/prisma/prisma-client.ts b/prisma/prisma-client.ts index 1b1a04a..baba3fe 100644 --- a/prisma/prisma-client.ts +++ b/prisma/prisma-client.ts @@ -30,6 +30,9 @@ export const songStore = PrismaVectorStore.withModel(prisma).create( columns: { id: PrismaVectorStore.IdColumn, name : PrismaVectorStore.ContentColumn, + slug : PrismaVectorStore.ContentColumn, + label : PrismaVectorStore.ContentColumn, + primaryImage : PrismaVectorStore.ContentColumn, duration : PrismaVectorStore.ContentColumn, year : PrismaVectorStore.ContentColumn, origin : PrismaVectorStore.ContentColumn, @@ -37,12 +40,7 @@ export const songStore = PrismaVectorStore.withModel(prisma).create( tags : PrismaVectorStore.ContentColumn, mood : PrismaVectorStore.ContentColumn, lyricsSnippet : PrismaVectorStore.ContentColumn, - }, - filter: { - content: { - equals: "default", - }, - }, + } } ); diff --git a/src/controllers/song.controller.ts b/src/controllers/song.controller.ts index 07b8236..20d2c21 100644 --- a/src/controllers/song.controller.ts +++ b/src/controllers/song.controller.ts @@ -1,10 +1,12 @@ +/* eslint-disable no-console */ import { NextFunction, Request, Response, Router } from 'express'; import auth from '../utils/auth'; import { getSong, getSongs, createSong, updateSong, - deleteSong + deleteSong, + aiSearchSongs } from '../services/songs.service'; @@ -30,24 +32,18 @@ router.get('/songs', auth.optional, async (req: Request, res: Response, next: Ne } }); -/** - * Get paginated feed songs - * @auth required - * @route {GET} /songs/feed - * @returns songs list of songs - */ + router.get( - '/songs', - auth.required, + '/ai-search-songs', async (req: Request, res: Response, next: NextFunction) => { try { - res.json("result"); + const result = await aiSearchSongs(req.query); + res.json(result); } catch (error) { next(error); } }, ); - /** * Create song * @route {POST} /songs diff --git a/src/services/home.service.ts b/src/services/home.service.ts index a1b024c..2cbaf8a 100644 --- a/src/services/home.service.ts +++ b/src/services/home.service.ts @@ -1,3 +1,4 @@ +/* eslint-disable import/prefer-default-export */ import prisma from '../../prisma/prisma-client'; @@ -66,6 +67,7 @@ export const getHomeData = async (query: any, username?: string) => { }); + // eslint-disable-next-line camelcase const new_trending = playlists.map((playlist: any) => ({ id: playlist.slug, title: playlist.name, diff --git a/src/services/songs.service.ts b/src/services/songs.service.ts index ba74ea8..cade18f 100644 --- a/src/services/songs.service.ts +++ b/src/services/songs.service.ts @@ -39,21 +39,7 @@ export const getSongs = async (query: any, username?: string) => { }, }); } - - console.log("Searching for Similar Songs"); - console.log(query.search); - await songStore.similaritySearch(query.search, 10, "default").catch((e) => { - console.log("Error in Similarity Search"); - console.log(e); - - }).then((result) => { - console.log("Similarity Search Result"); - console.log(result); - - }); - - - + const songs = await prisma.song.findMany({ where: { AND: andQueries }, orderBy: { @@ -115,6 +101,15 @@ export const getSongs = async (query: any, username?: string) => { }; }; + +export const aiSearchSongs = async (query: any) => { + const result = await songStore.similaritySearchWithScore(query.search, 1); + console.log(result); + return { + result, + }; +} + export const createSong = async (song: any, username : string) => { const { name,