added regex support for query
Added a the regex support for queries - this will also match substrings! (change from previous behavior). Also fixed the test vor Custom popups, since this was b0rken.
This commit is contained in:
@@ -142,9 +142,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];
|
||||
@@ -155,7 +158,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;
|
||||
});
|
||||
|
||||
@@ -177,7 +177,7 @@ test('Popup - Custom', function () {
|
||||
assertPresent(popup);
|
||||
|
||||
var text = popup.html();
|
||||
ok((text.indexOf('<h3>3</h3>y: 6') != -1))
|
||||
ok((text.indexOf('<h3>1</h3>y: 2') != -1))
|
||||
|
||||
view.remove();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user