Skip to content

Instantly share code, notes, and snippets.

@larubbio
Created February 6, 2009 04:40
Show Gist options
  • Save larubbio/59231 to your computer and use it in GitHub Desktop.
Save larubbio/59231 to your computer and use it in GitHub Desktop.
A simple ubiquity command for searching evri.com
CmdUtils.makeSearchCommand({
name: "evri",
url: "http://www.evri.com/",
icon: "http://www.evri.com/favicon.ico",
description: "search less. understand more.",
preview: function(pblock, directObject) {
var searchTerm = directObject.text;
// Don't even display any text before fetching search results,
// since the results come back nearly instantaneously. In the
// future, we can display a throbber.
if(searchTerm.length < 1) {
var myString = [
'<style type="text/css">',
' div.header-description h1 {',
' color: #ED1A7A;',
' font-size: 24px;',
' font-weight: bold;',
' font-family: Lucida Grande,Tahoma,Myriad,Arial;',
' }',
' div.header-description p {',
' color: #FFFFFF;',
' font-size: 16px;',
' font-family: Lucida Grande,Tahoma,Myriad,Arial;',
' }',
'</style>',
'<div>',
' <div id="evri-description" class="header-description">',
' <h1>search less. understand more.</h1>',
' <p> Evri opens up a whole new way to explore connections -- between people, places, and things on the web and in the news.</p>',
' </div>',
'</div>'
].join('');
pblock.innerHTML = CmdUtils.renderTemplate( myString,
{});
return;
}
var url = "http://www.evri.com/api/v1/entities/find.json";
var params = { prefix: searchTerm };
CmdUtils.previewGet( pblock, url, params, function(data) {
var numToDisplay = 8;
var results = data.evriThing.entities.entity.splice( 0, numToDisplay );
//for access keys
for (var i = 0; i < results.length; i++) {
var result = results[i];
result.key = i+1;
var facets = result.facets.facet;
if (facets.length == 2) {
result.facets = result.facets.facet[0].name.$ + " and " + result.facets.facet[1].name.$;
} else if ( facets.length == 3) {
result.facets = result.facets.facet[0].name.$ + ", " + result.facets.facet[1].name.$ + ", " + result.facets.facet[2].name.$;
} else if ( facets.length > 3) {
result.facets = result.facets.facet[0].name.$ + ", " + result.facets.facet[1].name.$ + ", " + result.facets.facet[2].name.$ + " ...";
} else {
result.facets = result.facets.facet.name.$;
}
}
var ns = { results: results, searchTerm: searchTerm };
var tmpl = [
'<style type="text/css">',
' div.title {',
' color: #FFFFFF;',
' font-size: 12px;',
' font-family: Lucida Grande,Tahoma,Myriad,Arial;',
' }',
' div.title a {',
' color: #2B6CD5;',
' }',
' div.facets, div.property {',
' color: #888888;',
' font-size: 11px;',
' margin-left: 36px;',
' font-family: Lucida Grande,Tahoma,Myriad,Arial;',
' }',
'</style>',
'<div id="evri-search">',
' {for result in results}',
' <div class="eresult">',
' <div class="title">',
' ${result.key}: <a href="http://www.evri.com${result.@href}.html" accesskey="${result.key}">${result.name.$}</a>',
' </div>',
' <div class="facets">',
' ${result.facets}',
' </div>',
' <div class="property">',
' ${result.properties.property.value.$}',
' </div>',
' </div>',
' {forelse}',
' <b>Your search - ${searchTerm} - did not match any documents. </b>',
' {/for}',
' <small>Tip: You can go to any result in this preview by using its number as an access key. (Linux and Windows: alt-number, Mac: control-number)</small>',
'</div>'
].join('');
pblock.innerHTML = CmdUtils.renderTemplate(tmpl, ns);
}, "json");
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment