Consider matchScore when sorting the preset list

This commit is contained in:
Bryan Housel
2017-03-12 19:01:15 -04:00
parent 73f32fe5f3
commit 5e7919e78c
2 changed files with 13 additions and 6 deletions

View File

@@ -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

View File

@@ -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;
}