-
Notifications
You must be signed in to change notification settings - Fork 8
/
app.js
55 lines (43 loc) · 1.24 KB
/
app.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
var http = require('http');
var director = require('director');
var log = require("./log").log;
var solr = require('solr-client');
var union = require('union');
var ecstatic = require('ecstatic');
var url = require('url');
var client = solr.createClient();
function solrSearch(searchterm) {
//add page to start from
var parts = url.parse(this.req.url, true);
var page = parts.query['page'];
var that = this;
var query = client.createQuery().q(searchterm)
.dismax()
.qf({title_t : 0.2 , summary_t : 3.3})
.mm(2).start(page).rows(10);
client.search(query, function(err, obj) {
if (err) throw err;
that.res.writeHead(200, {
'Content-Type': 'text/html'
});
that.res.end(JSON.stringify(obj));
});
}
//##### The flatiron-director router
var router = new director.http.Router({
'/search/:searchterm': {
get: solrSearch
}
});
var server = union.createServer({
before: [
function(req, res) {
var found = router.dispatch(req, res);
if (!found) {
res.emit('next');
}
},
ecstatic(__dirname + '/public')]
});
server.listen(8080);
console.log('Listening on http://127.0.0.1:8080');