谷歌自定义搜索API自动完成? [英] Google Custom Search API Autocomplete?
问题描述
我们正在使用谷歌的自定义搜索API(有偿服务器端API)来驱动我们的搜索结果。
We're using the google custom search API (paid-for server-side API) to power our search results.
我想自动完成功能添加到搜索 - 然而,没有人知道是否有这种支持(?或者通过服务器端API,或者通过某种客户端的JSONP)
I'd like to add an autocomplete feature to the search - however, does anyone know if there is support for this (either via the server-side API, or via some sort of client-side JSONP?)
我已经使用了谷歌定制搜索自动完成试过,不过这似乎想要的结果,我不想画的搜索框和显示谷歌广告。
I have tried using the autocomplete for the Google Customised search, but this appears to want to draw the search box and display google ads with the results, which I don't want.
推荐答案
得到这个工作是这样的 - 希望这可以帮助别人:)
Got this working something like this - hope this helps someone else :)
$(function () {
$('input.search')
.focus(function () { this.select(); })
.mouseup(function (e) { e.preventDefault(); })
.autocomplete({
position: {
my: "left top",
at: "left bottom",
offset: "0, 5",
collision: "none"
},
source: function (request, response) {
$.ajax({
url: "http://clients1.google.com/complete/search?q=" + request.term + "&hl=en&client=partner&source=gcsc&partnerid={GOOGLESEARCHID}&ds=cse&nocache=" + Math.random().toString(),
dataType: "jsonp",
success: function (data) {
response($.map(data[1], function (item) {
return {
label: item[0],
value: item[0]
};
}));
}
});
},
autoFill: true,
minChars: 0,
select: function (event, ui) {
$(this).closest('input').val(ui.item.value);
$(this).closest('form').trigger('submit');
}
});
});
这篇关于谷歌自定义搜索API自动完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!