mirror of
https://github.com/nasa/openmct.git
synced 2025-03-23 20:45:17 +00:00
[Search] Timeout passed from SearchAggregator
The timeout value is now an optional parameter of the providers, and the search aggregator now passes a common default value to all of them.
This commit is contained in:
parent
ed956d351d
commit
c0c0371451
@ -29,6 +29,9 @@ define(
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
var DEFUALT_TIMEOUT = 1000,
|
||||
DEFAULT_MAX_RESULTS = 100;
|
||||
|
||||
/**
|
||||
* Allows multiple services which provide search functionality
|
||||
* to be treated as one.
|
||||
@ -112,7 +115,11 @@ define(
|
||||
|
||||
// Get result list promises
|
||||
for (var i = 0; i < providers.length; i += 1) {
|
||||
resultsPromises.push(providers[i].query(inputID, validType));
|
||||
resultsPromises.push(
|
||||
providers[i].query(
|
||||
inputID, validType, DEFAULT_MAX_RESULTS, DEFUALT_TIMEOUT
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Wait for the promises to fufill
|
||||
|
@ -33,8 +33,7 @@ define(
|
||||
// so hide them here.
|
||||
var ID = "_id",
|
||||
SCORE = "_score",
|
||||
DEFAULT_MAX_RESULTS = 100,
|
||||
DEFAULT_TIMEOUT = 1000;
|
||||
DEFAULT_MAX_RESULTS = 100;
|
||||
|
||||
/**
|
||||
* A model service which reads domain object models from an external
|
||||
@ -171,9 +170,12 @@ define(
|
||||
* final list of results
|
||||
* @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, validType, maxResults) {
|
||||
var searchTerm;
|
||||
function queryElasticsearch(inputID, validType, maxResults, timeout) {
|
||||
var searchTerm,
|
||||
esQuery;
|
||||
|
||||
// Check to see if the user provided a maximum
|
||||
// number of results to display
|
||||
@ -188,12 +190,17 @@ define(
|
||||
// Process search term
|
||||
searchTerm = processSearchTerm(searchTerm);
|
||||
|
||||
// Create the query to elasticsearch
|
||||
esQuery = ROOT + "/_search/?q=" + searchTerm +
|
||||
"&size=" + maxResults;
|
||||
if (timeout) {
|
||||
esQuery += "&timeout=" + timeout;
|
||||
}
|
||||
|
||||
// Get the data...
|
||||
return $http({
|
||||
method: "GET",
|
||||
url: ROOT + "/_search/?q=" + searchTerm +
|
||||
"&size=" + maxResults +
|
||||
"&timeout=" + DEFAULT_TIMEOUT
|
||||
url: esQuery
|
||||
}).then(function (rawResults) {
|
||||
// ...then process the data
|
||||
return processResults(rawResults, validType);
|
||||
|
@ -43,7 +43,7 @@ define(
|
||||
* @param {WorkerService} workerService the service which allows
|
||||
* more easy creation of web workers.
|
||||
*/
|
||||
function GenericSearchProvider(/*$rootScope, */objectService, /*workerService*/) {
|
||||
function GenericSearchProvider($rootScope, objectService, workerService) {
|
||||
/*
|
||||
var worker = workerService.run('genericSearchWorker'),
|
||||
lastestItems;
|
||||
@ -88,7 +88,7 @@ define(
|
||||
// Recursive helper function for getItems()
|
||||
function itemsHelper(children, i) {
|
||||
var date = new Date;
|
||||
if (date.getTime() >= stopTime) {
|
||||
if (stopTime && date.getTime() >= stopTime) {
|
||||
// This indexing of items has timed out
|
||||
console.log('timed out');
|
||||
console.log('returning', children);
|
||||
@ -110,14 +110,18 @@ define(
|
||||
}
|
||||
|
||||
// Converts the filetree into a list
|
||||
function getItems() {
|
||||
function getItems(timeout) {
|
||||
// Aquire My Items (root folder)
|
||||
return objectService.getObjects(['mine']).then(function (objects) {
|
||||
// Get all of its descendents
|
||||
|
||||
// Set a timeout for itemsHelper
|
||||
var date = new Date;
|
||||
stopTime = date.getTime() + DEFAULT_TIMEOUT;
|
||||
if (timeout) {
|
||||
// Set a timeout for itemsHelper
|
||||
var date = new Date;
|
||||
stopTime = date.getTime() + timeout;
|
||||
}
|
||||
// If there was no timeout provided, leave undefined
|
||||
// itemsHelper should just treat this as having no timeout
|
||||
|
||||
return itemsHelper([objects.mine], 0).then(function (items) {
|
||||
// Turn them into searchResult objects (object, id, and score)
|
||||
@ -217,8 +221,10 @@ define(
|
||||
* final list of results
|
||||
* @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, validType, maxResults) {
|
||||
function queryGeneric(inputID, validType, maxResults, timeout) {
|
||||
var input,
|
||||
terms = [],
|
||||
searchResults = [],
|
||||
@ -231,12 +237,13 @@ define(
|
||||
maxResults = DEFAULT_MAX_RESULTS;
|
||||
}
|
||||
|
||||
|
||||
// Get the user input
|
||||
input = document.getElementById(inputID).value;
|
||||
|
||||
// Get items list
|
||||
//requestItems(); // Test out the worker
|
||||
return getItems().then(function (searchResultItems) {
|
||||
return getItems(timeout).then(function (searchResultItems) {
|
||||
// Keep track of the number of results to display
|
||||
if (searchResultItems.length < maxResults) {
|
||||
resultsLength = searchResultItems.length;
|
||||
|
Loading…
x
Reference in New Issue
Block a user