Skip to content

Tanning Bed is a generic Solr interface for models, because models are too sexy to get the their tans from the sun directly ;-)

Notifications You must be signed in to change notification settings

notch8/tanning_bed

Repository files navigation

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 calling solr_add
Update is solr_update
Delete is solr_delete
TanningBed.solr_search("Big")

Limit to item

result = ModelName.solr_search
@models = ModelName.solr_load(result)

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.

About

Tanning Bed is a generic Solr interface for models, because models are too sexy to get the their tans from the sun directly ;-)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages