• Stars
    star
    102
  • Rank 335,584 (Top 7 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 15 years ago
  • Updated about 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

ActsAsSolr with new features

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.

More Repositories

1

inploy

Rails and Sinatra deployment made easy
Ruby
401
star
2

signal

An integration server written in Rails and integrated with metric_fu, rspec, cucumber and maven. Easy to install and easy to use
Ruby
176
star
3

rails6_template

A template for a Rails 5 application
Ruby
124
star
4

kilt

A client that listens to Pivotal Tracker activities and notifies them with Growl (Mac OSx), Libnotify (Linux) or Snarl (Windows)
Ruby
104
star
5

ansible-project-bootstrap

Ansible project boostrap is a default Ansible project you can fork and improve with your needs
Jinja
66
star
6

conventional-changelog-ruby

Ruby lib and executable to generate a conventional changelog
Ruby
50
star
7

activerecord_i18n_defaults

Common attributes translations for Rails 2.2+
Ruby
32
star
8

jetty-solr

A Jetty server with Solr embedded and configured, ready to use with acts_as_solr_reloaded
Shell
28
star
9

shouty

A Twitter-like for your intranet
Ruby
22
star
10

active_lucene

ActiveRecord/ActiveModel's like interface for Lucene
Ruby
21
star
11

gemhub

Simple gem creation
Ruby
20
star
12

remarkable_paperclip

Paperclip Ramarkable Matchers
Ruby
15
star
13

rspec-maven-plugin

Fork of http://svn.codehaus.org/mojo/trunk/sandbox/rspec-maven-plugin/
Java
12
star
14

auth_helpers

AuthHelpers is a collection of modules and controller to extend your Authlogic models. Currently it supports Confirmable and Recoverable behavior.
Ruby
11
star
15

remarkable_thinking_sphinx

Thinking Sphinx Remarkable Matchers
Ruby
10
star
16

github-user-events

A better interface to view GitHub's users's public activity
CoffeeScript
10
star
17

contacts_rails

Google, Yahoo and Live Contacts in your Rails application with only a line of code
Ruby
9
star
18

redtube

A Ruby interface to the Redtube API
Ruby
9
star
19

haml4j

Haml on a Java plataform
Java
8
star
20

remarkable_acts_as_taggable_on

Acts As Taggable On Remarkable Matchers
Ruby
7
star
21

jasmine-jquery-matchers

Jasmine matchers to be used with jQuery
JavaScript
7
star
22

remarkable_inherited_resources

Inherited Resources Remarkable Matchers
Ruby
7
star
23

rocr

Ruby OCR, currently only supports Gocr
Ruby
6
star
24

remarkable_extensions

Collection of unofficial Remarkable matchers
Ruby
5
star
25

liquid4j

Liquid on the Java plataform
Java
5
star
26

rspec-vraptor

RSpec's official VRaptor plugin
Ruby
4
star
27

remarkable_plugin

A Remarkable plugin generator
Ruby
4
star
28

j6

Like a G6 jQuery helpers
JavaScript
3
star
29

remarkable_you_name_it

Basic plugin structure for your custom Remarkable matchers
Ruby
3
star
30

hackerrank

Maintained Ruby wrapper to the HackerRank API
Ruby
3
star
31

will_paginate_latests

Rails plugin that paginates a model in a descendant order and works with i18n in the view
Ruby
3
star
32

vraptor2_sexy_urls

Sexy URLs in VRaptor
Java
2
star
33

haml4j_demo_app

A Java web application demo using Haml4j in the view and VRaptor Sexy Urls as the controller
Java
2
star
34

rhyme

A Java to Ruby objects translator
Ruby
2
star
35

railersbr

"We don't develop our system in Rails because there aren't enough railers in Brasil", you're wrong.
Ruby
2
star
36

iceproject

Rails Rumble "Simulation" project
Ruby
2
star
37

my_ldap_authenticator

A simple LDAP authenticator for simple LDAP servers
Ruby
2
star
38

lunr

Not-enterprise search platform
Ruby
2
star
39

ssophia

A SSO written in top of Devise/Rails
Ruby
2
star
40

dynamic_error_pages

Rails Dynamic Error Pages
Ruby
2
star
41

signal-auth

A plugin for Signal that adds authentication
Ruby
2
star
42

shoutt

Ruby
2
star
43

rails_reports

Ruby
1
star
44

acts_as_solr_reloaded_demo

ActsAsSolrReloaded Demo
Ruby
1
star
45

rails-rspec-matchers

Ruby
1
star
46

remarkable_friendly_id

A remarkable matcher for friendly_id
Ruby
1
star
47

sunspot-solr-server

1
star
48

remarkable_activerecord

Ruby
1
star
49

mysql-statsd

Send data to Statsd from MySQL
Ruby
1
star
50

ruqa

Ruby Query A... (I'm looking the meaning for the A)
Ruby
1
star
51

brasil.com

Ruby
1
star
52

remarkable_liquid

Remarkable Liquid Matchers
Ruby
1
star
53

active_lunr

Lunr plugin for Rails
Ruby
1
star