forked from weaviate/weaviate-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
43 lines (38 loc) · 1.12 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
const express = require('express')
const app = express()
const path = require('path')
const bodyParser = require('body-parser');
const weaviate = require("weaviate-client");
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'views')));
let initial_path = path.join(__dirname, "views");
//setting up client
const client = weaviate.client({
scheme: 'http',
host: 'localhost:8080',
});
//rendering home page
app.get('/', (req, res) => {
res.render(path.join(initial_path, "search.ejs"),{movie_info:{}});
})
//perform query for seached text
app.post('/search', (req, res) => {
let text = req.body['searched_data'];
console.log(text)
client.graphql
.get()
.withClassName('Movies')
.withFields(['title','genres','popularity','runtime'])
.withNearText({
concepts: [text],
certainty: 0.7
})
.do()
.then(info => {
res.render(path.join(initial_path, "search.ejs"),{movie_info:info['data']['Get']['Movies']});
})
.catch(err => {
console.error(err)
})
})
app.listen(process.env.PORT || 4000)