-
Notifications
You must be signed in to change notification settings - Fork 210
Comparison to SolrJS
The development of Ajax Solr was originally inspired by SolrJS, a JavaScript client library that was initially developed as a 2008 Google Summer of Code project by Matthias Epheser. Despite it’s many merits (and inclusion in the Solr 1.3), the code wasn’t production ready, and the project has averaged one commit per month in 2009. Below we outline the ways in which we were able to improve on the original.
SolrJS executes a separate request for each of its widgets. This is inefficient, as you may have many widgets for faceting on date, language, location, price, category, etc. and at least one widget for displaying results. AJAX Solr performs a single AJAX request. It can do this, because Solr can return the result set and the data for all facets in a single query.
AJAX Solr supports the back button and bookmarking (using the fragment identifier). You can add a filter or change your query, and click the back button to undo your changes. If you want to save your filtered result set, you just need to bookmark the page. SolrJS doesn’t do either.
As of writing, SolrJS is still not fully IE 6, IE 7, and IE 8-compatible. AJAX Solr is.
SolrJS requires that your Solr instance be publicly accessible. AJAX Solr was built under the assumption that you may want to proxy requests to your Solr instance, e.g. to limit what information the user has access to. AJAX Solr gives you the option.
SolrJS doesn’t provide support for Solr’s highlighting or sorting parameters. AJAX Solr does.
SolrJS’s functions for selecting/unselecting filters require that you pass in the full list of selected filters. AJAX Solr’s functions just require that you pass in the list of filters that you want to add or remove from the list of selected filters. In other words, with AJAX Solr, you don’t need to know the state of the current list of selected filters; you just add/remove what you want.
AJAX Solr’s manager adds useful functions, such as: `deselectWidget`, to deselect all of a given widget’s filters; `selectOnlyItems`, to deselect all except the given filters; `selectOnlyWidget`, to deselect all except the given widget’s filters. Thanks to these and other improvements, your widgets will never need access to the manager’s or other widgets’ private fields.
SolrJS defines a few hooks for modifying a widget’s behaviour. AJAX Solr adds: `afterChangeSelection`, which allows a widget to run some code if one of its filters was set/unset; `startAnimation`/`endAnimation`, which allow you to customize what happens while the AJAX request is being performed, e.g. replace the result set with a loading spinner; `displayQuery`, which allows you to display the current query, filters, sort, etc. to the user.
In the widgets we’ve written for AJAX Solr, we separate the HTML from the JavaScript by putting all the HTML into “theme” functions using the AjaxSolr.theme API call (inspired by Drupal).
We worked hard to ensure that AJAX Solr is DRY-er, more loosely coupled, and easier to read than SolrJS. Consider this example:
Widget inheritance in SolrJS:
jQuery.solrjs.AbstractClientSideWidget = jQuery.solrjs.createClass ("AbstractWidget", {
/* key/value pairs */
});
Widget inheritance in AJAX Solr:
AjaxSolr.AbstractFacetWidget = AjaxSolr.AbstractWidget.extend({
/* key/value pairs */
});