Created
March 1, 2012 12:50
-
-
Save timhodson/1949665 to your computer and use it in GitHub Desktop.
Kasabi: Solr Search API examples
This file contains hidden or 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
| ######################################## | |
| ## Quick curl examples | |
| ######################################## | |
| # Search for Queen Victoria in the Government Art Collection - JSON results | |
| curl -v -X GET "http://api.kasabi.com/dataset/government-art-collection/apis/search/solr?apikey=$KASABI_API_KEY&q=Queen+Victoria&wt=json" | |
| # Search for Queen Victoria in the Government Art Collection - XML results | |
| curl -v -X GET "http://api.kasabi.com/dataset/government-art-collection/apis/search/solr?apikey=$KASABI_API_KEY&q=Queen+Victoria&wt=xml" | xmllint --format - | |
| # Search for Queen Victoria in rdfs:label fields. | |
| # Note: Encoding of property URI | |
| # Note: Inclusion of encoded escape character ( \ => %5C ) before the colon in http:// | |
| # Note: The inclusion of Quotes to search for Phrase "Queen Victoria" | |
| curl -v -X GET "http://api.kasabi.com/dataset/government-art-collection/apis/search/solr?apikey=$KASABI_API_KEY&q=http%5C%3A%2F%2Fwww.w3.org%2F2000%2F01%2Frdf-schema%23label:\"Queen+Victoria\"&wt=xml" | xmllint --format - | |
| ######################################## | |
| ## a Javascript and jQuery example | |
| ######################################## | |
| $('document').ready(function () { | |
| searchString2 = escape("http\\://www.w3.org/2000/01/rdf-schema#label:\"Queen+Victoria\""); | |
| url2 = "" + apibase + "/dataset/government-art-collection/apis/search/solr?wt=json&q=" + searchString2 + apikey; | |
| return $.ajax({ | |
| url: url2, | |
| success: function(data) { | |
| var doc, _i, _len, _ref, _results; | |
| $('.foo').append("<h2>Solr Search API results...</h2>"); | |
| if (data['response'] != null) { | |
| $('.foo').append("<p>There were " + data['response']['numFound'] + " results.<br>Request:<code> GET " + url2 + "</code></p>"); | |
| _ref = data['response']['docs']; | |
| _results = []; | |
| for (_i = 0, _len = _ref.length; _i < _len; _i++) { | |
| doc = _ref[_i]; | |
| if (doc['subject_uri'] != null) { | |
| _results.push($('.foo').append("<p><a href=\"" + doc['subject_uri'] + "\">" + doc['http://www.w3.org/2000/01/rdf-schema#label'][0] + "</a></p>")); | |
| } else { | |
| _results.push(void 0); | |
| } | |
| } | |
| return _results; | |
| } | |
| } | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment