Created
November 22, 2011 20:36
-
-
Save makuk66/1386855 to your computer and use it in GitHub Desktop.
a simple Rsolr 1.0.3 example for basic auth
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
#!/usr/bin/env ruby | |
# | |
# A simple Rsolr 1.0.3 example for basic auth | |
# | |
# rvm gemset create rsolr-example | |
# rvm use rsolr-example | |
# gem install rsolr | |
require 'rsolr' | |
# patch basic auth support into RSolr, until it is supported upstream | |
require 'rsolr/connection' | |
class RSolr::Connection | |
protected | |
def setup_raw_request_with_basic_auth request_context | |
raw_request = setup_raw_request_without_basic_auth(request_context) | |
raw_request.basic_auth(request_context[:uri].user, request_context[:uri].password) | |
raw_request | |
end | |
alias_method :setup_raw_request_without_basic_auth, :setup_raw_request | |
alias_method :setup_raw_request, :setup_raw_request_with_basic_auth | |
end | |
rsolr = RSolr.connect :url => 'http://USERNAME:PASSWORD@HOSTNAME/ROUTEID/solr/collection1' | |
rsolr.add(:id => 1, :name => "some title", :body => "some body") | |
rsolr.commit | |
result = rsolr.select :params => { :q => "some" } | |
p result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the gist. For anyone coming here through search engines, RSolr now has basic auth built-in. Just specify username and password in the url as shown here.