About
This is the gem to install for the supported version of acts_as_solr on websolr.
Installation
cd your_rails_app
sudo gem install websolr-acts_as_solr
config.gem "websolr-acts_as_solr" # into config.environment.rb
echo websolr-acts_as_solr >> .gems # if using Heroku
acts_as_solr install # Installs config/solr.yml
echo "require 'aas_tasks'" >> Rakefile # Installs local development tasks
Usage
Starting a local development server
To start up a Solr instance for development, issue the following:
rake solr:start
Using in production
You need to make sure that the WEBSOLR_URL environment variable is set correctly.
If you’re using Heroku, this should happen automatically. You can verify by running heroku config.
If you’re running in your own environment, set the environment variable as you normally would on a *nix system.
If you have to set the variable in Ruby, you should be able to put the following in an Rails initializer:
if RAILS_ENV == "production"
ENV["WEBSOLR_URL"] = "http://index.websolr.com/solr/[your-api-key]"
load "websolr-acts_as_solr.rb"
end
Requirements
-
Java Runtime Environment(JRE) 1.5 aka 5.0 [www.java.com/en/download/index.jsp](http://www.java.com/en/download/index.jsp)
-
If you have libxml-ruby installed, make sure it’s at least version 0.7
Basic Usage
# Just include the line below to any of your ActiveRecord models:
acts_as_solr
# Or if you want, you can specify only the fields that should be indexed:
acts_as_solr :fields => [:name, :author]
# Then to find instances of your model, just do:
Model.find_by_solr(query) #query is a string representing your query
# Please see ActsAsSolr::ActsMethods in the RDoc for a complete info
acts_as_solr in your tests
To test code that uses acts_as_solr you must start a Solr server for the test environment. You can do that with
rake solr:start RAILS_ENV=test
However, if you would like to mock out Solr calls so that a Solr server is not needed (and your tests will run much faster), just add this to your ‘test_helper.rb` or similar:
class ActsAsSolr::Post
def self.execute(request)
true
end
end
(via)