GitXplorerGitXplorer
d

acts_as_solr_reloaded

public
102 stars
30 forks
8 issues

Commits

List of commits on branch master.
Unverified
20900d1339daa1f805c74c0d2203afb37edde3db

Merge pull request #42 from orthographic-pedant/spell_check/beginning

ddcrec1 committed 9 years ago
Unverified
d04c31d270c60cf5a6d5f14af5259a940cfacf4c

Fix typographical error(s)

oorthographic-pedant committed 9 years ago
Unverified
a992d3d7a9c8017aa0a4b71f8222ae1782c4d278

Merge pull request #36 from fbuenemann/fix/rexml-bad-entity-encoding

ddcrec1 committed 12 years ago
Unverified
fffed2f0cde97b8d1e8da75176ea31f5b1509c8b

Merge pull request #37 from fbuenemann/fix/gemspec

ddcrec1 committed 12 years ago
Unverified
ced38119d2a0a7ddeece028aab175fcf74f854e9

Merge pull request #35 from fbuenemann/fix/socket-timeout

ddcrec1 committed 12 years ago
Unverified
6af170fb2b08e35ed349dd47de62cd164a7dddc5

Remove missing files from gemspec

ffelixbuenemann committed 12 years ago

README

The README file for this repository.

Build status

Description

This plugin adds full text search capabilities and many other nifty features from Apache's Solr to any Rails model. It was based on the first draft by Erik Hatcher.

This plugin is intended for use in old versions of Rails. For newer versions, I strongly advice using Sunspot! Nevertheless, this plugin is used for Noosfero project in production. Any problem please open an issue.

It should support Rails 2.1 (and greater 2.x) and is developed latest Solr versions, so don't expect it to run on older Solr.

Installation

Install as a plugin

script/plugin install git://github.com/brauliobo/acts_as_solr_reloaded.git

Download Solr

rake solr:download

Requirements

  • Java Runtime Environment(JRE) 6.0 (or newer) from Oracle or OpenJDK

Configuration

See config/solr.yml file.

For solr configuration the important files are solrconfig.xml and schema.xml.

Basic Usage

Just include the line below to any of your ActiveRecord models:

acts_as_solr

Or if you want, you can specify only the fields that should be indexed:

acts_as_solr :fields => [:name, :author]

Then to find instances of your model, just do:

Model.search(query) #query is a string representing your query

Please see ActsAsSolr::ActsMethods for a complete info

Pagination

ActsAsSolr implements in SearchResults class an interface compatible with will_paginate and maybe others.

In your tests

To test code that uses acts_as_solr you must start a Solr server for the test environment. You can add to the beginning of your test/test_helper.rb the code:

ENV["RAILS_ENV"] = "test"
abort unless system 'rake solr:start' 
at_exit { system 'rake solr:stop' }

However, if you would like to mock out Solr calls so that a Solr server is not needed (and your tests will run much faster), just add this to your test_helper.rb or similar:

class ActsAsSolr::Post
  def self.execute(request)
    true
  end
end

Or to be more realistic and preserve performance, enable Solr when needed, by calling TestSolr.enable and disable solr otherwise by calling TestSolr.disable on Test::Unit::TestCase's setup:

 class ActsAsSolr::Post
   class << self
     alias_method :execute_orig, :execute
   end
 end
 module ActsAsSolr::ParserMethods
   alias_method :parse_results_orig, :parse_results
 end
 
 class TestSolr
 
   def self.enable
     ActsAsSolr::Post.class_eval do
       def self.execute(*args)
         execute_orig *args
       end
     end
     ActsAsSolr::ParserMethods.module_eval do
       def parse_results(*args)
         parse_results_orig *args
       end
     end
 
     # clear index
     ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => '*:*'))
 
     @solr_disabled = false
   end
 
   def self.disable
     return if @solr_disabled
 
     ActsAsSolr::Post.class_eval do
       def self.execute(*args)
         true
       end
     end
     ActsAsSolr::ParserMethods.module_eval do
       def parse_results(*args)
         parse_results_orig nil, args[1]
       end
     end
 
     @solr_disabled = true
   end
 
 end
 
 # disable solr actions by default
 TestSolr.disable

Release Information

Released under the MIT license.