query now supports regexes
actually compile stuff :/
This commit is contained in:
parent
73c414be30
commit
d5e36944d7
7
dist/recline.dataset.js
vendored
7
dist/recline.dataset.js
vendored
@ -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;
|
||||
});
|
||||
|
||||
7
dist/recline.js
vendored
7
dist/recline.js
vendored
@ -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;
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user