If you want to make the number of characters more important, you can sort by the length of the string.
orderBy: 'string.length'
Here is an example of plunker. Which doesn't make much sense, but proves that it works.
.
,
app.filter('sortByLength', function() {
return function(items) {
items.sort(function (a, b) {
return (a.length > b.length ? 1 : -1);
});
return items;
};
});
, .
.
app.filter('sortByMatch', function() {
return function(items, searchString) {
var re = new RegExp("[" + searchString + "]", "g");
items.sort(function (a, b) {
if (!searchString) {
return input;
}
var matchingCharsA = a.length - (a.match(re) || []).length;
var matchingCharsB = b.length - (b.match(re) || []).length;
return (matchingCharsA > matchingCharsB ? 1 : -1);
});
return items;
};
});
.
ng-repeat="item in.... | sortByMatch: searchString
, .