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