[#61,backend/elasticsearch][m]: create, update and delete support in elasticsearch backend -- fixes #61.

This commit is contained in:
Rufus Pollock
2012-04-22 22:17:47 +01:00
parent d19337eda4
commit 1bf64c5f94
2 changed files with 91 additions and 4 deletions

View File

@@ -21,7 +21,7 @@ this.recline.Backend = this.recline.Backend || {};
// <pre>http://localhost:9200/twitter/tweet</pre>
my.ElasticSearch = my.Base.extend({
__type__: 'elasticsearch',
readonly: true,
readonly: false,
_getESUrl: function(dataset) {
var out = dataset.get('elasticsearch_url');
if (out) return out;
@@ -55,9 +55,36 @@ this.recline.Backend = this.recline.Backend || {};
dfd.reject(arguments);
});
return dfd.promise();
} else if (model.__type__ == 'Document') {
var base = this._getESUrl(model.dataset) + '/' + model.id;
return $.ajax({
url: base,
dataType: 'json'
});
}
} else if (method === 'update') {
if (model.__type__ == 'Document') {
var data = JSON.stringify(model.toJSON());
var base = this._getESUrl(model.dataset);
if (model.id) {
base += '/' + model.id;
}
return $.ajax({
url: base,
type: 'POST',
data: data,
dataType: 'json'
});
}
} else if (method === 'delete') {
if (model.__type__ == 'Document') {
var base = this._getESUrl(model.dataset) + '/' + model.id;
return $.ajax({
url: base,
type: 'DELETE',
dataType: 'json'
});
}
} else {
alert('This backend currently only supports read operations');
}
},
_normalizeQuery: function(queryObj) {