[backend/elasticsearch][s]: ES backend supports full text queries and sorting.

This commit is contained in:
Rufus Pollock 2012-02-28 21:08:18 +00:00
parent ae587506f3
commit 64056da3aa
2 changed files with 46 additions and 1 deletions

View File

@ -47,9 +47,33 @@ this.recline.Backend = this.recline.Backend || {};
alert('This backend currently only supports read operations');
}
},
_normalizeQuery: function(queryObj) {
if (queryObj.toJSON) {
var out = queryObj.toJSON();
} else {
var out = _.extend({}, queryObj);
}
if (out.q != undefined && out.q.trim() === '') {
delete out.q;
}
if (!out.q) {
out.query = {
match_all: {}
}
} else {
out.query = {
query_string: {
query: out.q
}
}
delete out.q;
}
return out;
},
query: function(model, queryObj) {
var queryNormalized = this._normalizeQuery(queryObj);
var data = {source: JSON.stringify(queryNormalized)};
var base = this._getESUrl(model);
var data = _.extend({}, queryObj);
var jqxhr = $.ajax({
url: base + '/_search',
data: data,

View File

@ -1,6 +1,27 @@
(function ($) {
module("Backend ElasticSearch");
test("ElasticSearch queryNormalize", function() {
var backend = new recline.Backend.ElasticSearch();
var in_ = new recline.Model.Query();
in_.set({q: ''});
var out = backend._normalizeQuery(in_);
equal(out.q, undefined);
deepEqual(out.query.match_all, {});
var backend = new recline.Backend.ElasticSearch();
var in_ = new recline.Model.Query().toJSON();
in_.q = '';
var out = backend._normalizeQuery(in_);
equal(out.q, undefined);
deepEqual(out.query.match_all, {});
var in_ = new recline.Model.Query().toJSON();
in_.q = 'abc';
var out = backend._normalizeQuery(in_);
equal(out.query.query_string.query, 'abc');
});
var mapping_data = {
"note": {
"properties": {