Skip to content

Reuters tutorial: step 8

jpmckinney edited this page Sep 13, 2010 · 22 revisions

Table of Contents

We want to allow the user to explore the Reuters business news by place of origin. In a first stage, we will allow the user to see the facet data. In a second stage, we will allow the user to use the facet data for filtering.

First, update the Solr parameters for faceting in reuters.js:

var params = {
  ...
  'facet.field': [ 'topics', 'organisations', 'exchanges', 'countryCodes' ],
  ...
  'f.countryCodes.facet.limit': -1,
};

The facet.limit parameter for countryCodes is set to a negative value so that Solr returns all facet values for countryCodes.

Create a new widget, CountryCodeWidget.js, inheriting from AbstractFacetWidget:

(function ($) {
AjaxSolr. CountryCodeWidget = AjaxSolr.AbstractFacetWidget.extend({
});
})(jQuery);

Add the JavaScript file:

<script type="text/javascript" src="widgets/CountryCodeWidget.js"></script>

And add an instance of the widget to the Manager in reuters.js:

Manager.addWidget(new AjaxSolr.CountryCodeWidget({
  id: 'countries',
  target: '#countries',
  field: 'countryCodes'
}));

We will need the following utility function to implement the widget, so add it to reuters.js:

$.fn.showIf = function (condition) {
  if (condition) {
    return this.show();
  }
  else {
    return this.hide();
  }
}

Now, we’re ready to implement afterRequest:

Clone this wiki locally