Gravatar for james.margey@nymity.com

Question by jmargey, Jan 5, 2015 11:36 AM

Coveo, Requirejs, Backbone and External Templates

Hi,

I have to implement Coveo search into a solution which is implemented using Requirejs, Backbone and External Underscore Templates.

I want to use Coveo components outs of the box so I can utilize as much functionality as possible.

I have a scenario where my backbone view will call the search and then pass the data into a external backbone template using requirejs.

code segment of backbone view below

var myEndpoint = new Coveo.Rest.SearchEndpoint({ restUri: '/Coveo/Search' });

        var that = this;

        var queryToPerform = '(@pwreffacetcountrykey==("Belgium")) (@sysfiletype==("ref_lib","User_Guide", "test.com","Templates","Template_Media"))';



        myEndpoint.search({
            q: queryToPerform
        }).done(function (results) {
            if (results.queryError) {

                alert(results.message);

            } else {

                _.extend(results, previewReportModel);

                console.log("results", results);

                var previewReportModalView = new PreviewReportModalView(previewReportModel);

                that.previewmodal.show(previewReportModalView);
            }
        });

this is the call to pass the results to the template

this.$el.html(this.template(data));

This all works fine, it executes the query and the results are bound to the external template, and I can loop through the results if need be and render them however I want

the external template below

      <div class="modal-body">
    <div class="edit-report">

      <div class="coveo-results-section">
          <div class="coveo-results-column">


            <div class="coveo-results-section">
              <div class="coveo-results-column">
                <div class="CoveoResultList" data-wait-animation="fade">

                        //i can loop through my object here

                </div>
              </div>
            </div>
          </div>
      </div>
    </div>
  </div>
  <div class="modal-footer">
      <div class="CoveoPager"></div>
  </div>

The pager doesnt work and I presume its because I have not called $('#search').coveo('init');

Is there a way for me to pass the results set into an external underscore template using requirejs and still be able to get the pager working and coveo to render the results in there default way?

I also want to point out that I am limited to using underscore through requirejs so I cant use the coveo external templates solution.

Thanks

J.

Gravatar for pastjean@coveo.com

Comment by pastjean, Jan 5, 2015 1:41 PM

pager is indeed not working because init wasn't called

manually doing queries would require you to implement your own pager if you don't use the coveo.init

1 Reply
Gravatar for pastjean@coveo.com

Answer by pastjean, Jan 5, 2015 1:56 PM

Manually doing the query and not using coveo('init') requires you to manually manage your pager

you can do it this way:

{
    q:"yourquery",
    numberOfResults:10,
   firstResult:10 // this is the parameter to set the starting document, index starts a 0
}

to manage the number of pages the results returns you the maximum number of documents through the totalCountparameter. If you use the aq parameter in the query you should look at totalCountFiltered (or always look at it).

{
  ...
  totalCount: #,
  totalCountFiltered: #
  ...
}
Ask a question