Skip to content

Reuters tutorial: step 6

jpmckinney edited this page Sep 13, 2010 · 15 revisions

Table of Contents

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:


              
Clone this wiki locally