[Search] Input checks

More checks to see if the input is empty
before doing search computations.
This commit is contained in:
slhale 2015-08-11 13:08:58 -07:00
parent a48a0820ad
commit 11a45e4db0
3 changed files with 27 additions and 19 deletions

View File

@ -148,7 +148,7 @@ define(
} }
// If the user input is empty, we want to have no search results. // If the user input is empty, we want to have no search results.
if (searchTerm !== '') { if (searchTerm !== '' && searchTerm !== undefined) {
// Process the search term // Process the search term
searchTerm = processSearchTerm(searchTerm); searchTerm = processSearchTerm(searchTerm);

View File

@ -40,7 +40,9 @@ define(function () {
var inputText = $scope.ngModel.input; var inputText = $scope.ngModel.input;
// We are starting to load. // We are starting to load.
loading = true; if (inputText !== '' && inputText !== undefined) {
loading = true;
}
// Update whether the file tree should be displayed // Update whether the file tree should be displayed
// Hide tree only when starting search // Hide tree only when starting search

View File

@ -184,31 +184,37 @@ define(
}); });
} }
// For documentation, see query below // For documentation, see query below
function query(input, timestamp, maxResults, timeout) { function query(input, timestamp, maxResults, timeout) {
var terms = [], var terms = [],
searchResults = [], searchResults = [],
defer = $q.defer(); defer = $q.defer();
// Allow us to access this promise later to resolve it later // If the input is nonempty, do a search
pendingQueries[timestamp] = defer; if (input !== '' && input !== undefined) {
// Check to see if the user provided a maximum // Allow us to access this promise later to resolve it later
// number of results to display pendingQueries[timestamp] = defer;
if (!maxResults) {
// Else, we provide a default value // Check to see if the user provided a maximum
maxResults = DEFAULT_MAX_RESULTS; // 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 // Index the tree's contents once at the beginning