erichummel-sunspot_rails 1.2.1a
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +51 -0
- data/LICENSE +18 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +258 -0
- data/Rakefile +18 -0
- data/TESTING.md +35 -0
- data/TODO +8 -0
- data/VERSION.yml +4 -0
- data/dev_tasks/rdoc.rake +24 -0
- data/dev_tasks/release.rake +4 -0
- data/dev_tasks/spec.rake +22 -0
- data/dev_tasks/todo.rake +4 -0
- data/generators/sunspot/sunspot_generator.rb +9 -0
- data/generators/sunspot/templates/sunspot.yml +18 -0
- data/install.rb +1 -0
- data/lib/generators/sunspot_rails/install/install_generator.rb +13 -0
- data/lib/generators/sunspot_rails/install/templates/config/sunspot.yml +17 -0
- data/lib/generators/sunspot_rails.rb +9 -0
- data/lib/sunspot/rails/adapters.rb +83 -0
- data/lib/sunspot/rails/configuration.rb +323 -0
- data/lib/sunspot/rails/init.rb +5 -0
- data/lib/sunspot/rails/log_subscriber.rb +33 -0
- data/lib/sunspot/rails/railtie.rb +36 -0
- data/lib/sunspot/rails/railties/controller_runtime.rb +36 -0
- data/lib/sunspot/rails/request_lifecycle.rb +36 -0
- data/lib/sunspot/rails/searchable.rb +412 -0
- data/lib/sunspot/rails/server.rb +173 -0
- data/lib/sunspot/rails/solr_instrumentation.rb +21 -0
- data/lib/sunspot/rails/solr_logging.rb +63 -0
- data/lib/sunspot/rails/spec_helper.rb +26 -0
- data/lib/sunspot/rails/stub_session_proxy.rb +88 -0
- data/lib/sunspot/rails/tasks.rb +62 -0
- data/lib/sunspot/rails/version.rb +5 -0
- data/lib/sunspot/rails.rb +59 -0
- data/lib/sunspot_rails.rb +12 -0
- data/spec/configuration_spec.rb +173 -0
- data/spec/model_lifecycle_spec.rb +63 -0
- data/spec/model_spec.rb +356 -0
- data/spec/request_lifecycle_spec.rb +61 -0
- data/spec/schema.rb +27 -0
- data/spec/server_spec.rb +37 -0
- data/spec/session_spec.rb +24 -0
- data/spec/spec_helper.rb +46 -0
- data/spec/stub_session_proxy_spec.rb +122 -0
- metadata +155 -0
data/History.txt
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
== 1.2.0 2010-12-28
|
2
|
+
* Compatible with both Rails 2 and Rails 3
|
3
|
+
* Configure Sunspot with a SOLR_URL or WEBSOLR_URL environment variable, also
|
4
|
+
provide a default port based on Rails.env.
|
5
|
+
* Fix the 'Anonymous modules' ArgumentError for Ruby 1.9.2 and Rails 2.3
|
6
|
+
* Fix SQL's ambiguous ID issue when tables are joined
|
7
|
+
|
8
|
+
== 1.1.0 2010-04-01
|
9
|
+
* Added include option to searchable options to allow definition of eager
|
10
|
+
loading associations when indexing
|
11
|
+
|
12
|
+
== 1.0.4 2010-03-19
|
13
|
+
* Fix StubSessionProxy to match new internal API
|
14
|
+
|
15
|
+
== 1.0.2 2010-03-11
|
16
|
+
* Allow use of ActiveRecord object for coordinates extraction
|
17
|
+
* Works with non-standard primary keys
|
18
|
+
* Add :include, :select options to Searchable::search()
|
19
|
+
* Allow specification of min_memory and max_memory in config/sunspot.yml
|
20
|
+
* Searchable now more considerate of model namespaces
|
21
|
+
|
22
|
+
== 1.0.1 2010-03-05
|
23
|
+
* Fix Solr logging compatibility with RSolr 0.12.1
|
24
|
+
|
25
|
+
== 1.0.0 2010-03-03
|
26
|
+
* Sunspot::Rails::Server subclasses Sunspot::Server; no longer needs to shell out
|
27
|
+
* Use Sunspot built-in session proxies in Sunspot::Rails
|
28
|
+
* Sunspot::Rails adapter compatible with assumed inconsistency
|
29
|
+
* Use session proxy for disconnecting Sunspot in specs
|
30
|
+
* Allow specification of first ID for reindex batches.
|
31
|
+
* Log Solr requests in Rails logger
|
32
|
+
* Use class_inheritable_hash for sunspot_options
|
33
|
+
* Add `index` class method, which is like `reindex` but doesn't clear first
|
34
|
+
* Rename sunspot:solr:reindex to sunspot:reindex
|
35
|
+
* Use Sunspot::Installer to bootstrap Rails Solr home
|
36
|
+
|
37
|
+
== 0.10.7
|
38
|
+
* Added Sunspot::Rails::Server class to start/stop/run/bootstrap the solr server
|
39
|
+
* Added log_level key to sunspot.yml, see java docs for valid values (http://java.sun.com/j2se/1.5.0/docs/api/java/util/logging/Level.html)
|
40
|
+
* Added log_file key to sunspot.yml. This defaults to RAILS_ROOT/log/solr_<environment>.log.
|
41
|
+
* Added support for localsolr in sunspot_rails. You can add custom extension.jar files to your Rails.root/solr/lib directory
|
42
|
+
* Added an option to not reindex an object when certain columns have changed.
|
43
|
+
|
44
|
+
== 0.10.6
|
45
|
+
* Added script/generate sunspot support to generate the required sunspot.yml
|
46
|
+
file [Brandon Keepers]
|
47
|
+
|
48
|
+
== 0.10.5
|
49
|
+
* Added a auto_commit_after_request option to sunspot.yml. Sunspot will not
|
50
|
+
automatically commit any changes in solr if you set this value to false.
|
51
|
+
Strongly encouraged for production environment.
|
data/LICENSE
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
2
|
+
a copy of this software and associated documentation files (the
|
3
|
+
'Software'), to deal in the Software without restriction, including
|
4
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
5
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
6
|
+
permit persons to whom the Software is furnished to do so, subject to
|
7
|
+
the following conditions:
|
8
|
+
|
9
|
+
The above copyright notice and this permission notice shall be
|
10
|
+
included in all copies or substantial portions of the Software.
|
11
|
+
|
12
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
13
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
14
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
15
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
16
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
17
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
18
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Mat Brown
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,258 @@
|
|
1
|
+
= Sunspot::Rails
|
2
|
+
|
3
|
+
Sunspot::Rails is a Rails plugin that provides drop-in integration of the
|
4
|
+
Sunspot[http://outoftime.github.com/sunspot] Solr search library with Rails. It
|
5
|
+
provides the following features:
|
6
|
+
|
7
|
+
* Configure Sunspot using config/sunspot.yml
|
8
|
+
* Extend ActiveRecord for easy index configuration, search, and indexing
|
9
|
+
* Automatically index ActiveRecord objects when they are saved, and remove them
|
10
|
+
from the index when they are destroyed (can be disabled)
|
11
|
+
* Automatically commit Solr changes at the end of each request (can be disabled)
|
12
|
+
* Provide utility methods to find and fix orphaned documents and rebuild the
|
13
|
+
Solr index for a given class
|
14
|
+
* Provide rake tasks for starting and stopping the development Solr instance,
|
15
|
+
using the configuration in sunspot.yml
|
16
|
+
|
17
|
+
Sunspot::Rails has been tested with Rails versions 2.3 and 3.0
|
18
|
+
|
19
|
+
== Installation in Rails 3
|
20
|
+
|
21
|
+
In your <code>Gemfile</code>:
|
22
|
+
|
23
|
+
gem 'sunspot_rails'
|
24
|
+
|
25
|
+
== Installation in Rails 2
|
26
|
+
|
27
|
+
In your project's <code>config/environment.rb</code>, add the following gem dependencies:
|
28
|
+
|
29
|
+
config.gem 'sunspot'
|
30
|
+
config.gem 'sunspot_rails'
|
31
|
+
|
32
|
+
Install the gems with:
|
33
|
+
|
34
|
+
rake gems:install
|
35
|
+
|
36
|
+
Generate the file <code>config/sunspot.yml</code>:
|
37
|
+
|
38
|
+
script/generate sunspot
|
39
|
+
|
40
|
+
Rails doesn't automatically load rake tasks from plugins installed as gems
|
41
|
+
(https://rails.lighthouseapp.com/projects/8994/tickets/59). If you installed
|
42
|
+
Sunspot::Rails as a gem, add the following line to your project's Rakefile:
|
43
|
+
|
44
|
+
require 'sunspot/rails/tasks'
|
45
|
+
|
46
|
+
== Using Sunspot::Rails
|
47
|
+
|
48
|
+
If you wish to make modifications to the Solr schema, you can create a custom
|
49
|
+
Solr home in your project directory. In order to do so, create the directory
|
50
|
+
<code>RAILS_ROOT/solr/conf</code>, and copy in the contents of the Solr gem's
|
51
|
+
<code>solr/solr/conf</code> directory. If the files are in the right place,
|
52
|
+
Sunspot::Rails will detect them and tell Solr to use your local configurations.
|
53
|
+
Use caution when modifying <code>schema.xml</code> - Sunspot relies on the
|
54
|
+
field naming scheme in the packaged schema file.
|
55
|
+
|
56
|
+
To start up a Solr instance, issue the following:
|
57
|
+
|
58
|
+
rake sunspot:solr:start
|
59
|
+
|
60
|
+
Note that using the built-in Solr instance packaged with Sunspot is great for
|
61
|
+
development, but is not recommended for production. See the Sunspot
|
62
|
+
documentation for more information.
|
63
|
+
|
64
|
+
== Usage
|
65
|
+
|
66
|
+
=== Setup
|
67
|
+
|
68
|
+
In order for an ActiveRecord model to be indexable and searchable, it must be
|
69
|
+
configured for search. For example:
|
70
|
+
|
71
|
+
class Post < ActiveRecord::Base
|
72
|
+
searchable do
|
73
|
+
text :title, :body
|
74
|
+
integer :blog_id
|
75
|
+
time :updated_at
|
76
|
+
string :sort_title do
|
77
|
+
title.downcase.sub(/^(an?|the) /, '')
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
See the documentation for Sunspot.setup for full details on what can go in the
|
83
|
+
configuration block.
|
84
|
+
|
85
|
+
=== Indexing
|
86
|
+
|
87
|
+
By default, models are indexed whenever they are saved, and removed from the
|
88
|
+
index whenever they are destroyed. This behavior can be disabled:
|
89
|
+
|
90
|
+
class Post < ActiveRecord::Base
|
91
|
+
searchable :auto_index => false, :auto_remove => false do
|
92
|
+
# setup...
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
Note that <b>using the <code>:auto_remove</code> option is not recommended
|
97
|
+
</b>, as destroying an object without removing it from the index will
|
98
|
+
create an orphaned document in the index, which is a Bad Thing. Turning off
|
99
|
+
<code>:auto_index</code> is perfectly safe if you prefer to manage indexing manually
|
100
|
+
(perhaps using a background job).
|
101
|
+
|
102
|
+
If you have disabled lifecycle indexing hooks, you can invoke indexing
|
103
|
+
operations directly on your model:
|
104
|
+
|
105
|
+
post = Post.create
|
106
|
+
post.index
|
107
|
+
post.remove_from_index
|
108
|
+
|
109
|
+
=== Committing
|
110
|
+
|
111
|
+
When data is changed in Solr, it is initially stored in memory and not made
|
112
|
+
available to the currently running searcher instance. Issuing a +commit+ to Solr
|
113
|
+
will cause it to write the changes to disk, and instantiate a new searcher
|
114
|
+
instance. This operation is fairly expensive, so rather than issuing a commit
|
115
|
+
every time a document is added or removed, Sunspot::Rails issues a commit at
|
116
|
+
the end of any request where data has been added to or removed from Solr. If
|
117
|
+
you need to immediately issue a commit, bang!-versions of the methods are
|
118
|
+
available:
|
119
|
+
|
120
|
+
post = Post.create
|
121
|
+
post.index!
|
122
|
+
# this is the same as...
|
123
|
+
post.index
|
124
|
+
Sunspot.commit
|
125
|
+
|
126
|
+
When writing tests outside of the context of a controller request, you will want
|
127
|
+
to use one of these two approaches.
|
128
|
+
|
129
|
+
=== Searching
|
130
|
+
|
131
|
+
Do it like this:
|
132
|
+
|
133
|
+
Post.search do
|
134
|
+
with :blog_id, 1
|
135
|
+
with(:updated_at).greater_than(Time.now - 2.weeks)
|
136
|
+
order :sort_title, :asc
|
137
|
+
paginate :page => 1, :per_page => 15
|
138
|
+
end
|
139
|
+
|
140
|
+
See the documentation for <code>Sunspot.search</code> for all the options
|
141
|
+
available in the search block, and the information available in the result
|
142
|
+
block.
|
143
|
+
|
144
|
+
=== Searching for IDs
|
145
|
+
|
146
|
+
In some situations, you may want to get the IDs for models returned by a search
|
147
|
+
without actually loading the models out of the database. For that, you can
|
148
|
+
call +search_ids+, using the same block format as #search. This will return an
|
149
|
+
array of IDs.
|
150
|
+
|
151
|
+
|
152
|
+
=== Searching for multiple types
|
153
|
+
|
154
|
+
Sunspot is entirely agnostic about whether searches are for one or more types;
|
155
|
+
the only restriction is that columns used for restriction, ordering, etc. are
|
156
|
+
defined in the same way for all types being searched. Sunspot::Rails does not
|
157
|
+
provide any additional support for this, since there is not anything useful to
|
158
|
+
be added, so just use the interface provided by Sunspot:
|
159
|
+
|
160
|
+
Sunspot.search(Post, Comment) do
|
161
|
+
with :blog_id, 1
|
162
|
+
order :created_at, :asc
|
163
|
+
end
|
164
|
+
|
165
|
+
Be sure to check out the Sunspot documentation for all the details.
|
166
|
+
|
167
|
+
=== Adding search functionality in mixins
|
168
|
+
|
169
|
+
Sunspot does not require that search setup for a given class happen all in one
|
170
|
+
place; it is perfectly acceptable to call the <code>Sunspot.setup</code> method
|
171
|
+
more than once. This capability is particularly useful for adding search
|
172
|
+
functionality in mixins. For instance, if you have a +Ratable+ module, you may
|
173
|
+
wish to add additional search fields for searchable classes that mix in that
|
174
|
+
module. For example:
|
175
|
+
|
176
|
+
module Ratable
|
177
|
+
def self.included(base)
|
178
|
+
if base.searchable?
|
179
|
+
base.searchable do
|
180
|
+
float :average_rating do
|
181
|
+
ratings.average(:value)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
Note the use of <code>base.searchable?</code> - this ensures that only classes
|
189
|
+
that already have search enabled will have the additional configuration added.
|
190
|
+
The above pattern requires that the class be declared searchable before the
|
191
|
+
module is mixed in; other patterns (such as passing a :searchable option to an
|
192
|
+
acts_as_-style declaration) may be more flexible.
|
193
|
+
|
194
|
+
=== Utility methods
|
195
|
+
|
196
|
+
If you need to completely reindex all of the instances of a given model class,
|
197
|
+
you can issue:
|
198
|
+
|
199
|
+
Post.reindex
|
200
|
+
|
201
|
+
If for some reason models get deleted from the database, but not from the index,
|
202
|
+
they will become index orphans - not a good situation. To get IDs that exist in
|
203
|
+
the index but not the database, you can use the +index_orphans+ method; to
|
204
|
+
remove those documents from the index, use +clean_index_orphans+. Note that
|
205
|
+
neither of these operations should be needed if Sunspot and Sunspot::Rails are
|
206
|
+
used as intended.
|
207
|
+
|
208
|
+
|
209
|
+
== Testing Solr integration using RSpec
|
210
|
+
|
211
|
+
To disable the sunspot-solr integration for your active record models, require
|
212
|
+
the file `sunspot/rails/spec_helper`
|
213
|
+
|
214
|
+
Then, in your spec, use the #disconnect_sunspot method:
|
215
|
+
|
216
|
+
require 'sunspot/rails/spec_helper'
|
217
|
+
|
218
|
+
describe Post do
|
219
|
+
disconnect_sunspot
|
220
|
+
|
221
|
+
it 'should have some behavior'
|
222
|
+
# ...
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
In all of the examples in this group, all Sunspot calls will be stubbed out. The
|
227
|
+
Sunspot#search method will return a stub search object that mimics a search with
|
228
|
+
no results.
|
229
|
+
|
230
|
+
== Further Reading
|
231
|
+
|
232
|
+
Reading the {Sunspot documentation}[http://outoftime.github.com/sunspot/docs] is
|
233
|
+
highly recommended. Sunspot::Rails exists to wrap Sunspot with a Rails-friendly
|
234
|
+
API, but almost all of the functionality you use in Sunspot::Rails is
|
235
|
+
implemented in Sunspot.
|
236
|
+
|
237
|
+
Posts about Sunspot on my blog are available at http://outofti.me/tagged/sunspot
|
238
|
+
|
239
|
+
== Bugs
|
240
|
+
|
241
|
+
Please submit bug reports to
|
242
|
+
http://outoftime.lighthouseapp.com/projects/20339-sunspot
|
243
|
+
|
244
|
+
== Contributors
|
245
|
+
|
246
|
+
- Mat Brown (mat@patch.com)
|
247
|
+
- Peer Allan (peer.allan@gmail.com)
|
248
|
+
- Michael Moen (michael@underpantsgnome.com)
|
249
|
+
- Benjamin Krause (bk@benjaminkrause.com)
|
250
|
+
- Adam Salter (adam@codebright.net)
|
251
|
+
- Brandon Keepers (brandon@opensoul.org)
|
252
|
+
- Paul Canavese (paul@canavese.org)
|
253
|
+
- John Eberly (jeberly@elctech.com)
|
254
|
+
- Gert Thiel (gertthiel@gmail.com)
|
255
|
+
|
256
|
+
== License
|
257
|
+
|
258
|
+
Sunspot::Rails is distributed under the MIT License, copyright (c) 2009 Mat Brown
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/rdoctask'
|
3
|
+
|
4
|
+
if File.exist?(sunspot_lib = File.expand_path(File.join(File.dirname(__FILE__), '..', 'sunspot', 'lib')))
|
5
|
+
STDERR.puts("Using sunspot lib at #{sunspot_lib}")
|
6
|
+
$: << sunspot_lib
|
7
|
+
end
|
8
|
+
|
9
|
+
task :environment do
|
10
|
+
if ENV['SUNSPOT_LIB']
|
11
|
+
$: << ENV['SUNSPOT_LIB']
|
12
|
+
end
|
13
|
+
ENV['RAILS_ROOT'] ||= File.join(File.dirname(__FILE__), 'spec', 'rails3')
|
14
|
+
ENV['RAILS_ENV'] ||= 'test'
|
15
|
+
require File.expand_path(File.join(ENV['RAILS_ROOT'], 'config', 'environment.rb'))
|
16
|
+
end
|
17
|
+
|
18
|
+
FileList['dev_tasks/*.rake', 'lib/sunspot/rails/tasks.rb'].each { |file| load(file) }
|
data/TESTING.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Testing `sunspot_rails`
|
2
|
+
|
3
|
+
Note: All the paths mentioned in here are relative to the current directory, or `sunspot/sunspot_rails`.
|
4
|
+
|
5
|
+
The `sunspot_rails` gem is tested with RSpec, and its spec suite is located in `spec`.
|
6
|
+
|
7
|
+
These specs are to be run against up to date Rails 2 and Rails 3 applications, included at `spec/rails2` and `spec/rails3`, respectively. The `spec_helper.rb` file loads the environment for these applications based on the `RAILS_ROOT` provided when invoking tests, outlined below.
|
8
|
+
|
9
|
+
## Start Solr
|
10
|
+
|
11
|
+
Specs expect to connect to Solr on `http://localhost:8980/solr`
|
12
|
+
|
13
|
+
rake sunspot:solr:start
|
14
|
+
|
15
|
+
## Install dependencies
|
16
|
+
|
17
|
+
Each application uses Bundler to manage its dependencies. The `Gemfile` also installs the `sunspot` and `sunspot_rails` gems from your copies checked out locally. Because Bundler expands the full path to `sunspot` and `sunspot_rails`, we're excluding its generated `Gemfile.lock` file from version control.
|
18
|
+
|
19
|
+
pushd spec/rails2
|
20
|
+
bundle install
|
21
|
+
cd ../rails3
|
22
|
+
bundle install
|
23
|
+
popd
|
24
|
+
|
25
|
+
## Invoke specs
|
26
|
+
|
27
|
+
The project contains wrapper scripts that set up the environment to run the
|
28
|
+
specs under Rails 2 and Rails 3 respectively:
|
29
|
+
|
30
|
+
rake spec:rails2
|
31
|
+
rake spec:rails3
|
32
|
+
|
33
|
+
Or you can run them both:
|
34
|
+
|
35
|
+
rake spec
|
data/TODO
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
* Delegate new_search method
|
2
|
+
=======
|
3
|
+
* Fix final status output for reindex
|
4
|
+
* Add batch-per-request option
|
5
|
+
* Optionally yield from reindex
|
6
|
+
* Access to all searchable classes
|
7
|
+
* Add a method to disable sunspot updates for certain values, e.g.
|
8
|
+
if you just touch a record, sunspot shouldn't index the
|
data/VERSION.yml
ADDED
data/dev_tasks/rdoc.rake
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
begin
|
2
|
+
require 'hanna/rdoctask'
|
3
|
+
rescue LoadError
|
4
|
+
if require 'rubygems'
|
5
|
+
retry
|
6
|
+
end
|
7
|
+
# It's OK if hanna isn't installed.
|
8
|
+
end
|
9
|
+
|
10
|
+
Rake::RDocTask.new(:doc) do |rdoc|
|
11
|
+
rdoc.main = 'README.rdoc'
|
12
|
+
rdoc.rdoc_files.include('README.rdoc', 'lib/sunspot/rails/**/*.rb', 'lib/sunspot/rails.rb')
|
13
|
+
rdoc.rdoc_dir = 'doc'
|
14
|
+
end
|
15
|
+
|
16
|
+
namespace :doc do
|
17
|
+
desc 'Generate rdoc and move into pages directory'
|
18
|
+
task :publish => :redoc do
|
19
|
+
doc_dir = File.join(File.dirname(__FILE__), '..', 'doc')
|
20
|
+
publish_dir = File.join(File.dirname(__FILE__), '..', '..', 'pages', 'rails', 'docs')
|
21
|
+
FileUtils.rm_rf(publish_dir) if File.exist?(publish_dir)
|
22
|
+
FileUtils.cp_r(doc_dir, publish_dir)
|
23
|
+
end
|
24
|
+
end
|
data/dev_tasks/spec.rake
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
desc 'Run spec suite in both Rails 2 and Rails 3'
|
2
|
+
task :spec => [:"spec:rails2", :"spec:rails3"]
|
3
|
+
|
4
|
+
namespace :spec do
|
5
|
+
desc 'Run spec suite in Rails 2 application'
|
6
|
+
task :rails2 do
|
7
|
+
ENV['BUNDLE_GEMFILE'] = 'spec/rails2/Gemfile'
|
8
|
+
ENV['RAILS_ROOT'] = 'spec/rails2'
|
9
|
+
require 'bundler'
|
10
|
+
Bundler.setup(:default, :test)
|
11
|
+
system "spec --color #{ENV['SPEC'] || 'spec'}"
|
12
|
+
end
|
13
|
+
|
14
|
+
desc 'Run spec suite in Rails 3 application'
|
15
|
+
task :rails3 do
|
16
|
+
ENV['BUNDLE_GEMFILE'] = 'spec/rails3/Gemfile'
|
17
|
+
ENV['RAILS_ROOT'] = 'spec/rails3'
|
18
|
+
require 'bundler'
|
19
|
+
Bundler.setup(:default, :test)
|
20
|
+
system "rspec --color #{ENV['SPEC'] || 'spec'}"
|
21
|
+
end
|
22
|
+
end
|
data/dev_tasks/todo.rake
ADDED
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module SunspotRails
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
def self.source_root
|
5
|
+
@source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
6
|
+
end
|
7
|
+
def copy_config_file
|
8
|
+
template 'config/sunspot.yml'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module Sunspot #:nodoc:
|
2
|
+
module Rails #:nodoc:
|
3
|
+
#
|
4
|
+
# This module provides Sunspot Adapter implementations for ActiveRecord
|
5
|
+
# models.
|
6
|
+
#
|
7
|
+
module Adapters
|
8
|
+
class ActiveRecordInstanceAdapter < Sunspot::Adapters::InstanceAdapter
|
9
|
+
#
|
10
|
+
# Return the primary key for the adapted instance
|
11
|
+
#
|
12
|
+
# ==== Returns
|
13
|
+
#
|
14
|
+
# Integer:: Database ID of model
|
15
|
+
#
|
16
|
+
def id
|
17
|
+
@instance.id
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class ActiveRecordDataAccessor < Sunspot::Adapters::DataAccessor
|
22
|
+
# options for the find
|
23
|
+
attr_accessor :include, :select
|
24
|
+
|
25
|
+
#
|
26
|
+
# Set the fields to select from the database. This will be passed
|
27
|
+
# to ActiveRecord.
|
28
|
+
#
|
29
|
+
# ==== Parameters
|
30
|
+
#
|
31
|
+
# value<Mixed>:: String of comma-separated columns or array of columns
|
32
|
+
#
|
33
|
+
def select=(value)
|
34
|
+
value = value.join(', ') if value.respond_to?(:join)
|
35
|
+
@select = value
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# Get one ActiveRecord instance out of the database by ID
|
40
|
+
#
|
41
|
+
# ==== Parameters
|
42
|
+
#
|
43
|
+
# id<String>:: Database ID of model to retreive
|
44
|
+
#
|
45
|
+
# ==== Returns
|
46
|
+
#
|
47
|
+
# ActiveRecord::Base:: ActiveRecord model
|
48
|
+
#
|
49
|
+
def load(id)
|
50
|
+
@clazz.first(options_for_find.merge(
|
51
|
+
:conditions => { @clazz.primary_key => id}
|
52
|
+
))
|
53
|
+
end
|
54
|
+
|
55
|
+
#
|
56
|
+
# Get a collection of ActiveRecord instances out of the database by ID
|
57
|
+
#
|
58
|
+
# ==== Parameters
|
59
|
+
#
|
60
|
+
# ids<Array>:: Database IDs of models to retrieve
|
61
|
+
#
|
62
|
+
# ==== Returns
|
63
|
+
#
|
64
|
+
# Array:: Collection of ActiveRecord models
|
65
|
+
#
|
66
|
+
def load_all(ids)
|
67
|
+
@clazz.all(options_for_find.merge(
|
68
|
+
:conditions => { @clazz.primary_key => ids.map { |id| id }}
|
69
|
+
))
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def options_for_find
|
75
|
+
options = {}
|
76
|
+
options[:include] = @include unless @include.blank?
|
77
|
+
options[:select] = @select unless @select.blank?
|
78
|
+
options
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|