From 48693df51f90ebc09882657f6fa8125c22414a3a Mon Sep 17 00:00:00 2001 From: slhale Date: Tue, 11 Aug 2015 13:52:23 -0700 Subject: [PATCH] [Search] Input checks More checks to see if the input is empty before doing search computations. --- .../src/ElasticsearchSearchProvider.js | 2 +- platform/search/src/GenericSearchProvider.js | 39 +++++++++++-------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/platform/persistence/elastic/src/ElasticsearchSearchProvider.js b/platform/persistence/elastic/src/ElasticsearchSearchProvider.js index 83b3bb593c..af13628af9 100644 --- a/platform/persistence/elastic/src/ElasticsearchSearchProvider.js +++ b/platform/persistence/elastic/src/ElasticsearchSearchProvider.js @@ -149,7 +149,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/GenericSearchProvider.js b/platform/search/src/GenericSearchProvider.js index 3351d7fd4e..36cf61f35f 100644 --- a/platform/search/src/GenericSearchProvider.js +++ b/platform/search/src/GenericSearchProvider.js @@ -191,24 +191,31 @@ define( 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