RSolr

RSolr is a Ruby client for Solr. It is designed to be a simple, low-level wrapper that provides direct access to the Solr API. As such, its use encourages familiarity with the Solr API, which in turn offers simple, direct access to Solr.

This document provides a basic overview of common RSolr usage. You can find RSolr’s comprehensive official documentation at its source repository on Github.

Installation

RSolr is distributed as a Ruby Gem. To install it using the command-line RubyGems tool, simply run:

gem install rsolr

To use RSolr with Bundler in your Rails, Sinatra or other Ruby application, you can include the following in your Gemfile:

gem 'rsolr'

Basic Usage

When using RSolr, you need to specify the URL of the Solr index which you are connecting to. This can be done by passing a :url option to the RSolr.connect method, which returns a RSolr::Client object for you to use in indexing and searching your data.

Easy on the Commits

Searching your documents

The RSolr client provides a select method which sends requests to the Solr /select handler. It accepts a hash of parameters, which it serializes into the query string of its request.

Here is a simple example, using the q param to perform a keyword query:

search = rsolr.select :params => { :q => "keywords" }

Note that in this example, the query is performed according to the query parser settings defined in solrconfig.xml and potentially your default query field specified in schema.xml. Here is a more explicit search using the DisMax query parser to search our example name and body fields.