mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 01:02:58 +00:00
Consider matchScore when sorting the preset list
This commit is contained in:
@@ -56,9 +56,14 @@ export function presetCollection(collection) {
|
||||
var leading_name = _.filter(searchable, function(a) {
|
||||
return leading(a.name().toLowerCase());
|
||||
}).sort(function(a, b) {
|
||||
var i = a.name().toLowerCase().indexOf(value) - b.name().toLowerCase().indexOf(value);
|
||||
if (i === 0) return a.name().length - b.name().length;
|
||||
else return i;
|
||||
var i;
|
||||
i = b.originalScore - a.originalScore;
|
||||
if (i !== 0) return i;
|
||||
|
||||
i = a.name().toLowerCase().indexOf(value) - b.name().toLowerCase().indexOf(value);
|
||||
if (i !== 0) return i;
|
||||
|
||||
return a.name().length - b.name().length;
|
||||
});
|
||||
|
||||
// matches value to preset.terms values
|
||||
|
||||
@@ -21,16 +21,18 @@ export function presetPreset(id, preset, fields) {
|
||||
};
|
||||
|
||||
|
||||
var matchScore = preset.matchScore || 1;
|
||||
preset.originalScore = preset.matchScore || 1;
|
||||
|
||||
|
||||
preset.matchScore = function(entity) {
|
||||
var tags = preset.tags,
|
||||
score = 0;
|
||||
|
||||
for (var t in tags) {
|
||||
if (entity.tags[t] === tags[t]) {
|
||||
score += matchScore;
|
||||
score += preset.originalScore;
|
||||
} else if (tags[t] === '*' && t in entity.tags) {
|
||||
score += matchScore / 2;
|
||||
score += preset.originalScore / 2;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user