Freebase Suggest
Freebase Suggest is a jQuery plugin that adds Freebase topic autocomplete to search boxes on your site.
Start typing text and the widget suggests relevant matches from the
millions of topics on Freebase.com or any subset of types like People, Locations or Animals.
Topic flyouts help the user select the correct item which is uniquely identified with a Freebase id.
Try it out:
Features:
- Cross browser - based on jQuery, tested on IE7+, FF2+, Safari 3+ and Chrome
- 33KB Minified (+ 19KB for jQuery)
- Cross-domain. No proxy servers required thanks to JSONP.
- Hosted on freebaselibs.com
- Free! (The standard Freebase ToS apply.)
Add to your site
It's easy to add Freebase Suggeest to your web page. Just include this html in your document head:
<link type="text/css" rel="stylesheet" href="http://freebaselibs.com/static/suggest/1.0.1/suggest.min.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="http://freebaselibs.com/static/suggest/1.0.1/suggest.min.js"></script>
<script type="text/javascript">
$(function() {
$("#myinput").suggest({type:'/film/director'});
});
</script>
Assuming this text input in the document body:
<input type="text" id="myinput"/>
Why do I want Freebase Suggest for my data application?
- With autocomplete, your users type less to enter more data
- Data entry is fun and accurate! Reduce the cognitive load on your users thanks to the images and descriptions in the topic flyouts
- Use strong identifiers rather than text keywords. The name "Sting" is ambiguous, but the Freebase IDs /en/sting and /en/sting_1959 are not.
- Avoid duplicate names for the same entity. Puff Daddy, P. Diddy, Sean Combs all refer to /en/sean_combs
Questions?
Questions, bug reports and feedback very welcome on the Freebase Developers Mailing List or the Google Code Issues List.
Examples
Example 1. Basic usage
$("#example1")
.suggest()
.bind("fb-select", function(e, data) {
alert(data.name + ", " + data.id);
});
Try it out here:
Example 2. Suggest new
$("#example2")
.suggest({
"suggest_new": "Click on me if you don't see anything in the list"
})
.bind("fb-select", function(e, data) {
alert(data.name + ", " + data.id);
})
.bind("fb-select-new", function(e, val) {
alert("Suggest new: " + val);
});
Try it out here:
Example 3. Required
$("#example3")
.suggest({
"required": "always"
})
.bind("fb-select", function(e, data) {
alert(data.name + ", " + data.id);
})
.bind("fb-required", function(e) {
alert("This is required");
});
Try it out here:
Example 4. Constraining suggestions by type and type_strict
Constrain suggestions by countries or US States.
$("#example4")
.suggest({
"type": ["/location/country", "/location/us_state"],
"type_strict": "any"
})
.bind("fb-select", function(e, data) {
alert(data.name + ", " + data.id);
});
Try it out here:
Example 5. Constraining suggestions by mql_filter
Suggest films directed by Steven Spielberg
$("#example5")
.suggest({
"type": "/film/film",
"mql_filter": [{"/film/film/directed_by": "Steven Spielberg"}]
})
.bind("fb-select", function(e, data) {
alert(data.name + ", " + data.id);
});
Try it out here:
Example 6. Search box behavior
Add suggest to your search box.
$("#example6")
.suggest({
"type": "/film/film",
"soft": true
})
.bind("fb-select", function(e, data) {
alert(data.name + ", " + data.id);
});
Plugins
The Freebase Suggest core library is extensible to create your own custom suggestions. The core library can be thought as a drop down list that appears below a text input and handles keyboard and mouse interactions with the list like up and down arrow keys and selecting. Here are some plugins that are an extension of the core Freebase Suggest library.