Skip to content
This repository has been archived by the owner on Oct 5, 2020. It is now read-only.

Splitting facets and results back-end calls #544

Open
grtjn opened this issue Dec 5, 2017 · 1 comment
Open

Splitting facets and results back-end calls #544

grtjn opened this issue Dec 5, 2017 · 1 comment

Comments

@grtjn
Copy link
Contributor

grtjn commented Dec 5, 2017

Sometimes facets are big, and thus slow. To not have them slow down showing of results, you can make mlSearch do separate calls for them. It requires adding something like this above ctrl.init() in search.controller.js:

    // override internal search to split results and facets call..
    ctrl._search = function() {
      this.searchPending = true;

      // results only
      var promise = this.mlSearch.search({
        'return-results': true,
        'return-facets': false
      })
      .then(this.updateSearchResults.bind(this));

      // facets only
      this.mlSearch.search({
        'return-results': false,
        'return-facets': true
      })
      .then(this.updateSearchResults.bind(this));

      this.updateURLParams();
      return promise;
    };

    // override the updateSearchResults to handle split of results and facets..
    ctrl.updateSearchResults = function updateSearchResults(data) {
      var oldFacets = ctrl.response.facets;
      var oldResults = ctrl.response.results;

      superCtrl.updateSearchResults.apply(ctrl, arguments);

      if (!ctrl.response.facets) {
        ctrl.response.facets = oldFacets;
      } else {
        ctrl.response.results = oldResults;
      }

      return ctrl;
    };
@sashamitrovich
Copy link

Good job. As you found out later, need to add this to ctrl.updateSearchResults, too:


      // forcing caching of results for an "ad-hoc" query
      ctrl.mlSearch.results=ctrl.response;

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants