diff --git a/dist/recline.dataset.js b/dist/recline.dataset.js index cce33d6e..05ae6add 100644 --- a/dist/recline.dataset.js +++ b/dist/recline.dataset.js @@ -713,20 +713,23 @@ 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]; - if (value !== null) { + if ((value !== null) && (value !== undefined)) { value = value.toString(); } else { // value can be null (apparently in some cases) 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 432d97bb..269c1b57 100644 --- a/dist/recline.js +++ b/dist/recline.js @@ -1032,20 +1032,23 @@ 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]; - if (value !== null) { + if ((value !== null) && (value !== undefined)) { value = value.toString(); } else { // value can be null (apparently in some cases) 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; }); @@ -2682,9 +2685,6 @@ my.Map = Backbone.View.extend({ try { self.features.addData(feature); - if (feature.properties && feature.properties.popupContent) { - self.features.bindPopup(feature.properties.popupContent); - } } catch (except) { wrongSoFar += 1; var msg = 'Wrong geometry value'; @@ -2832,7 +2832,11 @@ my.Map = Backbone.View.extend({ var bg = new L.TileLayer(mapUrl, {maxZoom: 18, attribution: osmAttribution ,subdomains: '1234'}); this.map.addLayer(bg); - this.features = new L.GeoJSON(); + this.features = new L.GeoJSON(null, + {onEachFeature: function(feature,layer) { + layer.bindPopup(feature.properties.popupContent); + } + }); this.map.addLayer(this.features); this.map.setView([0, 0], 2); diff --git a/src/backend.memory.js b/src/backend.memory.js index fd7f6119..ece95bd2 100644 --- a/src/backend.memory.js +++ b/src/backend.memory.js @@ -142,20 +142,23 @@ 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]; - if (value !== null) { + if ((value !== null) && (value !== undefined)) { value = value.toString(); } else { // value can be null (apparently in some cases) 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/src/view.map.js b/src/view.map.js index cd69bf34..c74b2cf0 100644 --- a/src/view.map.js +++ b/src/view.map.js @@ -217,9 +217,6 @@ my.Map = Backbone.View.extend({ try { self.features.addData(feature); - if (feature.properties && feature.properties.popupContent) { - self.features.bindPopup(feature.properties.popupContent); - } } catch (except) { wrongSoFar += 1; var msg = 'Wrong geometry value'; @@ -367,7 +364,11 @@ my.Map = Backbone.View.extend({ var bg = new L.TileLayer(mapUrl, {maxZoom: 18, attribution: osmAttribution ,subdomains: '1234'}); this.map.addLayer(bg); - this.features = new L.GeoJSON(); + this.features = new L.GeoJSON(null, + {onEachFeature: function(feature,layer) { + layer.bindPopup(feature.properties.popupContent); + } + }); this.map.addLayer(this.features); this.map.setView([0, 0], 2); diff --git a/test/backend.memory.test.js b/test/backend.memory.test.js index 23bea1d9..3c858206 100644 --- a/test/backend.memory.test.js +++ b/test/backend.memory.test.js @@ -74,7 +74,7 @@ test('query string', function () { }); data.query({q: 'UK 6'}).then(function(out) { - equal(out.total, 1); + equal(out.total, 2); // the new regex support will find 2 hits deepEqual(out.hits[0].id, 1); }); }); @@ -234,7 +234,7 @@ test('query string', function () { }); dataset.query({q: 'UK 6'}).then(function() { - equal(dataset.records.length, 1); + equal(dataset.records.length, 2); deepEqual(dataset.records.models[0].id, 1); }); }); diff --git a/test/view.map.test.js b/test/view.map.test.js index 1efd3d83..698c22e6 100644 --- a/test/view.map.test.js +++ b/test/view.map.test.js @@ -177,7 +177,7 @@ test('Popup - Custom', function () { assertPresent(popup); var text = popup.html(); - ok((text.indexOf('

3

y: 6') != -1)) + ok((text.indexOf('

1

y: 2') != -1)) view.remove(); });