i was using Freebase Search Widget for my project, using it i can select the word from the suggestion list in my input box, but how to get the category as well in another text box ?
Example: http://suggest-examples.freebaseapps.com/
If i type: James Cameron, it will be selected in the text box, but i also want the category to be selected in another text box ?
Code:
$(function() {
$("#myinput").suggest({
key: "YOUR-API-KEY-GOES-HERE",
filter:'(all type:/film/director)'
});
});
The Freebase Search widget uses the Freebase Search API to suggest entities. So When you type "james cameron" into the input field, you're sending the following Search API request:
https://www.googleapis.com/freebase/v1/search?query=james+cameron&exact=false&prefixed=true
You can see in the responses from that API call that it passes back the name, ID, a ranking and what the entity is notable for:
{
"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 ).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.