function matchSubstrs(methodName) { var tokens = []; var len = methodName.length; for (var size = 1; size <= len; size++){ for (var i = 0; i+size<= len; i++){ tokens.push(methodName.substr(i, size)); } } return tokens; } $(function initSearchBar() { var methodNames = new Bloodhound({ datumTokenizer: matchSubstrs, queryTokenizer: Bloodhound.tokenizers.whitespace, prefetch: { url: './methodNames.json', cache: false } }); var sourceFiles = new Bloodhound({ datumTokenizer: matchSubstrs, queryTokenizer: Bloodhound.tokenizers.whitespace, prefetch: { url: './sourceFiles.json', cache: false } }); var githubIssues = new Bloodhound({ datumTokenizer: Bloodhound.tokenizers.whitespace, queryTokenizer: Bloodhound.tokenizers.whitespace, remote: { url: 'https://api.github.com/search/issues?q=%QUERY+repo:caolan/async', cache: true, wildcard: '%QUERY', transform: function(response) { return $.map(response.items, function(issue) { // if (issue.state !== 'open') { // return null; // } return { url: issue.html_url, name: issue.number + ': ' + issue.title, number: issue.number }; }).sort(function(a, b) { return b.number - a.number; }); } } }); $('.typeahead').typeahead({ hint: true, highlight: true, minLength: 1 }, { name: 'Methods', source: methodNames, templates: { header: '