Reuters tutorial: step 1

raydot edited this page Oct 22, 2014 · 29 revisions

Table of Contents

In this first iteration, we make sure we can talk to the Solr instance. AJAX Solr is JavaScript framework-agnostic; it only requires an AJAX implementation to send requests to Solr. In this example, we use jQuery.

In AJAX Solr, the Manager sends these requests, and passes the responses to each widget for handling. (The Manager behaves as the controller in a MVC framework. All public calls should be performed on the manager.)

In the head tag, we add the JavaScript files for AJAX Solr and the Manager:

<script src="../../lib/core/Core.js"></script>
<script src="../../lib/core/AbstractManager.js"></script>
<script src="../../lib/managers/Manager.jquery.js"></script>

In the reuters.js file, once the DOM is ready, we’ll initialize a instance of the Manager. (We wrap the code in (function ($) { ... })(jQuery); to permit local usage of the $ variable while preventing conflicts over it):

var Manager;
(function ($) {
  $(function () {
    Manager = new AjaxSolr.Manager({
      solrUrl: 'http://evolvingweb.ca/solr/reuters/'
    });
    Manager.init();
  });
})(jQuery);

The manager takes as a parameter either solrUrl – if talking to Solr directly – or proxyUrl – if talking to Solr through a proxy. (Usually, you want to talk to the instance through a proxy, for security. We will go over writing proxies for AJAX Solr in another tutorial. Here, we communicate with the instance directly.)

AJAX Solr stores Solr parameters in a ParameterStore. In your web application, some parameters won’t change, e.g. facet and facet.field. These will usually be set at the same time as the Manager is initialized. Other parameters will change, e.g. q and fq. These will usually be modified by one or more widgets.

We add the JavaScript files for the ParameterStore:

<script src="../../lib/core/Parameter.js"></script>
<script src="../../lib/core/ParameterStore.js"></script>

(To use another ParameterStore, see the AbstractManager#setStore method and the ParameterStore class.)

Let’s use the ParameterStore addByValue API method right now to build a basic query:

Manager.store.addByValue('q', '*:*');

The Solr instance storing the Reuters data uses SearchHandler as its default request handler, in which the q parameter is mandatory. If we do not wish to set a query, we must set the q parameter to *:*, which means “match all documents.”

To finish this iteration, check if we can talk to Solr using the AbstractManager doRequest API method:

Manager.doRequest();

If you’re running Safari or Firefox with Firebug, you can open the JavaScript console and type Manager.response to view the Solr response.

[What we have so far]

Now, let's see some results.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.