-
Notifications
You must be signed in to change notification settings - Fork 207
Comparison to SolrJS
SolrJS is a JavaScript client library that was initially developed as a 2008 Google Summer of Code project. However, it is nearly inactive, averaging one commit per month for the past year. This could be acceptable if the library were mature and bug-free, but it isn’t yet.
SolrJS executes an AJAX 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 retrieve the result set and the data for each facet in a single query. AJAX Solr takes advantage of this feature; SolrJS doesn’t.
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 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). Examples will be provided on the wiki shortly.
After working with SolrJS for a month, I can assure you AJAX Solr is DRY-er, more loosely coupled, and easier to read than SolrJS. SolrJS’s coupling between the manager and its widgets, for example, is very tight. If you require detailed justification, contact [email protected]. AJAX Solr’s API is also more of a pleasure to work with. Consider this example:
Inheritance in SolrJS:
jQuery.solrjs.AbstractClientSideWidget = jQuery.solrjs.createClass ("AbstractWidget", {
/* key/value pairs */
});
Inheritance in AJAX Solr:
AjaxSolr.AbstractFacetWidget = AjaxSolr.AbstractWidget.extend({
/* key/value pairs */
});