diff --git a/src/backend.solr.js b/src/backend.solr.js
new file mode 100644
index 00000000..fae6d353
--- /dev/null
+++ b/src/backend.solr.js
@@ -0,0 +1,65 @@
+this.recline = this.recline || {};
+this.recline.Backend = this.recline.Backend || {};
+this.recline.Backend.Solr = this.recline.Backend.Solr || {};
+
+(function($, my) {
+ my.__type__ = 'solr';
+
+ // ### fetch
+ //
+ // dataset must have a solr or url attribute pointing to solr endpoint
+ my.fetch = function(dataset) {
+ var jqxhr = $.ajax({
+ url: dataset.solr || dataset.url,
+ data: {
+ rows: 1,
+ wt: 'json'
+ },
+ dataType: 'jsonp',
+ jsonp: 'json.wrf'
+ });
+ var dfd = $.Deferred();
+ jqxhr.done(function(results) {
+ // if we get 0 results we cannot get fields
+ var fields = []
+ if (results.response.numFound > 0) {
+ fields = _.map(_.keys(results.response.docs[0]), function(fieldName) {
+ return { id: fieldName };
+ });
+ }
+ var out = {
+ fields: fields,
+ useMemoryStore: false
+ };
+ dfd.resolve(out);
+ });
+ return dfd.promise();
+ }
+
+ // TODO - much work on proper query support is needed!!
+ my.query = function(queryObj, dataset) {
+ var q = queryObj.q || '*:*';
+ var data = {
+ q: q,
+ rows: queryObj.size,
+ start: queryObj.from,
+ wt: 'json'
+ };
+ var jqxhr = $.ajax({
+ url: dataset.solr || dataset.url,
+ data: data,
+ dataType: 'jsonp',
+ jsonp: 'json.wrf'
+ });
+ var dfd = $.Deferred();
+ jqxhr.done(function(results) {
+ var out = {
+ total: results.response.numFound,
+ hits: results.response.docs
+ };
+ dfd.resolve(out);
+ });
+ return dfd.promise();
+ };
+
+}(jQuery, this.recline.Backend.Solr));
diff --git a/test/backend.solr.test.js b/test/backend.solr.test.js
new file mode 100644
index 00000000..2b7ec65a
--- /dev/null
+++ b/test/backend.solr.test.js
@@ -0,0 +1,85 @@
+(function ($) {
+module("Backend SOLR");
+
+test("fetch", function() {
+ var dataset = new recline.Model.Dataset({
+ url: 'http://openspending.org/api/search',
+ backend: 'solr'
+ });
+ // stop();
+
+ var stub = sinon.stub($, 'ajax', function(options) {
+ return {
+ done: function(callback) {
+ callback(sample_data);
+ return this;
+ },
+ fail: function() {
+ }
+ };
+ });
+
+ dataset.fetch().done(function(dataset) {
+ var exp = [
+ "_id",
+ "amount",
+ "category.label_facet",
+ "dataset",
+ "from.label_facet",
+ "id",
+ "subcategory.label_facet",
+ "time.label_facet",
+ "to.label_facet"
+ ];
+ deepEqual(
+ exp,
+ _.pluck(dataset.fields.toJSON(), 'id')
+ );
+ // check we've mapped types correctly
+ equal(dataset.fields.get('amount').get('type'), 'string');
+
+ // fetch does a query so we can check for records
+ equal(dataset.recordCount, 10342132);
+ equal(dataset.records.length, 2);
+ equal(dataset.records.at(0).get('id'), '3e3e25d7737634127b76d5ee4a7df280987013c7');
+ // start();
+ });
+ $.ajax.restore();
+});
+
+var sample_data = {
+ "response": {
+ "docs": [
+ {
+ "_id": "south-african-national-gov-budget-2012-13::3e3e25d7737634127b76d5ee4a7df280987013c7",
+ "amount": 30905738200000.0,
+ "category.label_facet": "General public services",
+ "dataset": "south-african-national-gov-budget-2012-13",
+ "from.label_facet": "National Treasury",
+ "id": "3e3e25d7737634127b76d5ee4a7df280987013c7",
+ "subcategory.label_facet": "Transfers of a general character between different levels of government",
+ "time.label_facet": "01. April 2012",
+ "to.label_facet": "Provincial Equitable Share"
+ },
+ {
+ "_id": "south-african-national-gov-budget-2012-13::738849e28e6b3c45e5b0001e142b51479b3a3e41",
+ "amount": 8938807300000.0,
+ "category.label_facet": "General public services",
+ "dataset": "south-african-national-gov-budget-2012-13",
+ "from.label_facet": "National Treasury",
+ "id": "738849e28e6b3c45e5b0001e142b51479b3a3e41",
+ "subcategory.label_facet": "Public debt transactions",
+ "time.label_facet": "01. April 2012",
+ "to.label_facet": "State Debt Costs"
+ }
+ ],
+ "numFound": 10342132,
+ "start": 0
+ },
+ "responseHeader": {
+ "QTime": 578,
+ "status": 0
+ }
+};
+
+})(this.jQuery);
diff --git a/test/index.html b/test/index.html
index 8830b603..e1168150 100644
--- a/test/index.html
+++ b/test/index.html
@@ -37,6 +37,7 @@
+
@@ -45,6 +46,7 @@
+