From 11a45e4db0d393bb3937b2d3e11cc76540895349 Mon Sep 17 00:00:00 2001 From: slhale Date: Tue, 11 Aug 2015 13:08:58 -0700 Subject: [PATCH] [Search] Input checks More checks to see if the input is empty before doing search computations. --- .../elastic/src/ElasticSearchProvider.js | 2 +- .../src/controllers/SearchController.js | 4 +- .../src/services/GenericSearchProvider.js | 40 +++++++++++-------- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/platform/persistence/elastic/src/ElasticSearchProvider.js b/platform/persistence/elastic/src/ElasticSearchProvider.js index f8150ddafc..2f8d91fa08 100644 --- a/platform/persistence/elastic/src/ElasticSearchProvider.js +++ b/platform/persistence/elastic/src/ElasticSearchProvider.js @@ -148,7 +148,7 @@ define( } // If the user input is empty, we want to have no search results. - if (searchTerm !== '') { + if (searchTerm !== '' && searchTerm !== undefined) { // Process the search term searchTerm = processSearchTerm(searchTerm); diff --git a/platform/search/src/controllers/SearchController.js b/platform/search/src/controllers/SearchController.js index 1ecccd5c2d..d1f0e5b091 100644 --- a/platform/search/src/controllers/SearchController.js +++ b/platform/search/src/controllers/SearchController.js @@ -40,7 +40,9 @@ define(function () { var inputText = $scope.ngModel.input; // We are starting to load. - loading = true; + if (inputText !== '' && inputText !== undefined) { + loading = true; + } // Update whether the file tree should be displayed // Hide tree only when starting search diff --git a/platform/search/src/services/GenericSearchProvider.js b/platform/search/src/services/GenericSearchProvider.js index 068f304321..a68f5323af 100644 --- a/platform/search/src/services/GenericSearchProvider.js +++ b/platform/search/src/services/GenericSearchProvider.js @@ -184,31 +184,37 @@ define( }); } - // For documentation, see query below function query(input, timestamp, maxResults, timeout) { var terms = [], searchResults = [], defer = $q.defer(); - // Allow us to access this promise later to resolve it later - pendingQueries[timestamp] = defer; + // If the input is nonempty, do a search + if (input !== '' && input !== undefined) { + + // Allow us to access this promise later to resolve it later + pendingQueries[timestamp] = defer; - // Check to see if the user provided a maximum - // number of results to display - if (!maxResults) { - // Else, we provide a default value - maxResults = DEFAULT_MAX_RESULTS; + // Check to see if the user provided a maximum + // number of results to display + if (!maxResults) { + // Else, we provide a default value + maxResults = DEFAULT_MAX_RESULTS; + } + // Similarly, check if timeout was provided + if (!timeout) { + timeout = DEFAULT_TIMEOUT; + } + + // Send the query to the worker + workerSearch(input, maxResults, timestamp, timeout); + + return defer.promise; + } else { + // Otherwise return an empty result + return {hits: [], total: 0}; } - // Similarly, check if timeout was provided - if (!timeout) { - timeout = DEFAULT_TIMEOUT; - } - - // Send the query to the worker - workerSearch(input, maxResults, timestamp, timeout); - - return defer.promise; } // Index the tree's contents once at the beginning