-
Notifications
You must be signed in to change notification settings - Fork 207
Reuters tutorial: step 6
jpmckinney edited this page Sep 13, 2010
·
15 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
Thanks to the last step, we’re displaying the value of the q parameter, which we set to “oil” in step 1. Let’s now allow the user to change the value of that parameter.
First, remove the code that set the query to “oil” in reuters.js:
Manager.store.addByValue('q', 'oil');
Create a new widget, TextWidget.js, inheriting from AbstractTextWidget:
(function ($) {
AjaxSolr.TextWidget = AjaxSolr.AbstractTextWidget.extend({
});
})(jQuery);
And add the JavaScript files:
<script type="text/javascript" src="../../lib/core/AbstractTextWidget.js"></script> <script type="text/javascript" src="widgets/TextWidget.js"></script>
AbstractTextWidget provides many convenient functions specific to free-text widgets, but you may alternatively inherit from AbstractWidget if you choose not to use those functions.
Now, add an instance of the widget to the Manager in reuters.js:
Manager.addWidget(new AjaxSolr.TextWidget({
id: 'text',
target: '#search'
}));
Let’s implement the abstract method afterRequest, which should be familiar now: