I just builded my own youtube search based on Youtube API V3.
I would like to add auto complete function to search input, the problem is, the wordlist.
If I add a big word list, that means a bigger load time, and the autocomplete is useless, because you need to write out the full word, for get your correct word, if I add a small wordlist, the load time is good, but the problem is same, the autocomplete is useless, because dosen't complete any useful.
So I looked this problem in a different way.
What about if I somehow I get the youtube autocomplete wordlist, based on relevance, and the wordlist only then loaded, when you typing.
Is that possible?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
With so many research I found a solution for this:
$("#q").autocomplete({
source: function(request, response){
/* Need a api key for this, so we add it: */
var apiKey = 'MYAPIKEY';
/* command */
var query = request.term;
/* youtube ajax request */
$.ajax({
url: "http://suggestqueries.google.com/complete/search?hl=en&ds=yt&client=youtube&hjson=t&cp=1&q="+query+"&key="+apiKey+"&format=5&alt=json&callback=?",
dataType: 'jsonp',
success: function(data, textStatus, request) {
response( $.map( data[1], function(item) {
return {
label: item[0],
value: item[0]
}
}));
}
});
},
/* seçilene işlem yapmak için burayı kullanabilirsin */
select: function( event, ui ) {
}
});
I hope it help also someone else who looking for a something like this.