From 33e8084852a6f83e95dee87abd525ac461a4ec45 Mon Sep 17 00:00:00 2001 From: shale Date: Thu, 23 Jul 2015 16:10:03 -0700 Subject: [PATCH] [Search] Getting input text The controller now gets the input text from the DOM element ID, then passes that string along to the search service, instead of passing the raw ID. --- platform/features/search/src/SearchAggregator.js | 7 +++---- .../search/src/controllers/SearchController.js | 9 +++++++-- .../src/providers/ElasticsearchSearchProvider.js | 10 +++------- .../search/src/providers/GenericSearchProvider.js | 11 +++-------- 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/platform/features/search/src/SearchAggregator.js b/platform/features/search/src/SearchAggregator.js index bd2de34b65..21e7f65b35 100644 --- a/platform/features/search/src/SearchAggregator.js +++ b/platform/features/search/src/SearchAggregator.js @@ -125,7 +125,7 @@ define( } // For documentation, see sendQuery below. - function queryAll(inputID, timestamp) { + function queryAll(inputText, timestamp) { // If there's not a timestamp, make this time the timestamp if (!timestamp) { var date = new Date(); @@ -134,7 +134,7 @@ define( // Send the query to all the providers for (var i = 0; i < providers.length; i += 1) { - providers[i].query(inputID, timestamp, DEFAULT_MAX_RESULTS, DEFUALT_TIMEOUT); + providers[i].query(inputText, timestamp, DEFAULT_MAX_RESULTS, DEFUALT_TIMEOUT); } // Update the merged results list @@ -146,8 +146,7 @@ define( * Sends a query to each of the providers, then updates the global * latestMergedResults accordingly. * - * @param inputID The name of the ID property of the html text - * input where this funcion should find the search term. + * @param inputText The text input that is the query. * @param timestamp (optional) The time at which this function * was called. This timestamp will be associated with the * latest results list, which allows us to see if it has been diff --git a/platform/features/search/src/controllers/SearchController.js b/platform/features/search/src/controllers/SearchController.js index 335687add7..70edf748fe 100644 --- a/platform/features/search/src/controllers/SearchController.js +++ b/platform/features/search/src/controllers/SearchController.js @@ -70,13 +70,14 @@ define(function () { function search(inputID) { var date = new Date(), - timestamp = date.getTime(); + timestamp = date.getTime(), + inputText = document.getElementById(inputID).value; // Reset 'load more' numResults = INITIAL_LOAD_NUMBER; // Send the query - searchService.sendQuery(inputID, timestamp); + searchService.sendQuery(inputText, timestamp); update(timestamp); } @@ -101,6 +102,10 @@ define(function () { } }, + /** + * Checks to see if we are still waiting for the results to be + * fully updated. + */ isLoading: function () { return loading; }, diff --git a/platform/features/search/src/providers/ElasticsearchSearchProvider.js b/platform/features/search/src/providers/ElasticsearchSearchProvider.js index 88e4342893..cb4344aab8 100644 --- a/platform/features/search/src/providers/ElasticsearchSearchProvider.js +++ b/platform/features/search/src/providers/ElasticsearchSearchProvider.js @@ -145,9 +145,8 @@ define( } // For documentation, see query below. - function queryElasticsearch(inputID, timestamp, maxResults, timeout) { - var searchTerm, - esQuery; + function queryElasticsearch(searchTerm, timestamp, maxResults, timeout) { + var esQuery; // Check to see if the user provided a maximum // number of results to display @@ -156,9 +155,6 @@ define( maxResults = DEFAULT_MAX_RESULTS; } - // Get the user input - searchTerm = document.getElementById(inputID).value; - // If the user input is empty, we want to have no search results. if (searchTerm !== '') { // Process search term @@ -198,7 +194,7 @@ define( * * More search details at * https://www.elastic.co/guide/en/elasticsearch/reference/current/search-uri-request.html * - * @param inputID the name of the ID property of the html text + * @param searchTerm The text input that is the query. * input where this funcion should find the search term * @param timestamp the time at which this function was called, * this timestamp will be associated with the latest results diff --git a/platform/features/search/src/providers/GenericSearchProvider.js b/platform/features/search/src/providers/GenericSearchProvider.js index 1b5a1ef520..4099bbf6f3 100644 --- a/platform/features/search/src/providers/GenericSearchProvider.js +++ b/platform/features/search/src/providers/GenericSearchProvider.js @@ -158,9 +158,8 @@ define( } // For documentation, see query below. - function queryGeneric(inputID, timestamp, maxResults, timeout) { - var input, - terms = [], + function queryGeneric(input, timestamp, maxResults, timeout) { + var terms = [], searchResults = [], resultsLength; @@ -171,9 +170,6 @@ define( maxResults = DEFAULT_MAX_RESULTS; } - // Get the user input - input = document.getElementById(inputID).value; - // Get items list return getItems(timeout).then(function () { // Then get the worker to search through it @@ -195,8 +191,7 @@ define( * * Scores are higher for matches that have more than one of * the terms as substrings. * - * @param inputID the name of the ID property of the html text - * input where this funcion should find the search term + * @param input The text input that is the query. * @param timestamp the time at which this function was called, * this timestamp will be associated with the latest results * list, which allows the aggregator to see if it has been