As you already know, Solr has an API exposed as an HTTP interface. With the use of several provided response writers, we can use virtually any language to connect to Solr, send a query, and fetch the results. In the following recipe, I'll show you how to prepare Solr to use it with Ruby and how to use the Ruby language to fetch data from Solr.
Before you start with this recipe, please ensure that you have rsolr gem installed. Information on how to do that can be found at the following address:
Let's start with the schema.xml
file. We will only need two fields, so the field definition part of the file should look like this:
<field name="id" type="string" indexed="true" stored="true" required="true" /> <field name="name" type="text" indexed="true" stored="true" />
Now let's index some data. To do that, I used the following code fragment:
require 'rubygems' require 'rsolr' solr = RSolr.connect :url =>...