-
Notifications
You must be signed in to change notification settings - Fork 18
/
index.js
70 lines (58 loc) · 2.93 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const express = require('express')
const app = express()
const path = require('path')
const bodyParser = require('body-parser');
const { default: weaviate } = require('weaviate-ts-client');
const e = require('express');
require('dotenv').config();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'views')));
let initial_path = path.join(__dirname, "views");
//Importing query functions from query.js
let { get_keyword_results, get_semantic_results, get_hybrid_results, get_movie_details, get_recommended_movies } = require('./queries')
const client = weaviate.client({
scheme: 'https',
host: process.env.WEAVIATE_URL, // Replace with your endpoint
apiKey: new weaviate.ApiKey(process.env.WEAVIATE_API_KEY), // Replace w/ your Weaviate instance API key
headers: { 'X-OpenAI-Api-Key': process.env.OPENAI_API_KEY },
});
// variable storing the searched text
let text = "";
// variable storing ID of the movie being viewed
let id = "";
//rendering home page
app.get('/', (req, res) => {
res.render(path.join(initial_path, "search.ejs"), { movie_info: {}, googleTagId: process.env.GOOGLE_TAG_ID });
})
//perform query for seached text
app.get('/search', (req, res) => {
// stores the searched text in variable "text"
text = req.query['searched_data'].toLowerCase();
if (req.query['semantic_search'] != undefined) {
let get_results = get_semantic_results(text);
get_results.then(results => { res.render(path.join(initial_path, "search.ejs"), { movie_info: results.data.Get.Awesome_moviate_movies, googleTagId: process.env.GOOGLE_TAG_ID }) });
}
else if (req.query['hybrid_search'] != undefined) {
let get_results = get_hybrid_results(text);
get_results.then(results => { res.render(path.join(initial_path, "search.ejs"), { movie_info: results.data.Get.Awesome_moviate_movies, googleTagId: process.env.GOOGLE_TAG_ID }) });
}
else {
let get_results = get_keyword_results(text);
get_results.then(results => { res.render(path.join(initial_path, "search.ejs"), { movie_info: results.data.Get.Awesome_moviate_movies, googleTagId: process.env.GOOGLE_TAG_ID }) });
}
})
app.get('/movie/:id', (req, res) => {
// stores the ID of the movie that is being viewed in in variable "id"
id = req.params.id
//retrieving information of the movie with the given id
let movie_info = get_movie_details(id);
movie_info.then(info1 => {
let recommended_movies = get_recommended_movies(info1.data.Get.Awesome_moviate_movies[0]._additional.id)
recommended_movies.then(info2 => {
res.render(path.join(initial_path, "movie_info.ejs"), { movie_info: info1.data.Get.Awesome_moviate_movies, related_movies: info2.data.Get.Awesome_moviate_movies, googleTagId: process.env.GOOGLE_TAG_ID });
})
})
})
app.listen(process.env.PORT || 3000,
() => console.log(`The app is running on: http://localhost:${process.env.PORT || 3000}`)
)