Created
January 14, 2010 21:59
-
-
Save gcarothers/277550 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" | |
"http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg-flat.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" | |
xmlns:svg="http://www.w3.org/2000/svg" | |
xml:lang="en"> | |
<head> | |
<title>Quick and Dirty Product Search</title> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" type="text/javascript"></script> | |
</head> | |
<body> | |
<ol id="results"> | |
</ol> | |
<script> | |
var search_by_title = function (search_term, callback) { | |
var sparql = "\ | |
PREFIX fn: <http://www.w3.org/2005/xpath-functions#> \ | |
PREFIX trons: <http://purl.oreilly.com/ns/trons/> \ | |
PREFIX status: <http://purl.oreilly.com/statuses/> \ | |
PREFIX dc: <http://purl.org/dc/terms/> \ | |
PREFIX foaf: <http://xmlns.com/foaf/0.1/> \ | |
PREFIX mods: <http://www.loc.gov/mods/> \ | |
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \ | |
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \ | |
PREFIX product-types: <http://purl.oreilly.com/product-types/> \ | |
PREFIX om: <http://purl.oreilly.com/ns/meta/> \ | |
SELECT DISTINCT ?title ?edition ?isbn ?publisher_name \ | |
WHERE { \ | |
?ip dc:type product-types:IP ; \ | |
dc:title ?title ; \ | |
dc:publisher ?publisher ; \ | |
mods:edition ?edition ; \ | |
dc:hasFormat ?product ; \ | |
\ | |
a om:Product ; \ | |
. \ | |
?product dc:type product-types:BOOK ;\ | |
dc:identifier ?isbn ; \ | |
trons:validAccordingTo status:publicly-visible ;\ | |
.\ | |
{?product trons:validAccordingTo status:active } \ | |
UNION \ | |
{ ?product trons:validAccordingTo status:out-of-print } \ | |
FILTER (REGEX(str(?isbn),'^urn:isbn:'))\ | |
?publisher foaf:name ?publisher_name . \ | |
FILTER (langMatches(lang(?publisher_name), 'en')). \ | |
FILTER(REGEX(str(?title), '" + search_term + "', 'i')) .\ | |
}"; | |
var query = {"query" : sparql, | |
"output" : "json" | |
}; | |
var url = "http://goban.oreilly.com:2020/sparql?" + $.param(query) + "&callback=?"; | |
$.getJSON(url, callback); | |
}; | |
$( function() { | |
search_by_title("geek",function (data) { | |
$.each(data.results.bindings, function () { | |
$("#results").append("<li>" + this.title.value + ", " + this.edition.value + "e " + this.isbn.value.substr(9) + " " + this.publisher_name.value + "</li>"); | |
}); | |
}); | |
} | |
); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment