Freebase Search 小部件使用Freebase Search API来建议实体。因此,当您在输入字段中键入“james cameron”时,您将发送以下搜索 API 请求:
https://www.googleapis.com/freebase/v1/search?query=james+cameron&exact=false&prefixed=true
您可以在该 API 调用的响应中看到,它传回了名称、ID、排名以及实体的显着特征:
{
"mid": "/m/03_gd",
"id": "/en/james_cameron",
"name": "James Cameron",
"notable": {
"name": "Film Director",
"id": "/m/02jknp"
},
"lang": "en",
"score": 629.205872
},...
All of this data is accessible from the jQuery callback in the Search widget like this:
$(function() {
$("#myinput").suggest({
key: "YOUR-API-KEY-GOES-HERE",
filter:'(all type:/film/director)'
}).bind("fb-select", function(e, data) {
alert(data.name + ", " + data.id + " (" + data.notable.name + ")");
});
});
In this case, James Cameron (/m/03_gd) is notable for being a film director (/m/02jknp).