From d5e36944d76e5786715fd45e5cc07323bbf960cf Mon Sep 17 00:00:00 2001 From: Michael Bauer Date: Thu, 13 Sep 2012 16:37:08 +0200 Subject: [PATCH] query now supports regexes actually compile stuff :/ --- dist/recline.dataset.js | 7 +++++-- dist/recline.js | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/dist/recline.dataset.js b/dist/recline.dataset.js index 99fd7876..83cb1a2b 100644 --- a/dist/recline.dataset.js +++ b/dist/recline.dataset.js @@ -727,9 +727,12 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {}; this._applyFreeTextQuery = function(results, queryObj) { if (queryObj.q) { var terms = queryObj.q.split(' '); + var patterns=_.map(terms, function(term) { + return new RegExp(term.toLowerCase());; + }); results = _.filter(results, function(rawdoc) { var matches = true; - _.each(terms, function(term) { + _.each(patterns, function(pattern) { var foundmatch = false; _.each(self.fields, function(field) { var value = rawdoc[field.id]; @@ -740,7 +743,7 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {}; value = ''; } // 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) // if (foundmatch) return true; }); diff --git a/dist/recline.js b/dist/recline.js index e1b5f239..2a1c5071 100644 --- a/dist/recline.js +++ b/dist/recline.js @@ -1032,9 +1032,12 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {}; this._applyFreeTextQuery = function(results, queryObj) { if (queryObj.q) { var terms = queryObj.q.split(' '); + var patterns=_.map(terms, function(term) { + return new RegExp(term.toLowerCase());; + }); results = _.filter(results, function(rawdoc) { var matches = true; - _.each(terms, function(term) { + _.each(patterns, function(pattern) { var foundmatch = false; _.each(self.fields, function(field) { var value = rawdoc[field.id]; @@ -1045,7 +1048,7 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {}; value = ''; } // 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) // if (foundmatch) return true; });