acts_as_ferret 0.4.7 → 0.4.8.rails3
Sign up to get free protection for your applications and to get access to all the features.
- data/README +36 -2
- data/acts_as_ferret.gemspec +5 -4
- data/config/ferret_server.yml +2 -2
- data/lib/act_methods.rb +2 -2
- data/lib/acts_as_ferret.rb +14 -9
- data/lib/ferret_server.rb +9 -9
- data/lib/instance_methods.rb +1 -1
- data/lib/server_manager.rb +24 -11
- data/lib/unix_daemon.rb +1 -1
- data/{init.rb → rails/init.rb} +0 -0
- data/script/ferret_server +2 -0
- metadata +10 -5
data/README
CHANGED
@@ -21,9 +21,8 @@ http://github.com/jkraemer/acts_as_ferret/tree/master .
|
|
21
21
|
|
22
22
|
Add this to your project's config/environment.rb:
|
23
23
|
|
24
|
-
<tt>config.gem 'acts_as_ferret', :version => '~> 0.4.
|
24
|
+
<tt>config.gem 'acts_as_ferret', :version => '~> 0.4.8'</tt>
|
25
25
|
|
26
|
-
With Rails 3 of course instead you have to update your Gemfile, but I guess you already knew that ;-)
|
27
26
|
With the gem installed, change into your RAILS_ROOT and run the supplied aaf_install script.
|
28
27
|
This will copy rake tasks, capistrano recipes and the ferret server config and startup script
|
29
28
|
into your project.
|
@@ -43,6 +42,37 @@ No additional setup needed.
|
|
43
42
|
|
44
43
|
== Usage
|
45
44
|
|
45
|
+
There are two ways to make your models searchable with aaf. The option to configure acts_as_ferret with
|
46
|
+
a single configuration file has been introduced because it makes more sense when a single index holds multiple
|
47
|
+
models - it's simply more logicl to define that index and tell which models should go into it than to call
|
48
|
+
acts_as_ferret in each model pointing to the same index every time.
|
49
|
+
|
50
|
+
=== central configuration file
|
51
|
+
|
52
|
+
With this option, all acts_as_ferret indexes are configured in a single file, RAILS_ROOT/config/aaf.rb:
|
53
|
+
|
54
|
+
ActsAsFerret::define_index( 'my_index',
|
55
|
+
:models => {
|
56
|
+
SomeModel => {
|
57
|
+
:fields => {
|
58
|
+
:name => { :boost => 4, :store => :yes, :via => :ferret_title },
|
59
|
+
:foo => { :store => :no, :index => :untokenized },
|
60
|
+
:baz => { :store => :yes, :via => :ferret_content }
|
61
|
+
}
|
62
|
+
}
|
63
|
+
} )
|
64
|
+
|
65
|
+
ActsAsFerret::define_index( 'some_other_index',
|
66
|
+
:models => {
|
67
|
+
Foo => { :fields => { ... } },
|
68
|
+
Bar => { ... },
|
69
|
+
} )
|
70
|
+
|
71
|
+
|
72
|
+
As you can see for every index you want to define there's a single call, and each model that should go
|
73
|
+
into the index gets it's own ferret options hash (see the acts_as_ferret class method docs for all available options).
|
74
|
+
|
75
|
+
=== In your models (the old fashioned way)
|
46
76
|
include the following in your model class (specifiying the fields you want to get indexed):
|
47
77
|
|
48
78
|
<tt>acts_as_ferret :fields => [ :title, :description ]</tt>
|
@@ -55,6 +85,10 @@ less results).
|
|
55
85
|
|
56
86
|
Please see ActsAsFerret::ActMethods#acts_as_ferret for more information.
|
57
87
|
|
88
|
+
== Known issues
|
89
|
+
|
90
|
+
aaf is not yet ready for Rails3. Feel free to submit patches!
|
91
|
+
|
58
92
|
== License
|
59
93
|
|
60
94
|
Released under the MIT license.
|
data/acts_as_ferret.gemspec
CHANGED
@@ -5,8 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 4
|
8
|
-
-
|
9
|
-
|
8
|
+
- 8
|
9
|
+
- rails3
|
10
|
+
version: 0.4.8.rails3
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Jens Kraemer
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-07-
|
18
|
+
date: 2010-07-13 14:10:00 +02:00
|
18
19
|
default_executable: aaf_install
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
@@ -208,7 +209,7 @@ files:
|
|
208
209
|
- doc/demo/vendor/plugins/will_paginate/test/pagination_test.rb
|
209
210
|
- doc/monit-example
|
210
211
|
- doc/README.win32
|
211
|
-
- init.rb
|
212
|
+
- rails/init.rb
|
212
213
|
- install.rb
|
213
214
|
- lib
|
214
215
|
- lib/act_methods.rb
|
data/config/ferret_server.yml
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
# host: where to reach the DRb server (used by application processes to contact the server)
|
3
3
|
# port: which port the server should listen on
|
4
4
|
# socket: where the DRb server should create the socket (absolute path), this setting overrides host:port configuration
|
5
|
-
# pid_file: location of the server's pid file (relative to
|
6
|
-
# log_file: log file (default:
|
5
|
+
# pid_file: location of the server's pid file (relative to Rails.root)
|
6
|
+
# log_file: log file (default: Rails.root/log/ferret_server.log
|
7
7
|
# log_level: log level for the server's logger
|
8
8
|
production:
|
9
9
|
host: localhost
|
data/lib/act_methods.rb
CHANGED
@@ -26,7 +26,7 @@ module ActsAsFerret #:nodoc:
|
|
26
26
|
# to determine if it should be indexed or not.
|
27
27
|
#
|
28
28
|
# index_dir:: declares the directory where to put the index for this class.
|
29
|
-
# The default is
|
29
|
+
# The default is Rails.root/index/Rails.env/CLASSNAME.
|
30
30
|
# The index directory will be created if it doesn't exist.
|
31
31
|
#
|
32
32
|
# reindex_batch_size:: reindexing is done in batches of this size, default is 1000
|
@@ -75,7 +75,7 @@ module ActsAsFerret #:nodoc:
|
|
75
75
|
# set up AR hooks
|
76
76
|
after_create :ferret_create
|
77
77
|
after_update :ferret_update
|
78
|
-
after_destroy :ferret_destroy
|
78
|
+
after_destroy :ferret_destroy
|
79
79
|
end
|
80
80
|
|
81
81
|
cattr_accessor :aaf_configuration
|
data/lib/acts_as_ferret.rb
CHANGED
@@ -82,7 +82,7 @@ require 'rdig_adapter'
|
|
82
82
|
# whatever reason.
|
83
83
|
#
|
84
84
|
# remote:: Set this to false to force acts_as_ferret into local (non-DRb) mode even if
|
85
|
-
# config/ferret_server.yml contains a section for the current
|
85
|
+
# config/ferret_server.yml contains a section for the current Rails.env
|
86
86
|
# Usually you won't need to touch this option - just configure DRb for
|
87
87
|
# production mode in ferret_server.yml.
|
88
88
|
#
|
@@ -107,7 +107,7 @@ module ActsAsFerret
|
|
107
107
|
@@index_using_classes = {}
|
108
108
|
def self.index_using_classes; @@index_using_classes end
|
109
109
|
|
110
|
-
@@logger = Logger.new "#{
|
110
|
+
@@logger = Logger.new "#{Rails.root || '.'}/log/acts_as_ferret.log"
|
111
111
|
@@logger.level = ActiveRecord::Base.logger.level rescue Logger::DEBUG
|
112
112
|
mattr_accessor :logger
|
113
113
|
|
@@ -145,10 +145,15 @@ module ActsAsFerret
|
|
145
145
|
remote?
|
146
146
|
|
147
147
|
|
148
|
-
#
|
148
|
+
# Declares an index.
|
149
149
|
#
|
150
|
-
#
|
151
|
-
#
|
150
|
+
# Use this method to define your indexes in a global initializer (i.e. config/initializers/aaf.rb).
|
151
|
+
# This is especially useful if you want to have multiple classes share the same index for cross-model
|
152
|
+
# searching as you only need a single call to declare the index for all models.
|
153
|
+
#
|
154
|
+
# This method is also used internally to declare an index when you use the
|
155
|
+
# acts_as_ferret call inside your class (which in turn can be omitted if the initializer is used).
|
156
|
+
# Returns the created index instance.
|
152
157
|
#
|
153
158
|
# === Options are:
|
154
159
|
#
|
@@ -250,7 +255,7 @@ module ActsAsFerret
|
|
250
255
|
|
251
256
|
def self.load_config
|
252
257
|
# using require_dependency to make the reloading in dev mode work.
|
253
|
-
require_dependency "#{
|
258
|
+
require_dependency "#{Rails.root}/config/aaf.rb"
|
254
259
|
ActsAsFerret::logger.info "loaded configuration file aaf.rb"
|
255
260
|
rescue LoadError
|
256
261
|
ensure
|
@@ -513,10 +518,10 @@ module ActsAsFerret
|
|
513
518
|
|
514
519
|
|
515
520
|
# make sure the default index base dir exists. by default, all indexes are created
|
516
|
-
# under
|
521
|
+
# under Rails.root/index/Rails.env
|
517
522
|
def self.init_index_basedir
|
518
|
-
index_base = "#{
|
519
|
-
@@index_dir = "#{index_base}/#{
|
523
|
+
index_base = "#{Rails.root || '.'}/index"
|
524
|
+
@@index_dir = "#{index_base}/#{Rails.env}"
|
520
525
|
end
|
521
526
|
|
522
527
|
mattr_accessor :index_dir
|
data/lib/ferret_server.rb
CHANGED
@@ -14,9 +14,9 @@ module ActsAsFerret
|
|
14
14
|
DEFAULTS = {
|
15
15
|
'host' => 'localhost',
|
16
16
|
'port' => '9009',
|
17
|
-
'cf' => "#{
|
18
|
-
'pid_file' => "#{
|
19
|
-
'log_file' => "#{
|
17
|
+
'cf' => "#{Rails.root}/config/ferret_server.yml",
|
18
|
+
'pid_file' => "#{Rails.root}/log/ferret_server.pid",
|
19
|
+
'log_file' => "#{Rails.root}/log/ferret_server.log",
|
20
20
|
'log_level' => 'debug',
|
21
21
|
'socket' => nil,
|
22
22
|
'script' => nil
|
@@ -27,8 +27,8 @@ module ActsAsFerret
|
|
27
27
|
def initialize (file=DEFAULTS['cf'])
|
28
28
|
@everything = YAML.load(ERB.new(IO.read(file)).result)
|
29
29
|
raise "malformed ferret server config" unless @everything.is_a?(Hash)
|
30
|
-
@config = DEFAULTS.merge(@everything[
|
31
|
-
if @everything[
|
30
|
+
@config = DEFAULTS.merge(@everything[Rails.env] || {})
|
31
|
+
if @everything[Rails.env]
|
32
32
|
@config['uri'] = socket.nil? ? "druby://#{host}:#{port}" : "drbunix:#{socket}"
|
33
33
|
end
|
34
34
|
end
|
@@ -46,7 +46,7 @@ module ActsAsFerret
|
|
46
46
|
# search requests from models declared to 'acts_as_ferret :remote => true'
|
47
47
|
#
|
48
48
|
# Usage:
|
49
|
-
# - modify
|
49
|
+
# - modify Rails.root/config/ferret_server.yml to suit your needs.
|
50
50
|
# - environments for which no section in the config file exists will use
|
51
51
|
# the index locally (good for unit tests/development mode)
|
52
52
|
# - run script/ferret_server to start the server:
|
@@ -73,7 +73,7 @@ module ActsAsFerret
|
|
73
73
|
ActiveRecord::Base.logger = @logger = Logger.new(@cfg.log_file)
|
74
74
|
ActiveRecord::Base.logger.level = Logger.const_get(@cfg.log_level.upcase) rescue Logger::DEBUG
|
75
75
|
if @cfg.script
|
76
|
-
path = File.join(
|
76
|
+
path = File.join(Rails.root, @cfg.script)
|
77
77
|
load path
|
78
78
|
@logger.info "loaded custom startup script from #{path}"
|
79
79
|
end
|
@@ -82,14 +82,14 @@ module ActsAsFerret
|
|
82
82
|
################################################################################
|
83
83
|
# start the server as a daemon process
|
84
84
|
def start
|
85
|
-
raise "ferret_server not configured for #{
|
85
|
+
raise "ferret_server not configured for #{Rails.env}" unless (@cfg.uri rescue nil)
|
86
86
|
platform_daemon { run_drb_service }
|
87
87
|
end
|
88
88
|
|
89
89
|
################################################################################
|
90
90
|
# run the server and block until it exits
|
91
91
|
def run
|
92
|
-
raise "ferret_server not configured for #{
|
92
|
+
raise "ferret_server not configured for #{Rails.env}" unless (@cfg.uri rescue nil)
|
93
93
|
run_drb_service
|
94
94
|
end
|
95
95
|
|
data/lib/instance_methods.rb
CHANGED
data/lib/server_manager.rb
CHANGED
@@ -17,11 +17,11 @@ OptionParser.new do |optparser|
|
|
17
17
|
exit
|
18
18
|
end
|
19
19
|
|
20
|
-
optparser.on('-R', '--root=PATH', 'Set
|
20
|
+
optparser.on('-R', '--root=PATH', 'Set Rails.root to the given string') do |r|
|
21
21
|
$ferret_server_options['root'] = r
|
22
22
|
end
|
23
23
|
|
24
|
-
optparser.on('-e', '--environment=NAME', 'Set
|
24
|
+
optparser.on('-e', '--environment=NAME', 'Set Rails.env to the given string') do |e|
|
25
25
|
$ferret_server_options['environment'] = e
|
26
26
|
end
|
27
27
|
|
@@ -37,19 +37,32 @@ OptionParser.new do |optparser|
|
|
37
37
|
end
|
38
38
|
|
39
39
|
################################################################################
|
40
|
+
|
41
|
+
def determine_rails_root
|
42
|
+
possible_rails_roots = [
|
43
|
+
$ferret_server_options['root'],
|
44
|
+
(defined?(FERRET_SERVER) ? File.join(File.dirname(FERRET_SERVER), '..') : nil),
|
45
|
+
File.join(File.dirname(__FILE__), *(['..']*4)),
|
46
|
+
'.'
|
47
|
+
].compact
|
48
|
+
# take the first dir where environment.rb can be found
|
49
|
+
possible_rails_roots.find{ |dir| File.readable?(File.join(dir, 'config', 'environment.rb')) }
|
50
|
+
end
|
51
|
+
|
40
52
|
begin
|
41
53
|
ENV['FERRET_USE_LOCAL_INDEX'] = 'true'
|
42
54
|
ENV['RAILS_ENV'] = $ferret_server_options['environment']
|
43
|
-
|
44
55
|
# determine RAILS_ROOT unless already set
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
56
|
+
Rails.root = determine_rails_root
|
57
|
+
|
58
|
+
begin
|
59
|
+
require File.join(Rails.root, 'config', 'environment')
|
60
|
+
rescue LoadError
|
61
|
+
puts "Unable to find Rails environment.rb in any of these locations:\n#{possible_rails_roots.join("\n")}\nPlease use the --root option of ferret_server to point it to your Rails.root."
|
62
|
+
raise $!
|
63
|
+
end
|
64
|
+
|
65
|
+
# require 'acts_as_ferret'
|
53
66
|
ActsAsFerret::Remote::Server.new.send($ferret_server_action)
|
54
67
|
rescue Exception => e
|
55
68
|
$stderr.puts(e.message)
|
data/lib/unix_daemon.rb
CHANGED
@@ -13,7 +13,7 @@ module ActsAsFerret
|
|
13
13
|
trap("TERM") { exit(0) }
|
14
14
|
sess_id = Process.setsid
|
15
15
|
STDIN.reopen("/dev/null")
|
16
|
-
STDOUT.reopen("#{
|
16
|
+
STDOUT.reopen("#{Rails.root}/log/ferret_server.out", "a")
|
17
17
|
STDERR.reopen(STDOUT)
|
18
18
|
block.call
|
19
19
|
end
|
data/{init.rb → rails/init.rb}
RENAMED
File without changes
|
data/script/ferret_server
CHANGED
metadata
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_ferret
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: -428173559
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 4
|
8
|
-
-
|
9
|
-
|
9
|
+
- 8
|
10
|
+
- rails3
|
11
|
+
version: 0.4.8.rails3
|
10
12
|
platform: ruby
|
11
13
|
authors:
|
12
14
|
- Jens Kraemer
|
@@ -14,7 +16,7 @@ autorequire:
|
|
14
16
|
bindir: bin
|
15
17
|
cert_chain: []
|
16
18
|
|
17
|
-
date: 2010-07-
|
19
|
+
date: 2010-07-13 14:10:00 +02:00
|
18
20
|
default_executable: aaf_install
|
19
21
|
dependencies:
|
20
22
|
- !ruby/object:Gem::Dependency
|
@@ -24,6 +26,7 @@ dependencies:
|
|
24
26
|
requirements:
|
25
27
|
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
27
30
|
segments:
|
28
31
|
- 0
|
29
32
|
version: "0"
|
@@ -167,7 +170,7 @@ files:
|
|
167
170
|
- doc/demo/vendor/plugins/will_paginate/test/pagination_test.rb
|
168
171
|
- doc/monit-example
|
169
172
|
- doc/README.win32
|
170
|
-
- init.rb
|
173
|
+
- rails/init.rb
|
171
174
|
- install.rb
|
172
175
|
- lib/act_methods.rb
|
173
176
|
- lib/acts_as_ferret.rb
|
@@ -213,6 +216,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
213
216
|
requirements:
|
214
217
|
- - ">="
|
215
218
|
- !ruby/object:Gem::Version
|
219
|
+
hash: 3
|
216
220
|
segments:
|
217
221
|
- 0
|
218
222
|
version: "0"
|
@@ -220,13 +224,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
220
224
|
requirements:
|
221
225
|
- - ">="
|
222
226
|
- !ruby/object:Gem::Version
|
227
|
+
hash: 3
|
223
228
|
segments:
|
224
229
|
- 0
|
225
230
|
version: "0"
|
226
231
|
requirements: []
|
227
232
|
|
228
233
|
rubyforge_project: acts_as_ferret
|
229
|
-
rubygems_version: 1.3.
|
234
|
+
rubygems_version: 1.3.7
|
230
235
|
signing_key:
|
231
236
|
specification_version: 3
|
232
237
|
summary: acts_as_ferret - Ferret based full text search for any ActiveRecord model
|