-
Notifications
You must be signed in to change notification settings - Fork 209
Reuters tutorial: step 8
jpmckinney edited this page Sep 13, 2010
·
22 revisions
- Reuters tutorial
- Step 1: Talk to Solr
- Step 2: Add a results widget
- Step 3: Add a pager widget
- Step 4: Add a tagcloud widget
- Step 5: Display the current filters
- Step 6: Add a free-text widget
- Step 7: Add an autocomplete widget
- Step 8: Add a map widget
- Step 9: Add a calendar widget
- Step 10: Support the back button
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: