Created
October 28, 2011 20:57
-
-
Save lbjay/1323534 to your computer and use it in GitHub Desktop.
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
| import urllib2 | |
| from invenio import intbitset | |
| import simplejson | |
| import mimetools | |
| def get_facets(bitset, solr_url): | |
| facet_query_url = "%s/invenio_facets" % solr_url | |
| # now use the bitset to fetch the facet data | |
| r = urllib2.Request(facet_query_url) | |
| data = bitset.fastdump() | |
| boundary = mimetools.choose_boundary() | |
| # fool solr into thinking we're uploading a file so it will read our data as a stream | |
| data_size = len(data) | |
| contents = '--%s\r\n' % boundary | |
| contents += 'Content-Disposition: form-data; name="bitset"; filename="bitset"\r\n' | |
| contents += 'Content-Type: application/octet-stream\r\n' | |
| contents += '\r\n' + data + '\r\n' | |
| contents += '--%s--\r\n\r\n' % boundary | |
| r.add_data(contents) | |
| contenttype = 'multipart/form-data; boundary=%s' % boundary | |
| r.add_unredirected_header('Content-Type', contenttype) | |
| # post the request and get back the facets as json | |
| u = urllib2.urlopen(r) | |
| return simplejson.load(u) | |
| def get_bitset(query, solr_url): | |
| invenio_query_url = "%s/select?qt=invenio_query&q=%s" % (solr_url, urllib2.quote(query)) | |
| # print invenio_query_url | |
| # query to get a bitset | |
| bitset = intbitset.intbitset() | |
| u = urllib2.urlopen(invenio_query_url) | |
| data = u.read() | |
| bitset.fastload(data) | |
| # print "query result: " + str(bitset) | |
| # print "results length: %d" % len(bitset.tolist()) | |
| return bitset |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment