mirror of
https://github.com/nasa/openmct.git
synced 2025-06-21 00:23:01 +00:00
[Search] Generic tracks total hits
The generic search worker keeps track of the total number of search hits before truncating to match the max results.
This commit is contained in:
@ -108,7 +108,7 @@ define(
|
|||||||
pendingQueries[event.data.timestamp].resolve(
|
pendingQueries[event.data.timestamp].resolve(
|
||||||
{
|
{
|
||||||
hits: searchResults,
|
hits: searchResults,
|
||||||
total: searchResults.length // TODO: Make worker return this
|
total: event.data.total
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -132,14 +132,13 @@
|
|||||||
var results = {},
|
var results = {},
|
||||||
input = data.input.toLocaleLowerCase(),
|
input = data.input.toLocaleLowerCase(),
|
||||||
terms = convertToTerms(input),
|
terms = convertToTerms(input),
|
||||||
timesToLoop = Math.min(indexedItems.length, data.maxNumber),
|
total,
|
||||||
i,
|
i,
|
||||||
score,
|
score;
|
||||||
message;
|
|
||||||
|
|
||||||
// If the user input is empty, we want to have no search results.
|
// If the user input is empty, we want to have no search results.
|
||||||
if (input !== '') {
|
if (input !== '') {
|
||||||
for (i = 0; i < timesToLoop; i += 1) {
|
for (i = 0; i < indexedItems.length; i += 1) {
|
||||||
score = scoreItem(indexedItems[i], input, terms);
|
score = scoreItem(indexedItems[i], input, terms);
|
||||||
if (score > 0) {
|
if (score > 0) {
|
||||||
results[indexedItems[i].id] = score;
|
results[indexedItems[i].id] = score;
|
||||||
@ -147,12 +146,19 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
message = {
|
// Store the total hits number
|
||||||
|
total = results.length;
|
||||||
|
// Truncate results if there are more than maxResults
|
||||||
|
if (results.length > data.maxNumber) {
|
||||||
|
results = results.slice(0, data.maxNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
request: 'search',
|
request: 'search',
|
||||||
results: results,
|
results: results,
|
||||||
|
total: total,
|
||||||
timestamp: data.timestamp
|
timestamp: data.timestamp
|
||||||
};
|
};
|
||||||
return message;
|
|
||||||
|
|
||||||
// TODO: After a search is completed, do we need to
|
// TODO: After a search is completed, do we need to
|
||||||
// clear out indexedItems?
|
// clear out indexedItems?
|
||||||
|
Reference in New Issue
Block a user