mirror of
https://github.com/nasa/openmct.git
synced 2025-06-22 00:57:11 +00:00
[Search] Aggregator aggregates
The search aggregator now combines the search results from each search provider and returns that. Objects may appear in the list more than once.
This commit is contained in:
@ -38,60 +38,41 @@ define(
|
|||||||
* aggregated
|
* aggregated
|
||||||
*/
|
*/
|
||||||
function SearchAggregator($q, providers) {
|
function SearchAggregator($q, providers) {
|
||||||
return {
|
|
||||||
query: providers[0].query
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
function getPromisedResults(resultsPromises, promiseIndex, finalResults) {
|
||||||
// Pick a domain object model to use, favoring the one
|
if (promiseIndex >= resultsPromises.length) {
|
||||||
// with the most recent timestamp
|
return finalResults;
|
||||||
function pick(a, b) {
|
} else {
|
||||||
var aModified = (a || {}).modified || Number.NEGATIVE_INFINITY,
|
return resultsPromises[promiseIndex].then(function (results) {
|
||||||
bModified = (b || {}).modified || Number.NEGATIVE_INFINITY;
|
finalResults = finalResults.concat(results);
|
||||||
return (aModified > bModified) ? a : (b || a);
|
return getPromisedResults(resultsPromises, promiseIndex + 1, finalResults);
|
||||||
}
|
|
||||||
|
|
||||||
// Merge results from multiple providers into one
|
|
||||||
// large result object.
|
|
||||||
function mergeModels(provided, ids) {
|
|
||||||
var result = {};
|
|
||||||
ids.forEach(function (id) {
|
|
||||||
provided.forEach(function (models) {
|
|
||||||
if (models[id]) {
|
|
||||||
result[id] = pick(result[id], models[id]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
/**
|
|
||||||
* Get models with the specified identifiers.
|
|
||||||
*
|
|
||||||
* This will invoke the `getModels()` method of all providers
|
|
||||||
* given at constructor-time, and aggregate the result into
|
|
||||||
* one object.
|
|
||||||
*
|
|
||||||
* Note that the returned object may contain a subset or a
|
|
||||||
* superset of the models requested.
|
|
||||||
*
|
|
||||||
* @param {string[]} ids an array of domain object identifiers
|
|
||||||
* @returns {Promise.<object>} a promise for an object
|
|
||||||
* containing key-value pairs,
|
|
||||||
* where keys are object identifiers and values
|
|
||||||
* are object models.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
getModels: function (ids) {
|
|
||||||
return $q.all(providers.map(function (provider) {
|
|
||||||
return provider.getModels(ids);
|
|
||||||
})).then(function (provided) {
|
|
||||||
return mergeModels(provided, ids);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calls the searches of each of the providers, then
|
||||||
|
// merges the results lists so that there are not redundant
|
||||||
|
// results
|
||||||
|
function mergeResults(inputID) {
|
||||||
|
var resultsPromises = [],
|
||||||
|
mergedResults = [];
|
||||||
|
|
||||||
|
for (var i = 0; i < providers.length; i += 1) {
|
||||||
|
resultsPromises.push(providers[i].query(inputID));
|
||||||
|
}
|
||||||
|
|
||||||
|
mergedResults = getPromisedResults(resultsPromises, 0, []);
|
||||||
|
|
||||||
|
//return mergedResults;
|
||||||
|
return mergedResults.then(function (c) {
|
||||||
|
//console.log('returning ', c);
|
||||||
|
return c;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
query: mergeResults
|
||||||
};
|
};
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return SearchAggregator;
|
return SearchAggregator;
|
||||||
|
@ -28,7 +28,9 @@ define(
|
|||||||
[],
|
[],
|
||||||
function () {
|
function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
var DEFAULT_MAX_RESULTS = 100;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A model service which reads domain object models from an external
|
* A model service which reads domain object models from an external
|
||||||
* persistence service.
|
* persistence service.
|
||||||
|
Reference in New Issue
Block a user