mirror of
https://github.com/nasa/openmct.git
synced 2025-03-24 04:55:21 +00:00
[Search] Manual max results option
Manual search now takes a max number of results option, just like the elasticsearch version.
This commit is contained in:
parent
6b3088f241
commit
3420eb69d3
@ -40,6 +40,7 @@ define(
|
||||
* @constructor
|
||||
*/
|
||||
function QueryService($http, objectService, ROOT) {
|
||||
var DEFAULT_MAX_RESULTS = 2048;
|
||||
|
||||
/////////////// The following is for non-Elastic Search /////////////////
|
||||
|
||||
@ -75,14 +76,22 @@ define(
|
||||
|
||||
// Search through items for items manually
|
||||
// This is a fallback if other search services aren't avaliable
|
||||
function queryManual(inputID) {
|
||||
function queryManual(inputID, maxResults) {
|
||||
var term,
|
||||
searchResults = [],
|
||||
itemsLength,
|
||||
resultsLength,
|
||||
itemModel,
|
||||
itemName,
|
||||
i;
|
||||
|
||||
|
||||
// Check to see if the user provided a maximum
|
||||
// number of results to display
|
||||
if (!maxResults) {
|
||||
// Else, we provide a default value. This is an
|
||||
// arbitrary big number.
|
||||
maxResults = DEFAULT_MAX_RESULTS;
|
||||
}
|
||||
|
||||
// Get the user input
|
||||
term = document.getElementById(inputID).value;
|
||||
|
||||
@ -91,10 +100,15 @@ define(
|
||||
|
||||
// Get items list
|
||||
return getItems().then(function (items) {
|
||||
itemsLength = items.length;
|
||||
// Keep track of the number of results to display
|
||||
if (items.length < maxResults) {
|
||||
resultsLength = items.length;
|
||||
} else {
|
||||
resultsLength = maxResults;
|
||||
}
|
||||
|
||||
// Then filter through the items list
|
||||
for (i = 0; i < itemsLength; i += 1) {
|
||||
for (i = 0; i < resultsLength; i += 1) {
|
||||
// Prevent errors from getModel not being defined
|
||||
if (items[i].getModel) {
|
||||
itemModel = items[i].getModel();
|
||||
@ -106,8 +120,7 @@ define(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//$scope.results = searchResults; // Some redundancy
|
||||
|
||||
return searchResults;
|
||||
});
|
||||
}
|
||||
@ -214,7 +227,7 @@ define(
|
||||
if (!maxResults) {
|
||||
// Else, we provide a default value. This is an
|
||||
// arbitrary big number.
|
||||
maxResults = 2048;
|
||||
maxResults = DEFAULT_MAX_RESULTS;
|
||||
}
|
||||
|
||||
// Get the user input
|
||||
|
Loading…
x
Reference in New Issue
Block a user