public
Description: Tanning Bed is a generic Solr interface for models, because models are too sexy to get the their tans from the sun directly ;-)
Homepage:
Clone URL: git://github.com/notch8/tanning_bed.git
notch8 (author)
Fri Oct 02 19:23:23 -0700 2009
commit  b20253cd348e61b4debf01b06f440142b8432b3d
tree    19e17cb7bb2b4cebcb97eeb5d0ecbdd43cbbfd03
parent  4701443a40fdbc46fe419cf9bf3c2fc0f35f6435
name age message
file .gitignore Mon Jan 19 11:55:17 -0800 2009 Really, I want this directory k, thanks [notch8]
file History.txt Tue Dec 30 21:51:27 -0800 2008 Fixed up the rake tasks a little and bumped the... [notch8]
file Manifest.txt Mon Jan 19 11:58:17 -0800 2009 Really, I want this directory k, thanks [notch8]
file README.rdoc Wed Apr 29 16:00:23 -0700 2009 updated to Ruby 1.9 compatibility [notch8]
file Rakefile Tue Dec 30 21:51:27 -0800 2008 Fixed up the rake tasks a little and bumped the... [notch8]
directory lib/ Wed Apr 29 16:00:23 -0700 2009 updated to Ruby 1.9 compatibility [notch8]
directory spec/ Fri Oct 02 19:23:23 -0700 2009 tanning bed array faceting example [notch8]
file tanning_bed.gemspec Wed Apr 29 16:00:23 -0700 2009 updated to Ruby 1.9 compatibility [notch8]
directory tasks/ Wed Apr 29 16:00:23 -0700 2009 updated to Ruby 1.9 compatibility [notch8]
directory vendor/ Mon Jan 19 11:28:55 -0800 2009 added log dir back in with a keep file [notch8]
README.rdoc

tanning_bed

    by Rob Kaufman (notch8.com)
    with permission and support from the Assay Depot (assaydepot.com)

DESCRIPTION:

Tanning Bed is Solr for models. Tanning Bed provides a Ruby interface for the Solr (lucene.apache.org/solr/) search engine to use in you’re models not matter whether they are Datamapper, Active Record, Couchrest or just general Ruby classes.

FEATURES/PROBLEMS:

  • Incredibly simple in design, no fancy hooks
  • Very Ruby

SYNOPSIS:

Setup

  Using TanningBed for a given class involves including the TanningBed model and then implementing a few (easy) methods.

  Objects must implement:

  * id - unique identifier for the record
  * Class.get - this method receives and object's id and loads it
  * solr_keys - an array of method names, the method results will be added to the index

Examples

CouchRest
  id is already implemented and so is get.  CouchRest has a method called keys which we'll use

    class MyDocument < CouchRest::Model
      include TanningBed

      key_accessor :name
      key_accessor :address

      def solr_keys
        keys
      end
ActiveRecord
  id is implemented in ActiveRecord already

   class MyModel < ActiveRecord::Base
     include TanningBed

     def get(value)
       find(value)
     end

     def solr_keys
       attribute_names
     end
   end

Adding, Updating or Deleting

  Adding a record is accomplished by

Changing Solr connection

  To change the url for Solr or to change whether autocommit is on or not add the following to you're instantiation (for example config/enviroments/production.rb)

   TanningBed.solr_connection(YOUR_SOLR_URL, :off)

Handling connection issues

  Only you can decide the best way to handle Solr exceptions in your application.  TanningBed provides a simple hook to allow you to do just that.  By default connection exceptions (Errno::ECONNREFUSED) in TanningBed methods simply output to STDERR.  This isn't really sufficient unless you're watching STDERR on you're application for problems.  A common thing to want to do is simply be notified of the error while failing silently.  To do that you might setup something like this:

   TanningBed.on_solr_exception = Proc.new {|e| deliver_solr_down_email(e) }

REQUIREMENTS:

  • Solr (bundled)
  • Solr-Ruby library (bundled)

INSTALL:

LICENSE:

(The MIT License)

Copyright © 2008 Assay Depot Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.