mirror of
https://github.com/nasa/openmct.git
synced 2025-02-22 02:06:49 +00:00
[Search] Comments
Updated the documentation.
This commit is contained in:
parent
92df11acc1
commit
4191bc1ac3
@ -44,7 +44,7 @@ define(
|
|||||||
var latestMergedResults = [],
|
var latestMergedResults = [],
|
||||||
lastMergeTimestamps = [];
|
lastMergeTimestamps = [];
|
||||||
|
|
||||||
// Remove extra objects that have the same ID
|
// Remove duplicate objects that have the same ID
|
||||||
function filterRepeats(results) {
|
function filterRepeats(results) {
|
||||||
var ids = [],
|
var ids = [],
|
||||||
idToIndicies = {}, // 'dictionary' mapping IDs to a list of indicies
|
idToIndicies = {}, // 'dictionary' mapping IDs to a list of indicies
|
||||||
@ -104,6 +104,7 @@ define(
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For documentation, see updateResults below.
|
||||||
function updateResults() {
|
function updateResults() {
|
||||||
var newerResults = [],
|
var newerResults = [],
|
||||||
providerTimestamps = [];
|
providerTimestamps = [];
|
||||||
@ -123,17 +124,7 @@ define(
|
|||||||
lastMergeTimestamps = providerTimestamps;
|
lastMergeTimestamps = providerTimestamps;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// For documentation, see sendQuery below.
|
||||||
* Sends a query to each of the providers, then updates the globl
|
|
||||||
* latestMergedResults accordingly.
|
|
||||||
*
|
|
||||||
* @param inputID The name of the ID property of the html text
|
|
||||||
* input where this funcion should find the search term.
|
|
||||||
* @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
|
|
||||||
* updated. If not provided, this aggregator will.
|
|
||||||
*/
|
|
||||||
function queryAll(inputID, timestamp) {
|
function queryAll(inputID, timestamp) {
|
||||||
// If there's not a timestamp, make this time the timestamp
|
// If there's not a timestamp, make this time the timestamp
|
||||||
if (!timestamp) {
|
if (!timestamp) {
|
||||||
@ -151,18 +142,48 @@ define(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
/**
|
||||||
|
* 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 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
|
||||||
|
* updated. If not provided, this aggregator will.
|
||||||
|
*/
|
||||||
sendQuery: queryAll,
|
sendQuery: queryAll,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the global latestMergedResults and lastMergeTimestamps
|
||||||
|
* by checking the latest results of each of the providers.
|
||||||
|
*/
|
||||||
updateResults: updateResults,
|
updateResults: updateResults,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the latest search results that have been calculated. The
|
||||||
|
* format of the returned objects are searchResult objects, which
|
||||||
|
* have the members id, object, and score.
|
||||||
|
*
|
||||||
|
* @param start (optional) The index of latestMergedResults at
|
||||||
|
* which to start getting results.
|
||||||
|
* @param stop (optional) The index of latestMergedResults at
|
||||||
|
* which to stop getting results.
|
||||||
|
*/
|
||||||
getLatestResults: function (start, stop) {
|
getLatestResults: function (start, stop) {
|
||||||
// TODO: Make sure that slice handles out of bounds
|
// TODO: Make sure that slice handles out of bounds
|
||||||
// By default if there are no start or stop provided, will return
|
// By default if there are no start or stop provided, will return
|
||||||
// the entire thing.
|
// the entire thing.
|
||||||
var a = latestMergedResults.slice(start, stop);
|
return latestMergedResults.slice(start, stop);
|
||||||
return a;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the timestamps for each of the provider's last controbutions
|
||||||
|
* to the latestMergedResults.
|
||||||
|
*/
|
||||||
getLatestTimestamps: function () {
|
getLatestTimestamps: function () {
|
||||||
var b = lastMergeTimestamps;
|
return lastMergeTimestamps;
|
||||||
return b;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,6 @@ define(function () {
|
|||||||
if (areOld) {
|
if (areOld) {
|
||||||
// Then wait and try to update again
|
// Then wait and try to update again
|
||||||
searchService.updateResults();
|
searchService.updateResults();
|
||||||
var latest = searchService.getLatestResults(0, numResults);
|
|
||||||
$timeout(waitForLatest, 100);
|
$timeout(waitForLatest, 100);
|
||||||
} else {
|
} else {
|
||||||
// We got the latest results now
|
// We got the latest results now
|
||||||
@ -60,10 +59,17 @@ define(function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
// Search the database using the user input of id "searchinput"
|
/**
|
||||||
|
* Search the filetree.
|
||||||
|
*
|
||||||
|
* @param inputID The name of the ID property of the html text
|
||||||
|
* input where this funcion should find the search term.
|
||||||
|
*/
|
||||||
search: search,
|
search: search,
|
||||||
|
|
||||||
// Check to see if there are any search results to display.
|
/**
|
||||||
|
* Checks to see if there are any search results to display.
|
||||||
|
*/
|
||||||
areResults: function () {
|
areResults: function () {
|
||||||
if ($scope.results) {
|
if ($scope.results) {
|
||||||
return $scope.results.length > 0;
|
return $scope.results.length > 0;
|
||||||
|
@ -144,29 +144,7 @@ define(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// For documentation, see query below.
|
||||||
* Searches through the filetree for domain objects using a search
|
|
||||||
* term. This is done through querying elasticsearch.
|
|
||||||
* Notes:
|
|
||||||
* * The order of the results is from highest to lowest score,
|
|
||||||
* as elsaticsearch determines them to be.
|
|
||||||
* * Wildcards are supported.
|
|
||||||
* * Fuzziness is used to produce more results that are still
|
|
||||||
* relevant. (All results within a certain edit distance.)
|
|
||||||
* * 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
|
|
||||||
* 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
|
|
||||||
* list, which allows the aggregator to see if it has been
|
|
||||||
* updated
|
|
||||||
* @param maxResults (optional) the maximum number of results
|
|
||||||
* that this function should return
|
|
||||||
* @param timeout (optional) the time after which the search should
|
|
||||||
* stop calculations and return partial results
|
|
||||||
*/
|
|
||||||
function queryElasticsearch(inputID, timestamp, maxResults, timeout) {
|
function queryElasticsearch(inputID, timestamp, maxResults, timeout) {
|
||||||
var searchTerm,
|
var searchTerm,
|
||||||
esQuery;
|
esQuery;
|
||||||
@ -202,12 +180,43 @@ define(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
/**
|
||||||
|
* Searches through the filetree for domain objects using a search
|
||||||
|
* term. This is done through querying elasticsearch.
|
||||||
|
* Notes:
|
||||||
|
* * The order of the results is from highest to lowest score,
|
||||||
|
* as elsaticsearch determines them to be.
|
||||||
|
* * Wildcards are supported.
|
||||||
|
* * Fuzziness is used to produce more results that are still
|
||||||
|
* relevant. (All results within a certain edit distance.)
|
||||||
|
* * 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
|
||||||
|
* 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
|
||||||
|
* list, which allows the aggregator to see if it has been
|
||||||
|
* updated
|
||||||
|
* @param maxResults (optional) the maximum number of results
|
||||||
|
* that this function should return
|
||||||
|
* @param timeout (optional) the time after which the search should
|
||||||
|
* stop calculations and return partial results
|
||||||
|
*/
|
||||||
query: queryElasticsearch,
|
query: queryElasticsearch,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the latest search results that have been calculated. The
|
||||||
|
* format of the returned objects are searchResult objects, which
|
||||||
|
* have the members id, object, and score.
|
||||||
|
*/
|
||||||
getLatestResults: function () {
|
getLatestResults: function () {
|
||||||
return latestResults;
|
return latestResults;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the timestamp for the last update of latestResults.
|
||||||
|
*/
|
||||||
getLatestTimestamp: function () {
|
getLatestTimestamp: function () {
|
||||||
return lastSearchTimestamp;
|
return lastSearchTimestamp;
|
||||||
}
|
}
|
||||||
|
@ -145,30 +145,7 @@ define(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// For documentation, see query below.
|
||||||
* Searches through the filetree for domain objects which match
|
|
||||||
* the search term. This function is to be used as a fallback
|
|
||||||
* in the case where other search services are not avaliable.
|
|
||||||
* Notes:
|
|
||||||
* * The order of the results is not guarenteed.
|
|
||||||
* * 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.
|
|
||||||
* * Wildcards are not (yet?) supported.
|
|
||||||
*
|
|
||||||
* @param inputID the name of the ID property of the html text
|
|
||||||
* 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
|
|
||||||
* list, which allows the aggregator to see if it has been
|
|
||||||
* updated
|
|
||||||
* @param maxResults (optional) the maximum number of results
|
|
||||||
* that this function should return
|
|
||||||
* @param timeout (optional) the time after which the search should
|
|
||||||
* stop calculations and return partial results
|
|
||||||
*/
|
|
||||||
function queryGeneric(inputID, timestamp, maxResults, timeout) {
|
function queryGeneric(inputID, timestamp, maxResults, timeout) {
|
||||||
var input,
|
var input,
|
||||||
terms = [],
|
terms = [],
|
||||||
@ -194,12 +171,44 @@ define(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
/**
|
||||||
|
* Searches through the filetree for domain objects which match
|
||||||
|
* the search term. This function is to be used as a fallback
|
||||||
|
* in the case where other search services are not avaliable.
|
||||||
|
* Notes:
|
||||||
|
* * The order of the results is not guarenteed.
|
||||||
|
* * 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.
|
||||||
|
* * Wildcards are not (yet?) supported.
|
||||||
|
*
|
||||||
|
* @param inputID the name of the ID property of the html text
|
||||||
|
* 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
|
||||||
|
* list, which allows the aggregator to see if it has been
|
||||||
|
* updated
|
||||||
|
* @param maxResults (optional) the maximum number of results
|
||||||
|
* that this function should return
|
||||||
|
* @param timeout (optional) the time after which the search should
|
||||||
|
* stop calculations and return partial results
|
||||||
|
*/
|
||||||
query: queryGeneric,
|
query: queryGeneric,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the latest search results that have been calculated. The
|
||||||
|
* format of the returned objects are searchResult objects, which
|
||||||
|
* have the members id, object, and score.
|
||||||
|
*/
|
||||||
getLatestResults: function () {
|
getLatestResults: function () {
|
||||||
return latestResults;
|
return latestResults;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the timestamp for the last update of latestResults.
|
||||||
|
*/
|
||||||
getLatestTimestamp: function () {
|
getLatestTimestamp: function () {
|
||||||
return lastSearchTimestamp;
|
return lastSearchTimestamp;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user