Skip to content

Commit 0075693

Browse files
authored
Merge pull request #51 from ibm-cds-labs/i50
I50
2 parents 26fa134 + 63302bb commit 0075693

22 files changed

+313
-198
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ start.sh
44
*.tsv
55
*.csv
66
.settings
7-
.jshintrc
87
.project
98
npm-debug.log
109
.vscode

.jshintrc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"bitwise" : true,
3+
"browser" : true,
4+
"curly" : true,
5+
"eqeqeq" : true,
6+
"es3" : false,
7+
"forin" : false,
8+
"jquery" : true,
9+
"latedef" : true,
10+
"maxparams" : 5,
11+
"maxdepth" : 3,
12+
"maxstatements" : false,
13+
"noarg" : true,
14+
"node" : true,
15+
"nonew" : true,
16+
"undef" : true,
17+
"unused" : true,
18+
"strict" : false,
19+
"esversion" : 6
20+
}

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
language: node_js
2+
node_js:
3+
- '0.12'

Gruntfile.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module.exports = function (grunt) {
2+
// Project configuration.
3+
grunt.initConfig({
4+
jshint: {
5+
options : {
6+
jshintrc: ".jshintrc",
7+
ignores : [ "node_modules/**/*.js" ]
8+
},
9+
src: ["Gruntfile.js", "app.js", "lib/**.js"],
10+
},
11+
jscs: {
12+
src: ["Gruntfile.js", "app.js", "lib/**.js"],
13+
options: {
14+
config: ".jscsrc",
15+
requireCurlyBraces: [ "if" ]
16+
}
17+
}
18+
});
19+
20+
grunt.loadNpmTasks("grunt-contrib-jshint");
21+
22+
grunt.registerTask("default", [ "lint", "jscs" ]);
23+
24+
grunt.loadNpmTasks("grunt-jscs");
25+
26+
grunt.registerTask("lint", "Check for common code problems.", [ "jshint" ]);
27+
};

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Overview: Simple Search Service
22

3+
![build status](https://travis-ci.org/ibm-cds-labs/simple-search-service.svg?branch=master)
4+
35
Simple Search Service is an IBM Bluemix app that lets you quickly create a faceted search engine, exposing an API you can use to bring search into your own apps. The service also creates a website that lets you preview the API and test it against your own data as well as manage your data via a simple CMS.
46

57
Once deployed, use the browser to upload CSV or TSV data. Specify the fields to facet, and the service handles the rest.

app.js

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ app.use(express.static(__dirname + '/public'));
6363
var multipart = multer({ dest: process.env.TMPDIR, limits: { files: 1, fileSize: 100000000 }});
6464

6565
// posted body parser
66-
var bodyParser = require('body-parser')({extended:true})
66+
var bodyParser = require('body-parser')({extended:true});
6767

6868
// compress all requests
6969
app.use(compression());
@@ -100,7 +100,7 @@ app.post('/upload', multipart, isloggedin.auth, function(req, res){
100100
};
101101

102102
dbimport.clear();
103-
app.locals.import[obj.files.file.name] = obj
103+
app.locals.import[obj.files.file.name] = obj;
104104
inference.infer(obj.files.file.path, function(err, data) {
105105
data.upload_id = req.files.file.name;
106106
res.send(data);
@@ -112,7 +112,7 @@ app.post('/fetch', bodyParser, isloggedin.auth, function(req, res){
112112
var obj = req.body;
113113

114114
dbimport.clear();
115-
app.locals.import[obj.url] = obj
115+
app.locals.import[obj.url] = obj;
116116

117117
inference.infer(obj.url, function(err, data) {
118118
data.upload_id = obj.url;
@@ -126,7 +126,7 @@ app.post('/import', bodyParser, isloggedin.auth, function(req, res){
126126
console.log("****",req.body.schema);
127127
console.log("****");
128128

129-
var currentUpload = app.locals.import[req.body.upload_id]
129+
var currentUpload = app.locals.import[req.body.upload_id];
130130

131131
// run this in parallel to save time
132132
var theschema = JSON.parse(req.body.schema);
@@ -181,16 +181,16 @@ app.get('/config', isloggedin.auth, function(req, res) {
181181
autocomplete: app.locals.autocomplete,
182182
cache: app.locals.cache,
183183
metrics: app.locals.metrics
184-
})
185-
})
184+
});
185+
});
186186

187187
//settings api
188188
app.get('/settings', isloggedin.auth, function (req, res) {
189189
db.settings(function(err, data) {
190190
if (err) {
191191
return res.status(err.statusCode).send({error: err.error, reason: err.reason});
192192
}
193-
data["appenv"] = sssenv;
193+
data.appenv = sssenv;
194194
res.send(data);
195195
});
196196
});
@@ -277,7 +277,7 @@ app.get('/autocompletes', cors(), isloggedin.auth, function(req, res) {
277277

278278
Object.keys(data.counts).forEach(k => {
279279
facets[k] = `http://${req.headers.host}/autocompletes/${k}`;
280-
})
280+
});
281281

282282
res.send(facets);
283283

@@ -311,17 +311,19 @@ app.post('/service/enable/sas', isloggedin.auth, function(req, res) {
311311
registry.setEnv("search", "autocomplete_enable", true, function(err, data) {
312312

313313
if (err) {
314-
return res.send({ success: false })
314+
return res.send({ success: false });
315315
}
316316

317-
return res.send({ success: true })
317+
data = null;
318+
319+
return res.send({ success: true });
318320

319321
});
320322

321323
}
322324

323325
else {
324-
return res.send({ success: false })
326+
return res.send({ success: false });
325327
}
326328

327329
});
@@ -333,16 +335,18 @@ app.post('/service/disable/sas', isloggedin.auth, function(req, res) {
333335
registry.setEnv("search", "autocomplete_enable", false, function(err, data) {
334336

335337
if (err) {
336-
return res.send({ success: false })
338+
return res.send({ success: false });
337339
}
338340

339-
return res.send({ success: true })
341+
data = null;
342+
343+
return res.send({ success: true });
340344

341345
});
342346
}
343347

344348
else {
345-
return res.send({ success: false })
349+
return res.send({ success: false });
346350
}
347351

348352
});
@@ -355,17 +359,19 @@ app.post('/service/enable/scs', isloggedin.auth, function(req, res) {
355359
registry.setEnv("search", "cache_enable", true, function(err, data) {
356360

357361
if (err) {
358-
return res.send({ success: false })
362+
return res.send({ success: false });
359363
}
360364

361-
return res.send({ success: true })
365+
data = null;
366+
367+
return res.send({ success: true });
362368

363369
});
364370

365371
}
366372

367373
else {
368-
return res.send({ success: false })
374+
return res.send({ success: false });
369375
}
370376

371377
});
@@ -377,16 +383,18 @@ app.post('/service/disable/scs', isloggedin.auth, function(req, res) {
377383
registry.setEnv("search", "cache_enable", false, function(err, data) {
378384

379385
if (err) {
380-
return res.send({ success: false })
386+
return res.send({ success: false });
381387
}
382388

383-
return res.send({ success: true })
389+
data = null;
390+
391+
return res.send({ success: true });
384392

385393
});
386394
}
387395

388396
else {
389-
return res.send({ success: false })
397+
return res.send({ success: false });
390398
}
391399

392400
});
@@ -399,17 +407,19 @@ app.post('/service/enable/metrics', isloggedin.auth, function(req, res) {
399407
registry.setEnv("search", "metrics_enable", true, function(err, data) {
400408

401409
if (err) {
402-
return res.send({ success: false })
410+
return res.send({ success: false });
403411
}
404412

405-
return res.send({ success: true })
413+
data = null;
414+
415+
return res.send({ success: true });
406416

407417
});
408418

409419
}
410420

411421
else {
412-
return res.send({ success: false })
422+
return res.send({ success: false });
413423
}
414424

415425
});
@@ -421,16 +431,18 @@ app.post('/service/disable/metrics', isloggedin.auth, function(req, res) {
421431
registry.setEnv("search", "metrics_enable", false, function(err, data) {
422432

423433
if (err) {
424-
return res.send({ success: false })
434+
return res.send({ success: false });
425435
}
426436

427-
return res.send({ success: true })
437+
data = null;
438+
439+
return res.send({ success: true });
428440

429441
});
430442
}
431443

432444
else {
433-
return res.send({ success: false })
445+
return res.send({ success: false });
434446
}
435447

436448
});

lib/autocomplete.js

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var populate = function(service) {
2121
var actions = {};
2222
schema.fields.filter(f => f.facet).forEach(f => {
2323

24-
var name = `sss_${f.name}`
24+
var name = `sss_${f.name}`;
2525

2626
actions[name] = function(callback) {
2727

@@ -31,32 +31,43 @@ var populate = function(service) {
3131
name: name,
3232
url: `${appEnv.url}/autocompletes/${f.name}`
3333
}
34-
}
34+
};
3535

3636
if (service.username && service.password) {
3737
var auth = "Basic " + new Buffer(service.username + ":" + service.password).toString("base64");
3838
opts.headers = {
3939
"Authorization" : auth
40-
}
40+
};
4141
}
4242

4343
request.post(opts, function(err, res, body) {
44-
return callback()
45-
})
4644

47-
}
45+
res = null;
46+
body = null;
47+
err = null;
48+
49+
return callback();
50+
});
4851

49-
})
52+
};
53+
54+
});
5055

5156
async.series(actions, function(err, results) {
5257

58+
if (err) {
59+
return console.log(err);
60+
}
61+
62+
results = null;
63+
5364
console.log("autocompletes done");
5465

55-
})
66+
});
5667

57-
})
68+
});
5869

59-
}
70+
};
6071

6172
var append = function(data, service) {
6273

@@ -75,7 +86,9 @@ var append = function(data, service) {
7586
var actions = {};
7687
schema.fields.filter(f => f.facet).forEach(f => {
7788

78-
if (!data[f.name]) return false;
89+
if (!data[f.name]) {
90+
return false;
91+
}
7992

8093
actions[f.name] = function(callback) {
8194

@@ -84,37 +97,39 @@ var append = function(data, service) {
8497
json: {
8598
term: data[f.name]
8699
}
87-
}
100+
};
88101

89102
if (service.username && service.password) {
90103
var auth = "Basic " + new Buffer(service.username + ":" + service.password).toString("base64");
91104
opts.headers = {
92105
"Authorization" : auth
93-
}
106+
};
94107
}
95108

96109
request.put(opts, function(err, res, body) {
97-
return callback(err, body)
98-
})
110+
return callback(err, body);
111+
});
99112

100-
}
113+
};
101114

102115
});
103116

104117
async.series(actions, function(err, results) {
105118

106-
if (err) return console.log(err);
119+
if (err) {
120+
return console.log(err);
121+
}
107122

108123
console.log("autocomplete appended");
109124
console.log(results);
110125

111-
})
126+
});
112127

113-
})
128+
});
114129

115-
}
130+
};
116131

117132
module.exports = {
118133
populate: populate,
119134
append: append
120-
}
135+
};

0 commit comments

Comments
 (0)