diff --git a/platform/features/search/bundle.json b/platform/features/search/bundle.json index 908741b183..fd01c28a12 100644 --- a/platform/features/search/bundle.json +++ b/platform/features/search/bundle.json @@ -44,6 +44,12 @@ "implementation": "providers/GenericSearchProvider.js", "depends": [ "$rootScope", "objectService", "workerService" ] }, + { + "provides": "searchService", + "type": "provider", + "implementation": "providers/ElasticsearchSearchProvider.js", + "depends": [ "$http", "objectService", "ELASTIC_ROOT" ] + }, { "provides": "searchService", "type": "aggregator", diff --git a/platform/features/search/src/providers/ElasticsearchSearchProvider.js b/platform/features/search/src/providers/ElasticsearchSearchProvider.js index c6a71e240b..14da8b3029 100644 --- a/platform/features/search/src/providers/ElasticsearchSearchProvider.js +++ b/platform/features/search/src/providers/ElasticsearchSearchProvider.js @@ -40,13 +40,15 @@ define( * the filetree using ElasticSearch. * * @constructor - * @param $http Angular's $http service, for working with urls + * @param $http Angular's $http service, for working with urls. * @param {ObjectService} objectService the service from which * domain objects can be gotten. * @param ROOT the constant ELASTIC_ROOT which allows us to * interact with ElasticSearch. */ function ElasticsearchSearchProvider($http, objectService, ROOT) { + var latestResults = [], + lastSearchTimestamp = 0; // Check to see if the input has any special options function isDefaultFormat(searchTerm) { @@ -97,7 +99,7 @@ define( // Processes results from the format that elasticsearch returns to // a list of objects in the format that mct-representation can use - function processResults(rawResults) { + function processResults(rawResults, timestamp) { var results = rawResults.data.hits.hits, resultsLength = results.length, ids = [], @@ -122,7 +124,6 @@ define( // Get the domain objects from their IDs return objectService.getObjects(ids).then(function (objects) { - // Filter by search term for (var j = 0; j < resultsLength; j += 1) { var id = ids[j]; @@ -137,7 +138,8 @@ define( } } - //console.log('searchResults (in ES provider)', searchResults); + latestResults = searchResults; + lastSearchTimestamp = timestamp; return searchResults; }); } @@ -195,12 +197,20 @@ define( url: esQuery }).then(function (rawResults) { // ...then process the data - return processResults(rawResults); + return processResults(rawResults, timestamp); }); } return { - query: queryElasticsearch + query: queryElasticsearch, + + getLatestResults: function () { + return latestResults; + }, + + getLatestTimestamp: function () { + return lastSearchTimestamp; + } }; } diff --git a/platform/features/search/src/workers/GenericSearchWorker.js b/platform/features/search/src/workers/GenericSearchWorker.js index 7c5c7cab12..336c2e1222 100644 --- a/platform/features/search/src/workers/GenericSearchWorker.js +++ b/platform/features/search/src/workers/GenericSearchWorker.js @@ -78,7 +78,6 @@ // Then split it at the spaces terms = terms.split(' '); - console.log('terms', terms); return terms; } @@ -136,7 +135,6 @@ results[indexedItems[i].id] = { score: score }; - console.log(results[indexedItems[i].id]); } }