Book Image

Apache Solr 3.1 Cookbook

By : Rafał Kuć
Book Image

Apache Solr 3.1 Cookbook

By: Rafał Kuć

Overview of this book

<p>Apache Solr is a fast, scalable, modern, open source, and easy-to-use search engine. It allows you to develop a professional search engine for your ecommerce site, web application, or back office software. Setting up Solr is easy, but configuring it to get the most out of your site is the difficult bit.</p> <p>The Solr 3.1 Cookbook will make your everyday work easier by using real-life examples that show you how to deal with the most common problems that can arise while using the Apache Solr search engine. Why waste your time searching the Internet for solutions when you can have all the answers in one place?</p> <p>This cookbook will show you how to get the most out of your search engine. Each chapter covers a different aspect of working with Solr from analyzing your text data through querying, performance improvement, and developing your own modules. The practical recipes will help you to quickly solve common problems with data analysis, show you how to use faceting to collect data and to speed up the performance of Solr. You will learn about functionalities that most newbies are unaware of, such as sorting results by a function value, highlighting matched words, and computing statistics to make your work with Solr easy and stress free.</p>
Table of Contents (17 chapters)
Apache Solr 3.1 Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using Solr with Ruby


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.

Getting ready

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:

http://rubygems.org/gems/rsolr

How to do it...

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 =&gt...