I am trying to create a search against an API. It works great but it only looks at an exact match.
In other words If I dont put “The” in front of Empire it would never find… “The Empire Strike Back”, any idea what I am missing? Below is my jquery code:
$(document).ready(function() {
$(".game-select").select2({
ajax: {
url: “https://opdb.org/api/search/typeahead”,
dataType: ‘json’,
data: function(params) {
return {
q: params.term,
type: ‘public’
};
},
processResults: function(data, params) {
var resData = [];
data.forEach(function(value) {
if (value.name.toLowerCase().indexOf(params.term.toLowerCase()) == 0)
resData.push(value)
})
return {
results: $.map(resData, function(item) {
return {
text: item.text,
id: item.id
}
})
};
},
cache: true
},
minimumInputLength: 3
})
});