query now supports regexes

actually compile stuff :/
This commit is contained in:
Michael Bauer
2012-09-13 16:37:08 +02:00
parent 73c414be30
commit d5e36944d7
2 changed files with 10 additions and 4 deletions

View File

@@ -727,9 +727,12 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {};
this._applyFreeTextQuery = function(results, queryObj) { this._applyFreeTextQuery = function(results, queryObj) {
if (queryObj.q) { if (queryObj.q) {
var terms = queryObj.q.split(' '); var terms = queryObj.q.split(' ');
var patterns=_.map(terms, function(term) {
return new RegExp(term.toLowerCase());;
});
results = _.filter(results, function(rawdoc) { results = _.filter(results, function(rawdoc) {
var matches = true; var matches = true;
_.each(terms, function(term) { _.each(patterns, function(pattern) {
var foundmatch = false; var foundmatch = false;
_.each(self.fields, function(field) { _.each(self.fields, function(field) {
var value = rawdoc[field.id]; var value = rawdoc[field.id];
@@ -740,7 +743,7 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {};
value = ''; value = '';
} }
// TODO regexes? // TODO regexes?
foundmatch = foundmatch || (value.toLowerCase() === term.toLowerCase()); foundmatch = foundmatch || (pattern.test(value.toLowerCase()));
// TODO: early out (once we are true should break to spare unnecessary testing) // TODO: early out (once we are true should break to spare unnecessary testing)
// if (foundmatch) return true; // if (foundmatch) return true;
}); });

7
dist/recline.js vendored
View File

@@ -1032,9 +1032,12 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {};
this._applyFreeTextQuery = function(results, queryObj) { this._applyFreeTextQuery = function(results, queryObj) {
if (queryObj.q) { if (queryObj.q) {
var terms = queryObj.q.split(' '); var terms = queryObj.q.split(' ');
var patterns=_.map(terms, function(term) {
return new RegExp(term.toLowerCase());;
});
results = _.filter(results, function(rawdoc) { results = _.filter(results, function(rawdoc) {
var matches = true; var matches = true;
_.each(terms, function(term) { _.each(patterns, function(pattern) {
var foundmatch = false; var foundmatch = false;
_.each(self.fields, function(field) { _.each(self.fields, function(field) {
var value = rawdoc[field.id]; var value = rawdoc[field.id];
@@ -1045,7 +1048,7 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {};
value = ''; value = '';
} }
// TODO regexes? // TODO regexes?
foundmatch = foundmatch || (value.toLowerCase() === term.toLowerCase()); foundmatch = foundmatch || (pattern.test(value.toLowerCase()));
// TODO: early out (once we are true should break to spare unnecessary testing) // TODO: early out (once we are true should break to spare unnecessary testing)
// if (foundmatch) return true; // if (foundmatch) return true;
}); });