def select(self, *args, **kwargs): """ Submits the specified query to Solr's select interface (GET). if there are args it's a request.GET, kwargs are from the manager which looks like this: {'category' : 'news__national' 'type' : None 'author' : None 'year' : '2008' 'sort' : 'score desc'} """ if args and isinstance(args[0], Query): query = args[0] else: query = Query(*args, **kwargs) # Submits the response to solr request_url = self.select_url + "?" + query.url response = self.issue_request(request_url) try: return results.SelectResults(response) except (ValueError, results.SolrException), e: logger.error("Failed to return a valid search result for %s" % request_url) return results.EmptyResults(query.url)
def issue_request(self, url, content=None): """ Submits the specified Unicode content to the specified URL. Returns the raw response content as a string, or None if an error occurs. """ if content: data = content.encode("utf-8", "replace") else: data = None (req, res) = (urllib2.Request(url, data), None) req.add_header("Content-type", "text/xml; charset=utf-8") try: res = urllib2.urlopen(req).read() except StandardError, e: logger.error(e)