Skip to content

Commit 5c7ea9d

Browse files
committed
Merge pull request #33 from ibm-cds-labs/simple-search-service-update
display content in API page when facet on array of strings
2 parents b23cd89 + 31b52df commit 5c7ea9d

File tree

4 files changed

+65
-2
lines changed

4 files changed

+65
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ start.sh
77
.jshintrc
88
.project
99
npm-debug.log
10+
.vscode

app.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var express = require('express'),
1212
cache = require('./lib/cache.js'),
1313
schema = require('./lib/schema.js'),
1414
isloggedin = require('./lib/isloggedin.js'),
15+
sssenv = require('./lib/sssenv.js'),
1516
inference = require('./lib/inference.js');
1617

1718

@@ -134,12 +135,17 @@ app.get('/settings', isloggedin(), function (req, res) {
134135
if (err) {
135136
return res.status(err.statusCode).send({error: err.error, reason: err.reason});
136137
}
138+
data["appenv"] = sssenv;
137139
res.send(data);
138140
});
139141
});
140142

141143
app.post('/settings', isloggedin(), bodyParser, function(req, res) {
142-
db.settings(req.body, function(err, data) {
144+
var settings = req.body;
145+
if (settings.hasOwnProperty("appenv")) {
146+
delete settings.appenv;
147+
}
148+
db.settings(settings, function(err, data) {
143149
if (err) {
144150
return res.status(err.statusCode).send({error: err.error, reason: err.reason});
145151
}

lib/sssenv.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
var appEnv = require('cfenv').getAppEnv();
2+
3+
var app = {
4+
name: appEnv.app ? (appEnv.app.application_name || null) : null,
5+
id: appEnv.app ? (appEnv.app.application_id || null) : null,
6+
urls: appEnv.app ? (appEnv.app.uris || null) : null,
7+
host: null
8+
}
9+
10+
if (!appEnv.isLocal && app.id) {
11+
app.host = "https://console.ng.bluemix.net/?direct=classic/#/resources/appGuid=" + app.id;
12+
}
13+
14+
var dbservice = appEnv.services["cloudantNoSQLDB"]
15+
? appEnv.services["cloudantNoSQLDB"][0]
16+
: {};
17+
18+
var cloudant = {
19+
name: dbservice.name,
20+
username: dbservice.credentials ? dbservice.credentials.username : null,
21+
url: dbservice.credentials ? dbservice.credentials.url : null
22+
}
23+
24+
if (cloudant.url) {
25+
//strip username/password
26+
cloudant.url = cloudant.url.replace(/:\/\/\S+:\S+@/i, '://');
27+
}
28+
else {
29+
cloudant.url = dbservice.credentials ? (dbservice.credentials.host + ":" + dbservice.credentials.port) : "";
30+
}
31+
32+
if (cloudant.url && cloudant.url.indexOf("cloudant.com") > -1) {
33+
//cloudant.com
34+
cloudant.url += "/dashboard.html#/database/seams/_all_docs";
35+
}
36+
else {
37+
//couchdb
38+
cloudant.url += "/_utils/database.html?seams";
39+
}
40+
41+
var cacheservice = appEnv.getService("Redis by Compose") || {};
42+
var redis = {
43+
name: (cacheservice.name || null),
44+
username: cacheservice.credentials ? (cacheservice.credentials.username || null) : null,
45+
host: cacheservice.credentials ? (cacheservice.credentials.public_hostname || null) : null
46+
};
47+
48+
var sssenv = {
49+
application: app,
50+
storage: cloudant,
51+
cache: redis
52+
};
53+
54+
module.exports = sssenv;

public/js/seams.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ seamsApp.controller('seamsController', ['$scope', '$route', '$routeParams', '$lo
466466
var unfacetedfields = [];
467467
var facetedfields = [];
468468
for(var i in data.fields) {
469-
if (data.fields[i].type === "string") {
469+
if (data.fields[i].type === "string" || data.fields[i].type === "arrayofstrings") {
470470
if (data.fields[i].facet == true) {
471471
facetedfields.push(data.fields[i].name);
472472
}
@@ -498,10 +498,12 @@ seamsApp.controller('seamsController', ['$scope', '$route', '$routeParams', '$lo
498498
var restapi = '/settings';
499499
$http.get(restapi)
500500
.success(function(data) {
501+
$scope.$root.appenv = data ? data.appenv : {};
501502
$scope.$root.settings = data;
502503
})
503504
.error(function(data, status, headers, config) {
504505
console.log("Error retrieving settings:", data, status);
506+
$scope.$root.appenv = $scope.$root.appenv || {};
505507
$scope.$root.settings = {};
506508
});
507509
};

0 commit comments

Comments
 (0)