Exclude presets with searchable: false from search (fixes #932)

This commit is contained in:
John Firebaugh
2013-03-17 20:59:11 -07:00
parent 13cd85a362
commit 7912b33b4c
2 changed files with 18 additions and 5 deletions
+8 -4
View File
@@ -41,10 +41,14 @@ iD.presets.Collection = function(collection) {
value = value.toLowerCase();
var leading_name = _.filter(collection, function(a) {
var searchable = _.filter(collection, function(a) {
return a.searchable !== false;
});
var leading_name = _.filter(searchable, function(a) {
return leading(a.name().toLowerCase());
}),
leading_terms = _.filter(collection, function(a) {
leading_terms = _.filter(searchable, function(a) {
return _.any(a.terms || [], leading);
});
@@ -53,7 +57,7 @@ iD.presets.Collection = function(collection) {
return index === 0 || a[index - 1] === ' ';
}
var levenstein_name = collection.map(function(a) {
var levenstein_name = searchable.map(function(a) {
return {
preset: a,
dist: iD.util.editDistance(value, a.name().toLowerCase())
@@ -65,7 +69,7 @@ iD.presets.Collection = function(collection) {
}).map(function(a) {
return a.preset;
}),
leventstein_terms = _.filter(collection, function(a) {
leventstein_terms = _.filter(searchable, function(a) {
return _.any(a.terms || [], function(b) {
return iD.util.editDistance(value, b) + Math.min(value.length - b.length, 0) < 3;
});
+10 -1
View File
@@ -54,6 +54,15 @@ describe("iD.presets.Collection", function() {
it("always includes other", function() {
expect(c.search("blade of grass").collection.indexOf(p.other) >= 0).to.eql(true);
});
});
it("excludes presets with searchable: false", function() {
var excluded = iD.presets.Preset('excluded', {
tags: {},
geometry: [],
searchable: false
}),
collection = iD.presets.Collection([excluded, p.other]);
expect(collection.search("excluded").collection).not.to.include(excluded);
});
});
});