score wildcard matches as half a match

so that building=* doesn't get prioritized over more
specific one tag presets, like amenity=hospital
This commit is contained in:
Ansis Brammanis
2013-03-08 11:36:57 -05:00
parent 45c6c04399
commit f72e294156
2 changed files with 11 additions and 5 deletions
+10 -4
View File
@@ -13,12 +13,18 @@ iD.presets.Preset = function(preset, forms) {
};
preset.matchTags = function(entity) {
var tags = preset.match.tags;
var tags = preset.match.tags,
score = 0;
for (var t in tags) {
if (entity.tags[t] !== tags[t] &&
!(tags[t] === '*' && t in entity.tags)) return -1;
if (entity.tags[t] === tags[t]) {
score ++;
} else if (tags[t] === '*' && t in entity.tags) {
score += 0.5;
} else {
return -1;
}
}
return Object.keys(preset.match.tags).length;
return score;
};
preset.removeTags = function(tags, geometry) {
+1 -1
View File
@@ -103,7 +103,7 @@ describe('iD.presets.Preset', function() {
});
it("counts * as a match for any value", function() {
expect(p.building.matchTags(w4)).to.equal(1);
expect(p.building.matchTags(w4)).to.equal(0.5);
expect(p.building.matchTags(w5)).to.equal(-1);
});