Skip to content

Commit

Permalink
Add new columns to songStore and implement aiSearchSongs
Browse files Browse the repository at this point in the history
  • Loading branch information
JHM69 committed Feb 25, 2024
1 parent 5f8fd0a commit acaaaa1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 32 deletions.
10 changes: 4 additions & 6 deletions prisma/prisma-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,17 @@ export const songStore = PrismaVectorStore.withModel<Song>(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,
content : PrismaVectorStore.ContentColumn,
tags : PrismaVectorStore.ContentColumn,
mood : PrismaVectorStore.ContentColumn,
lyricsSnippet : PrismaVectorStore.ContentColumn,
},
filter: {
content: {
equals: "default",
},
},
}
}
);

Expand Down
18 changes: 7 additions & 11 deletions src/controllers/song.controller.ts
Original file line number Diff line number Diff line change
@@ -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';


Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/services/home.service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/prefer-default-export */


import prisma from '../../prisma/prisma-client';
Expand Down Expand Up @@ -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,
Expand Down
25 changes: 10 additions & 15 deletions src/services/songs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit acaaaa1

Please sign in to comment.