mirror of
https://github.com/nasa/openmct.git
synced 2025-02-20 17:33:23 +00:00
[Search] Style
Made style compliance changes.
This commit is contained in:
parent
e0e5ad1347
commit
dc53cf60d1
@ -50,11 +50,16 @@ define(
|
||||
function filterRepeats(results) {
|
||||
var ids = [],
|
||||
idToIndicies = {}, // 'dictionary' mapping IDs to a list of indicies
|
||||
filteredResults = [];
|
||||
filteredResults = [],
|
||||
i,
|
||||
id,
|
||||
indicies,
|
||||
highestScoringObject,
|
||||
j;
|
||||
|
||||
// Create a list of indicies of objects that correspond to any object ID
|
||||
for (var i = 0; i < results.length; i++) {
|
||||
var id = results[i].id;
|
||||
for (i = 0; i < results.length; i += 1) {
|
||||
id = results[i].id;
|
||||
|
||||
if (idToIndicies[id]) {
|
||||
// If the ID already exists in the dictionary, push this index to
|
||||
@ -71,13 +76,12 @@ define(
|
||||
|
||||
// Now for each ID in the dictionary, we want to use the version of
|
||||
// the object that has a higher score
|
||||
for (var i = 0; i < ids.length; i++) {
|
||||
var id = ids[i],
|
||||
indicies = idToIndicies[id],
|
||||
highestScoringObject;
|
||||
for (i = 0; i < ids.length; i += 1) {
|
||||
id = ids[i];
|
||||
indicies = idToIndicies[id];
|
||||
|
||||
highestScoringObject = results[ indicies[0] ];
|
||||
for (var j = 0; j < indicies.length; j++) {
|
||||
highestScoringObject = results[indicies[0]];
|
||||
for (j = 0; j < indicies.length; j += 1) {
|
||||
// If the score of the object corresponding to this index of the results
|
||||
// list has a higher score than the one we have, choose it instead
|
||||
if (results[indicies[j]].score > highestScoringObject.score) {
|
||||
@ -109,10 +113,11 @@ define(
|
||||
// For documentation, see updateResults below.
|
||||
function updateResults() {
|
||||
var newerResults = [],
|
||||
providerTimestamps = [];
|
||||
providerTimestamps = [],
|
||||
i;
|
||||
|
||||
// For each provider, get its most recent results
|
||||
for (var i = 0; i < providers.length; i += 1) {
|
||||
for (i = 0; i < providers.length; i += 1) {
|
||||
newerResults = newerResults.concat(providers[i].getLatestResults());
|
||||
providerTimestamps.push(providers[i].getLatestTimestamp());
|
||||
}
|
||||
@ -136,7 +141,7 @@ define(
|
||||
|
||||
// Check to make sure that these results are the latest ones
|
||||
function waitForLatest() {
|
||||
var areOld = lastMergeTimestamps.some(function(c) {return c < lastQueryTimestamp;});
|
||||
var areOld = lastMergeTimestamps.some(function (c) {return c < lastQueryTimestamp; });
|
||||
|
||||
// If any of the timestamps are older than the one we made the query with
|
||||
if (areOld) {
|
||||
@ -154,9 +159,12 @@ define(
|
||||
|
||||
// For documentation, see sendQuery below.
|
||||
function queryAll(inputText, callback, timestamp) {
|
||||
var date,
|
||||
i;
|
||||
|
||||
// If there's not a timestamp, make this time the timestamp
|
||||
if (!timestamp) {
|
||||
var date = new Date();
|
||||
date = new Date();
|
||||
timestamp = date.getTime();
|
||||
}
|
||||
|
||||
@ -164,7 +172,7 @@ define(
|
||||
lastQueryTimestamp = timestamp;
|
||||
|
||||
// Send the query to all the providers
|
||||
for (var i = 0; i < providers.length; i += 1) {
|
||||
for (i = 0; i < providers.length; i += 1) {
|
||||
providers[i].query(inputText, timestamp, DEFAULT_MAX_RESULTS, DEFUALT_TIMEOUT);
|
||||
}
|
||||
|
||||
|
@ -88,7 +88,7 @@ define(function () {
|
||||
*/
|
||||
areMore: function () {
|
||||
return numResults < searchService.getNumResults();
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* Increases the number of search results to display, and then
|
||||
|
@ -41,7 +41,7 @@ define(function () {
|
||||
// Check to make sure that these results are the latest ones
|
||||
function waitForLatest() {
|
||||
var timestamps = searchService.getLatestTimestamps(),
|
||||
areOld = timestamps.some(function(c) {return c < timestamp;});
|
||||
areOld = timestamps.some(function (c) {return c < timestamp; });
|
||||
// If any of the timestamps are older than the one we made the query with
|
||||
if (areOld) {
|
||||
// Then wait and try to update again
|
||||
@ -93,7 +93,7 @@ define(function () {
|
||||
*/
|
||||
areMore: function () {
|
||||
return numResults < searchService.getNumResults();
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* Increases the number of search results to display, and then
|
||||
|
@ -47,7 +47,7 @@ define(
|
||||
* interact with ElasticSearch.
|
||||
*/
|
||||
function ElasticsearchSearchProvider($http, objectService, ROOT) {
|
||||
var latestResults = [],
|
||||
var latestResults = [],
|
||||
lastSearchTimestamp = 0;
|
||||
|
||||
// Check to see if the input has any special options
|
||||
@ -104,7 +104,8 @@ define(
|
||||
resultsLength = results.length,
|
||||
ids = [],
|
||||
scores = {},
|
||||
searchResults = [];
|
||||
searchResults = [],
|
||||
i;
|
||||
|
||||
/*
|
||||
if (rawResults.data.hits.total > resultsLength) {
|
||||
@ -114,20 +115,23 @@ define(
|
||||
*/
|
||||
|
||||
// Get the result objects' IDs
|
||||
for (var i = 0; i < resultsLength; i += 1) {
|
||||
for (i = 0; i < resultsLength; i += 1) {
|
||||
ids.push(results[i][ID]);
|
||||
}
|
||||
|
||||
// Get the result objects' scores
|
||||
for (var i = 0; i < resultsLength; i += 1) {
|
||||
for (i = 0; i < resultsLength; i += 1) {
|
||||
//scores.push(results[i][SCORE]);
|
||||
scores[ ids[i] ] = results[i][SCORE];
|
||||
scores[ids[i]] = results[i][SCORE];
|
||||
}
|
||||
|
||||
// Get the domain objects from their IDs
|
||||
return objectService.getObjects(ids).then(function (objects) {
|
||||
for (var j = 0; j < resultsLength; j += 1) {
|
||||
var id = ids[j];
|
||||
var j,
|
||||
id;
|
||||
|
||||
for (j = 0; j < resultsLength; j += 1) {
|
||||
id = ids[j];
|
||||
|
||||
// Include items we can get models for
|
||||
if (objects[id].getModel) {
|
||||
|
@ -51,7 +51,7 @@ define(
|
||||
// Tell the web worker to add a new item's model to its list of items.
|
||||
function indexItem(domainObject) {
|
||||
var message = {
|
||||
request: 'index',
|
||||
request: 'index',
|
||||
model: domainObject.getModel(),
|
||||
id: domainObject.getId()
|
||||
};
|
||||
@ -65,26 +65,29 @@ define(
|
||||
// less than that if there are fewer matches).
|
||||
function workerSearch(searchInput, maxResults, timestamp) {
|
||||
var message = {
|
||||
request: 'search',
|
||||
request: 'search',
|
||||
input: searchInput,
|
||||
maxNumber: maxResults,
|
||||
maxNumber: maxResults,
|
||||
timestamp: timestamp
|
||||
};
|
||||
worker.postMessage(message);
|
||||
}
|
||||
|
||||
worker.onmessage = handleResponse;
|
||||
|
||||
function handleResponse(event) {
|
||||
var ids,
|
||||
id;
|
||||
|
||||
if (event.data.request === 'search') {
|
||||
// Convert the ids given from the web worker into domain objects
|
||||
var ids = [];
|
||||
for (var id in event.data.results) {
|
||||
ids = [];
|
||||
for (id in event.data.results) {
|
||||
ids.push(id);
|
||||
}
|
||||
objectService.getObjects(ids).then(function (objects) {
|
||||
var id;
|
||||
|
||||
latestResults = [];
|
||||
for (var id in objects) {
|
||||
for (id in objects) {
|
||||
latestResults.push({
|
||||
object: objects[id],
|
||||
id: id,
|
||||
@ -96,9 +99,11 @@ define(
|
||||
}
|
||||
}
|
||||
|
||||
worker.onmessage = handleResponse;
|
||||
|
||||
// Recursive helper function for getItems()
|
||||
function itemsHelper(children, i) {
|
||||
var date = new Date;
|
||||
var date = new Date();
|
||||
if (stopTime && date.getTime() >= stopTime) {
|
||||
// This indexing of items has timed out
|
||||
return children;
|
||||
@ -120,35 +125,40 @@ define(
|
||||
|
||||
// Converts the filetree into a list
|
||||
function getItems(timeout) {
|
||||
var rootIds = [];
|
||||
var rootIds = [],
|
||||
i;
|
||||
|
||||
for (var i = 0; i < roots.length; i++) {
|
||||
for (i = 0; i < roots.length; i += 1) {
|
||||
rootIds.push(roots[i].id);
|
||||
}
|
||||
|
||||
// Aquire root objects
|
||||
return objectService.getObjects(rootIds).then(function (objectsById) {
|
||||
var objects = [];
|
||||
var objects = [],
|
||||
date,
|
||||
id;
|
||||
|
||||
if (timeout) {
|
||||
// Set a timeout for itemsHelper
|
||||
var date = new Date;
|
||||
date = new Date();
|
||||
stopTime = date.getTime() + timeout;
|
||||
}
|
||||
// If there was no timeout provided, leave undefined
|
||||
// itemsHelper should just treat this as having no timeout
|
||||
|
||||
// Convert to the format itemsHelper takes
|
||||
for (var id in objectsById) {
|
||||
for (id in objectsById) {
|
||||
objects.push(objectsById[id]);
|
||||
}
|
||||
|
||||
// Get all of its descendents
|
||||
return itemsHelper(objects, 0).then(function (items) {
|
||||
var i;
|
||||
|
||||
// Add each item that itemsHelper found to the web worker index
|
||||
// TODO: Try to do this within itemsHelper. Perhaps just
|
||||
// need to add this to the last two if statements?
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
for (i = 0; i < items.length; i += 1) {
|
||||
indexItem(items[i]);
|
||||
}
|
||||
return; // We don't need to return anything anymore
|
||||
|
@ -33,7 +33,9 @@
|
||||
|
||||
// Helper function for index()
|
||||
function conainsItem(id) {
|
||||
for (var i = 0; i < indexedItems.length; i++) {
|
||||
var i;
|
||||
|
||||
for (i = 0; i < indexedItems.length; i += 1) {
|
||||
if (indexedItems[i].id === id) {
|
||||
return true;
|
||||
}
|
||||
@ -49,6 +51,8 @@
|
||||
* * id: The ID of the domain object
|
||||
*/
|
||||
function index(data) {
|
||||
var message;
|
||||
|
||||
// TODO: Since this is only within genericsearch, do
|
||||
// we really need to check if the index already holds it?
|
||||
// This might depend on how often/when we clear indexedItems.
|
||||
@ -59,7 +63,7 @@
|
||||
});
|
||||
}
|
||||
|
||||
var message = {
|
||||
message = {
|
||||
request: 'index'
|
||||
};
|
||||
return message;
|
||||
@ -91,7 +95,8 @@
|
||||
function scoreItem(item, input, terms) {
|
||||
var name = item.model.name.toLocaleLowerCase(),
|
||||
weight = 0.65,
|
||||
score = 0.0;
|
||||
score = 0.0,
|
||||
i;
|
||||
|
||||
// Make the score really big if the item name and
|
||||
// the original search input are the same
|
||||
@ -99,16 +104,16 @@
|
||||
score = 42;
|
||||
}
|
||||
|
||||
for (var i = 0; i < terms.length; i++) {
|
||||
for (i = 0; i < terms.length; i += 1) {
|
||||
// Increase the score if the term is in the item name
|
||||
if (name.includes(terms[i])) {
|
||||
score++;
|
||||
score += 1;
|
||||
|
||||
// Add extra to the score if the search term exists
|
||||
// as its own term within the items
|
||||
// TODO: This may be undesired
|
||||
if (name.split(' ').indexOf(terms[i]) !== -1) {
|
||||
score += .5;
|
||||
score += 0.5;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -132,14 +137,16 @@
|
||||
// specific search input.)
|
||||
var results = {},
|
||||
input = data.input.toLocaleLowerCase(),
|
||||
terms = convertToTerms(input),
|
||||
timesToLoop = Math.min(indexedItems.length, data.maxNumber);
|
||||
|
||||
terms = convertToTerms(input),
|
||||
timesToLoop = Math.min(indexedItems.length, data.maxNumber),
|
||||
i,
|
||||
score,
|
||||
message;
|
||||
|
||||
// If the user input is empty, we want to have no search results.
|
||||
if (input !== '') {
|
||||
for (var i = 0; i < timesToLoop; i++) {
|
||||
var score = scoreItem(indexedItems[i], input, terms);
|
||||
for (i = 0; i < timesToLoop; i += 1) {
|
||||
score = scoreItem(indexedItems[i], input, terms);
|
||||
if (score > 0) {
|
||||
results[indexedItems[i].id] = {
|
||||
score: score
|
||||
@ -148,8 +155,8 @@
|
||||
}
|
||||
}
|
||||
|
||||
var message = {
|
||||
request: 'search',
|
||||
message = {
|
||||
request: 'search',
|
||||
results: results,
|
||||
timestamp: data.timestamp
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user