mirror of
https://github.com/nasa/openmct.git
synced 2024-12-19 13:17:53 +00:00
[Search] expose constants, add fudge factor
The SearchAggregator exposes it's constants to add stability to tests. It also has a fudge factor which increaases the number of results it requests from providers to better support pagination when using client side filtering.
This commit is contained in:
parent
76151d09a0
commit
ce42429fbd
@ -31,8 +31,6 @@ define([
|
|||||||
) {
|
) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var DEFAULT_MAX_RESULTS = 100;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Aggregates multiple search providers as a singular search provider.
|
* Aggregates multiple search providers as a singular search provider.
|
||||||
* Search providers are expected to implement a `query` method which returns
|
* Search providers are expected to implement a `query` method which returns
|
||||||
@ -53,6 +51,23 @@ define([
|
|||||||
this.providers = providers;
|
this.providers = providers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If max results is not specified in query, use this as default.
|
||||||
|
*/
|
||||||
|
SearchAggregator.prototype.DEFAULT_MAX_RESULTS = 100;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Because filtering isn't implemented inside each provider, the fudge
|
||||||
|
* factor is a multiplier on the number of results returned-- more results
|
||||||
|
* than requested will be fetched, and then will be fetched. This helps
|
||||||
|
* provide more predictable pagination when large numbers of matches exist
|
||||||
|
* but very few matches match filters.
|
||||||
|
*
|
||||||
|
* If a provider level filter implementation is implemented in the future,
|
||||||
|
* remove this.
|
||||||
|
*/
|
||||||
|
SearchAggregator.prototype.FUDGE_FACTOR = 5;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a query to each of the providers. Returns a promise for
|
* Sends a query to each of the providers. Returns a promise for
|
||||||
* a result object that has the format
|
* a result object that has the format
|
||||||
@ -79,13 +94,13 @@ define([
|
|||||||
resultPromises;
|
resultPromises;
|
||||||
|
|
||||||
if (!maxResults) {
|
if (!maxResults) {
|
||||||
maxResults = DEFAULT_MAX_RESULTS;
|
maxResults = this.DEFAULT_MAX_RESULTS;
|
||||||
}
|
}
|
||||||
|
|
||||||
resultPromises = this.providers.map(function (provider) {
|
resultPromises = this.providers.map(function (provider) {
|
||||||
return provider.query(
|
return provider.query(
|
||||||
inputText,
|
inputText,
|
||||||
maxResults
|
maxResults * aggregator.FUDGE_FACTOR
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -49,6 +49,13 @@ define([
|
|||||||
aggregator = new SearchAggregator($q, objectService, providers);
|
aggregator = new SearchAggregator($q, objectService, providers);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("has a fudge factor", function () {
|
||||||
|
expect(aggregator.FUDGE_FACTOR).toBe(5);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("has default max results", function () {
|
||||||
|
expect(aggregator.DEFAULT_MAX_RESULTS).toBe(100);
|
||||||
|
});
|
||||||
|
|
||||||
it("can order model results by score", function () {
|
it("can order model results by score", function () {
|
||||||
var modelResults = {
|
var modelResults = {
|
||||||
@ -170,7 +177,11 @@ define([
|
|||||||
providers.push(provider);
|
providers.push(provider);
|
||||||
|
|
||||||
aggregator.query('find me', 123, 'filter');
|
aggregator.query('find me', 123, 'filter');
|
||||||
expect(provider.query).toHaveBeenCalledWith('find me', 123);
|
expect(provider.query)
|
||||||
|
.toHaveBeenCalledWith(
|
||||||
|
'find me',
|
||||||
|
123 * aggregator.FUDGE_FACTOR
|
||||||
|
);
|
||||||
expect($q.all).toHaveBeenCalledWith(['i prooomise!']);
|
expect($q.all).toHaveBeenCalledWith(['i prooomise!']);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -181,7 +192,10 @@ define([
|
|||||||
);
|
);
|
||||||
providers.push(provider);
|
providers.push(provider);
|
||||||
aggregator.query('find me');
|
aggregator.query('find me');
|
||||||
expect(provider.query).toHaveBeenCalledWith('find me', 100);
|
expect(provider.query).toHaveBeenCalledWith(
|
||||||
|
'find me',
|
||||||
|
aggregator.DEFAULT_MAX_RESULTS * aggregator.FUDGE_FACTOR
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can combine responses from multiple providers', function () {
|
it('can combine responses from multiple providers', function () {
|
||||||
|
Loading…
Reference in New Issue
Block a user