slush-marklogic-node icon indicating copy to clipboard operation
slush-marklogic-node copied to clipboard

Show more with remainder estimate

Open grtjn opened this issue 9 years ago • 0 comments

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?

grtjn avatar Jan 22 '16 20:01 grtjn