mirror of
https://github.com/nasa/openmct.git
synced 2025-02-20 09:26:45 +00:00
[Search] Comments and style
This commit is contained in:
parent
4439e1680d
commit
45bedb20c1
@ -37,9 +37,9 @@ define(
|
||||
* to be treated as one.
|
||||
*
|
||||
* @constructor
|
||||
* @param $q Angular's $q, for promise consolidation
|
||||
* @param {SearchProvider[]} providers the search providers to be
|
||||
* aggregated
|
||||
* @param $q Angular's $q, for promise consolidation.
|
||||
* @param {SearchProvider[]} providers The search providers to be
|
||||
* aggregated.
|
||||
*/
|
||||
function SearchAggregator($q, providers) {
|
||||
|
||||
@ -82,7 +82,7 @@ define(
|
||||
return results;
|
||||
}
|
||||
|
||||
// For documentation, see sendQuery below.
|
||||
// For documentation, see query below.
|
||||
function queryAll(inputText, maxResults) {
|
||||
var i,
|
||||
timestamp = Date.now(),
|
||||
|
@ -55,6 +55,7 @@ define(
|
||||
}
|
||||
|
||||
return searchTerm.split(' ').map(function (s) {
|
||||
// Don't add fuzziness for quoted strings
|
||||
if (s.indexOf('"') !== -1) {
|
||||
return s;
|
||||
} else {
|
||||
@ -84,13 +85,12 @@ define(
|
||||
// Add fuzziness for completeness
|
||||
searchTerm = addFuzziness(searchTerm);
|
||||
|
||||
//console.log('search term ', searchTerm);
|
||||
return searchTerm;
|
||||
}
|
||||
|
||||
// Processes results from the format that elasticsearch returns to
|
||||
// a list of search result objects (that contain domain objects), then
|
||||
// returns an object in the format {hits: searchResult[], total: number}
|
||||
// a list of searchResult objects, then returns a result object
|
||||
// (See documentation for query for object descriptions)
|
||||
function processResults(rawResults, timestamp) {
|
||||
var results = rawResults.data.hits.hits,
|
||||
resultsLength = results.length,
|
||||
|
@ -38,12 +38,12 @@ define(
|
||||
* the filetree without using external search implementations.
|
||||
*
|
||||
* @constructor
|
||||
* @param $q
|
||||
* @param {ObjectService} objectService the service from which
|
||||
* @param $q Angular's $q, for promise consolidation.
|
||||
* @param {ObjectService} objectService The service from which
|
||||
* domain objects can be gotten.
|
||||
* @param {WorkerService} workerService the service which allows
|
||||
* @param {WorkerService} workerService The service which allows
|
||||
* more easy creation of web workers.
|
||||
* @param {roots[]} roots an array of all the root domain objects.
|
||||
* @param {roots[]} roots An array of all the root domain objects.
|
||||
*/
|
||||
function GenericSearchProvider($q, objectService, workerService, roots) {
|
||||
var worker = workerService.run('genericSearchWorker'),
|
||||
@ -82,6 +82,8 @@ define(
|
||||
worker.postMessage(message);
|
||||
}
|
||||
|
||||
// Handles responses from the web worker. Namely, the results of
|
||||
// a search request.
|
||||
function handleResponse(event) {
|
||||
var ids = [],
|
||||
id;
|
||||
@ -96,7 +98,7 @@ define(
|
||||
var searchResults = [],
|
||||
id;
|
||||
|
||||
// Reset and repopulate the latest results
|
||||
// Create searchResult objects
|
||||
for (id in objects) {
|
||||
searchResults.push({
|
||||
object: objects[id],
|
||||
@ -106,20 +108,18 @@ define(
|
||||
}
|
||||
|
||||
// Resove the promise corresponding to this
|
||||
pendingQueries[event.data.timestamp].resolve(
|
||||
{
|
||||
hits: searchResults,
|
||||
total: event.data.total,
|
||||
timedOut: event.data.timedOut
|
||||
}
|
||||
);
|
||||
pendingQueries[event.data.timestamp].resolve({
|
||||
hits: searchResults,
|
||||
total: event.data.total,
|
||||
timedOut: event.data.timedOut
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
worker.onmessage = handleResponse;
|
||||
|
||||
// Recursive helper function for getItems()
|
||||
// Helper function for getItems(). Indexes the tree.
|
||||
function itemsHelper(children, i) {
|
||||
// Index the current node
|
||||
indexItem(children[i]);
|
||||
@ -153,7 +153,7 @@ define(
|
||||
var objects = [],
|
||||
id;
|
||||
|
||||
// Get each of the objects in objectsById
|
||||
// Get each of the domain objects in objectsById
|
||||
for (id in objectsById) {
|
||||
objects.push(objectsById[id]);
|
||||
}
|
||||
@ -164,18 +164,19 @@ define(
|
||||
}
|
||||
|
||||
|
||||
// For documentation, see query below.
|
||||
// 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;
|
||||
|
||||
// Check to see if the user provided a maximum
|
||||
// number of results to display
|
||||
if (!maxResults) {
|
||||
// Else, we provide a default value.
|
||||
// Else, we provide a default value
|
||||
maxResults = DEFAULT_MAX_RESULTS;
|
||||
}
|
||||
// Similarly, check if timeout was provided
|
||||
@ -183,8 +184,7 @@ define(
|
||||
timeout = DEFAULT_TIMEOUT;
|
||||
}
|
||||
|
||||
// Instead, assume that the items have already been indexed, and
|
||||
// just send the query to the worker.
|
||||
// Send the query to the worker
|
||||
workerSearch(input, maxResults, timestamp, timeout);
|
||||
|
||||
return defer.promise;
|
||||
@ -208,8 +208,8 @@ define(
|
||||
* * A domain object qualifies as a match for a search input if
|
||||
* the object's name property contains any of the search terms
|
||||
* (which are generated by splitting the input at spaces).
|
||||
* * Scores are higher for matches that have more than one of
|
||||
* the terms as substrings.
|
||||
* * Scores are higher for matches that have more of the terms
|
||||
* as substrings.
|
||||
*
|
||||
* @param input The text input that is the query.
|
||||
* @param timestamp The time at which this function was called.
|
||||
|
@ -32,6 +32,7 @@
|
||||
var indexedItems = [];
|
||||
|
||||
// Helper function for index()
|
||||
// Checks whether an item with this ID is already indexed
|
||||
function conainsItem(id) {
|
||||
var i;
|
||||
for (i = 0; i < indexedItems.length; i += 1) {
|
||||
@ -123,7 +124,7 @@
|
||||
*/
|
||||
function search(data) {
|
||||
// This results dictionary will have domain object ID keys which
|
||||
// point to the domain object's score.
|
||||
// point to the value the domain object's score.
|
||||
var results = {},
|
||||
input = data.input.toLocaleLowerCase(),
|
||||
terms = convertToTerms(input),
|
||||
|
Loading…
x
Reference in New Issue
Block a user