I have this fiddle which auto completes airport names.
The issue- Sorting
I found this question which addresses the issue, but I cant implement in my scenario. Not a pro!
Quick Preview from the question -
var source = ['Adam', 'Benjamin', 'Matt', 'Michael', 'Sam', 'Tim'];
$("input").autocomplete({
source: function (request, response) {
var term = $.ui.autocomplete.escapeRegex(request.term)
, startsWithMatcher = new RegExp("^" + term, "i")
, startsWith = $.grep(source, function(value) {
return startsWithMatcher.test(value.label || value.value || value);
})
, containsMatcher = new RegExp(term, "i")
, contains = $.grep(source, function (value) {
return $.inArray(value, startsWith) < 0 &&
containsMatcher.test(value.label || value.value || value);
});
response(startsWith.concat(contains));
}
});
I simply tried adjusting the source, but that was not working.
Also, the actual airport list contains above 35000 names, so is this search method efficient? And where and how does binary search fill in.