[#314,be/solr][s]: remove solr backend from core as in separate repo [1].

[1]: https://github.com/Recline/backend.solr
This commit is contained in:
Rufus Pollock 2013-02-10 17:05:30 +00:00
parent ba7e747b97
commit 6f82c4c5cc
5 changed files with 1 additions and 182 deletions

View File

@ -207,32 +207,6 @@ var templates = {
data: data
});
},
'http://openspending.org/api/search': function(record) {
record['time'] = record['time.label_facet']
var template = '<div class="record"> \
<h3> \
<a href="http://openspending.org/{{record.dataset}}/entries/{{record.id}}">{{record.dataset}} {{record.time}}</a> \
&ndash; <img src="http://openspending.org/static/img/icons/cd_16x16.png" /> {{amount_formatted}} \
</h3> \
<ul> \
{{#data}} \
<li>{{key}}: {{value}}</li> \
{{/data}} \
</ul> \
</div> \
';
var data = [];
_.each(_.keys(record), function(key) {
if (key !='_id' && key != 'id') {
data.push({ key: key, value: record[key] });
}
});
return Mustache.render(template, {
record: record,
amount_formatted: formatAmount(record['amount']),
data: data
});
},
'https://docs.google.com/spreadsheet/ccc?key=0Aon3JiuouxLUdExXSTl2Y01xZEszOTBFZjVzcGtzVVE': function(record) {
var template = '<div class="record"> \
<h3> \

View File

@ -86,7 +86,7 @@ ul.facet-items {
<div class="info">
<p>This demo shows how Recline can be used to build a search app. It includes faceting as well as search. You can find the <a href="demo.search.app.js">source javascript here</a> (plus <a href="{{page.root}}/docs/src/demo.search.app.html">prettified version of source for readability</a>) &ndash; please feel free to reuse!</p>
<p>The default setup uses local example data but you can also connect directly to any other <a href="{{page.root}}/docs/backends.html">backend supported by Recline</a>, for example SOLR, ElasticSearch or even a google docs spreadsheet. As an example: here's an <a href="?backend=solr&amp;url=http://openspending.org/api/search">example running against the SOLR-style OpenSpending API</a> and here's an example <a href="?backend=gdocs&amp;url=https://docs.google.com/spreadsheet/ccc?key=0Aon3JiuouxLUdExXSTl2Y01xZEszOTBFZjVzcGtzVVE">running against a GDocs spreadsheet (Oil spills in the Niger Delta)</a>.</p>
<p>The default setup uses local example data but you can also connect directly to any other <a href="{{page.root}}/docs/backends.html">backend supported by Recline</a>, for example SOLR, ElasticSearch or even a google docs spreadsheet. Here's an example <a href="?backend=gdocs&amp;url=https://docs.google.com/spreadsheet/ccc?key=0Aon3JiuouxLUdExXSTl2Y01xZEszOTBFZjVzcGtzVVE">running against a GDocs spreadsheet (Oil spills in the Niger Delta)</a>.</p>
</div>
<hr />

View File

@ -1,68 +0,0 @@
this.recline = this.recline || {};
this.recline.Backend = this.recline.Backend || {};
this.recline.Backend.Solr = this.recline.Backend.Solr || {};
(function($, my) {
my.__type__ = 'solr';
// use either jQuery or Underscore Deferred depending on what is available
var Deferred = _.isUndefined(this.jQuery) ? _.Deferred : jQuery.Deferred;
// ### 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 = new 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 = new 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));

View File

@ -1,85 +0,0 @@
(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);

View File

@ -38,7 +38,6 @@
<script type="text/javascript" src="../src/backend.elasticsearch.js"></script>
<script type="text/javascript" src="../src/backend.csv.js"></script>
<script type="text/javascript" src="../src/backend.ckan.js"></script>
<script type="text/javascript" src="../src/backend.solr.js"></script>
<script type="text/javascript" src="model.test.js"></script>
<script type="text/javascript" src="backend.memory.test.js"></script>
@ -47,7 +46,6 @@
<script type="text/javascript" src="backend.elasticsearch.test.js"></script>
<script type="text/javascript" src="backend.csv.test.js"></script>
<script type="text/javascript" src="backend.ckan.test.js"></script>
<script type="text/javascript" src="backend.solr.test.js"></script>
<!-- views and view tests -->
<script type="text/javascript" src="../src/view.grid.js"></script>