slush-marklogic-node
slush-marklogic-node copied to clipboard
Show more with remainder estimate
If you substract sum of facet counts from search total, you get a remainder estimate. You can use that in UI to show “12345 more …” instead of “see more …“..
Unfortunately, only works if element/prop doesn’t occur multiple times in one doc/frag. I am now checking sum < total, but that is not failsafe. Then again, when doing that calc inside search.controller.js, you can exclude facets if necessary.
Changes:
ctrl.updateSearchResults = function updateSearchResults(data) {
var total = data.total;
angular.forEach(data.facets, function(facet, key) {
var sum = 0;
angular.forEach(facet.facetValues, function(facetValue, index) {
sum += facetValue.count;
});
if (sum < total) {
facet.remainder = total - sum;
} else {
delete facet.remainder;
}
});
superCtrl.updateSearchResults.apply(ctrl, arguments);
return ctrl;
};
ctrl.showMoreFacets = function showMoreFacets(facet, facetName) {
var total = ctrl.response.total;
return superCtrl.showMoreFacets.apply(ctrl, arguments).then(function(facet) {
var sum = 0;
angular.forEach(facet.facetValues, function(facetValue, index) {
sum += facetValue.count;
});
if (sum < total) {
facet.remainder = total - sum;
} else {
delete facet.remainder;
}
return facet;
});
};
And then you only need to override ml-facets.html, and replace see more ... with {{facet.remainder || 'see'}} more ....
Good enough to include in vanilla slush?