Skip to content

Commit

Permalink
Merge pull request #10 from sat-utils/feature/custom_client
Browse files Browse the repository at this point in the history
accept custom es client
  • Loading branch information
drewbo authored Jun 12, 2017
2 parents a5510b5 + 23cefce commit 89ba0c4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions libs/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ if (_.has(process.env, 'AWS_ACCESS_KEY_ID') && _.has(process.env, 'AWS_SECRET_AC
}
}


var client = new elasticsearch.Client(esConfig);

// converts string intersect to js object
Expand All @@ -42,7 +43,7 @@ var intersectsToObj = function (intersects) {
return intersects;
};

var Search = function (event) {
var Search = function (event, customClient) {
var params;

logger.debug('received query:', event.query);
Expand Down Expand Up @@ -72,6 +73,8 @@ var Search = function (event) {
this.size = parseInt((params.limit) ? params.limit : 1);
this.frm = (page - 1) * this.size;
this.page = parseInt((params.skip) ? params.skip : page);

this.client = customClient || client;
};

var aoiCoveragePercentage = function (feature, scene, aoiArea) {
Expand Down Expand Up @@ -196,7 +199,7 @@ Search.prototype.legacy = function (callback) {
}

// limit search to only landsat
client.search(searchParams).then(function (body) {
this.client.search(searchParams).then(function (body) {
var response = [];
var count = 0;

Expand Down Expand Up @@ -246,7 +249,7 @@ Search.prototype.simple = function (callback) {

logger.debug(JSON.stringify(searchParams));

client.search(searchParams).then(function (body) {
this.client.search(searchParams).then(function (body) {
var response = [];
var count = 0;

Expand Down Expand Up @@ -291,7 +294,7 @@ Search.prototype.geojson = function (callback) {
return callback(e, null);
}

client.search(searchParams).then(function (body) {
this.client.search(searchParams).then(function (body) {
var count = body.hits.total;

var response = {
Expand Down Expand Up @@ -334,7 +337,7 @@ Search.prototype.count = function (callback) {
return callback(e, null);
}

client.search(searchParams).then(function (body) {
this.client.search(searchParams).then(function (body) {
var count = 0;

count = body.hits.total;
Expand Down Expand Up @@ -366,7 +369,7 @@ Search.prototype.health = function (callback) {
return callback(e, null);
}

client.search(searchParams).then(function (body) {
this.client.search(searchParams).then(function (body) {
var limit = 3000;
var count = 0;

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sat-api-lib",
"version": "0.5.0",
"version": "0.5.1",
"description": "A library for creating a search API of public Satellites metadata using Elasticsearch",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 89ba0c4

Please sign in to comment.