-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
59 lines (52 loc) · 1.46 KB
/
server.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
var express = require('express');
var app = express();
var cors = require('cors');
app.use(cors());
var SolrNode = require('solr-node');
var client = new SolrNode({
host: '127.0.0.1',
port: '8983',
core: 'rishabh_example',
protocol: 'http'
});
var fs = require('fs');
var parse = require('csv-parse');
var HashMap = require('hashmap');
var map = new HashMap();
fs.createReadStream("/home/rishabh/Downloads/solr-6.5.0/mapNBCNewsDataFile.csv")
.pipe(parse({delimiter: ','}))
.on('data', function(csvrow) {
map.set(csvrow[0],csvrow[1]);
});
app.get('/Go', function(req, res) {
var query;
if(req.query.choice.match("lucene"))
{
query='fl=id,description,title&indent=on&q='+req.query.search+'&wt=json&start=0&rows=10';
}
else if(req.query.choice.match("pagerank"))
{
query='fl=id,description,title&indent=on&q='+req.query.search+'&sort=pageRankFile%20desc&wt=json&start=0&rows=10';
}
client.search(query, function (err, result) {
if (err) {
console.log(err);
return;
}
var output=[];
output[0]=result.response.numFound;
output[1]=[];
result.response.docs.forEach(function(x){
var id=x.id;
var ans={"title":x.title,
"description":x.description,
"id":x.id,
"site_url":map.get(id.substring(id.lastIndexOf("/")+1))
}
output[1].push(ans);
});
res.send(output);
});
});
app.listen(1337);
console.log("listening on 1337");