[Search] Moving responsibility

Moving the responsibility of polling for updates
from the search controller to the search aggregator.

In progress. Previously this prototype was what
could be called semi-stable, but now it is no longer.
This commit is contained in:
shale 2015-07-23 16:58:21 -07:00
parent 341218e8f6
commit 300280e03e
3 changed files with 23 additions and 3 deletions

View File

@ -39,7 +39,7 @@
<!-- Results list -->
<div class="results">
<mct-representation key="'search-item'"
ng-repeat="result in results"
ng-repeat="result in searchService.latestResults"
mct-object="result.object"
ng-model="ngModel">
</mct-representation>

View File

@ -42,7 +42,8 @@ define(
*/
function SearchAggregator(providers) {
var latestMergedResults = [],
lastMergeTimestamps = [];
lastMergeTimestamps = [],
returnObject;
// Remove duplicate objects that have the same ID
function filterRepeats(results) {
@ -122,6 +123,7 @@ define(
// After all that is done, now replace latestMergedResults with this
latestMergedResults = newerResults;
lastMergeTimestamps = providerTimestamps;
returnObject.latestResults = latestMergedResults;
}
// For documentation, see sendQuery below.
@ -141,7 +143,7 @@ define(
updateResults();
}
return {
returnObject = {
/**
* Sends a query to each of the providers, then updates the global
* latestMergedResults accordingly.
@ -177,6 +179,14 @@ define(
return latestMergedResults.slice(start, stop);
},
/**
* The latest search results that have been calculated. The
* format of the returned objects are searchResult objects,
* which have the members id, object, and score. This array
* is updated constantly.
*/
latestResults: latestMergedResults,
/**
* Get the timestamps for each of the provider's last controbutions
* to the latestMergedResults.
@ -193,6 +203,7 @@ define(
return latestMergedResults.length;
}
};
return returnObject;
}
return SearchAggregator;

View File

@ -35,6 +35,15 @@ define(function () {
var numResults = INITIAL_LOAD_NUMBER,
loading = false;
//$scope.results = searchService.latestResults;
// This allows us to directly access the search aggregator's members.
// Most important is latestResults, which is continuously updated. This
// means that this controller does not have to poll for results any more.
$scope.searchService = searchService;
// TODO: Modify search aggregator to have a search result array which
// is of a size that can be chosen and modified by this controller.
function update(timestamp) {
// We are loading results
loading = true;