acts_as_ferret 0.4.8.2 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README +2 -6
- data/bin/aaf_install +10 -6
- data/config/ferret_server.yml +2 -2
- data/doc/demo/app/models/stats.rb +1 -1
- data/lib/acts_as_ferret.rb +39 -37
- data/lib/{act_methods.rb → acts_as_ferret/act_methods.rb} +1 -1
- data/lib/{blank_slate.rb → acts_as_ferret/blank_slate.rb} +0 -0
- data/lib/{bulk_indexer.rb → acts_as_ferret/bulk_indexer.rb} +0 -0
- data/lib/{class_methods.rb → acts_as_ferret/class_methods.rb} +0 -0
- data/lib/{ferret_extensions.rb → acts_as_ferret/ferret_extensions.rb} +12 -16
- data/lib/{ferret_find_methods.rb → acts_as_ferret/ferret_find_methods.rb} +0 -0
- data/lib/{ferret_result.rb → acts_as_ferret/ferret_result.rb} +0 -0
- data/lib/{index.rb → acts_as_ferret/index.rb} +0 -0
- data/lib/{instance_methods.rb → acts_as_ferret/instance_methods.rb} +1 -1
- data/lib/{local_index.rb → acts_as_ferret/local_index.rb} +7 -4
- data/lib/{more_like_this.rb → acts_as_ferret/more_like_this.rb} +0 -0
- data/lib/{multi_index.rb → acts_as_ferret/multi_index.rb} +0 -0
- data/lib/acts_as_ferret/railtie.rb +16 -0
- data/lib/{rdig_adapter.rb → acts_as_ferret/rdig_adapter.rb} +0 -1
- data/lib/{remote_functions.rb → acts_as_ferret/remote_functions.rb} +0 -0
- data/lib/{remote_index.rb → acts_as_ferret/remote_index.rb} +0 -0
- data/lib/{remote_multi_index.rb → acts_as_ferret/remote_multi_index.rb} +0 -0
- data/lib/{search_results.rb → acts_as_ferret/search_results.rb} +0 -0
- data/lib/acts_as_ferret/server/config.rb +50 -0
- data/lib/{ferret_server.rb → acts_as_ferret/server/server.rb} +11 -56
- data/lib/{unix_daemon.rb → acts_as_ferret/server/unix_daemon.rb} +2 -4
- data/lib/acts_as_ferret/version.rb +3 -0
- data/lib/{without_ar.rb → acts_as_ferret/without_ar.rb} +0 -0
- data/recipes/aaf_recipes.rb +2 -4
- data/script/ferret_server +72 -6
- data/tasks/ferret.rake +13 -9
- metadata +68 -39
- data/acts_as_ferret.gemspec +0 -59
- data/init.rb +0 -24
- data/install.rb +0 -18
- data/lib/ar_mysql_auto_reconnect_patch.rb +0 -41
- data/lib/server_manager.rb +0 -71
- data/script/ferret_daemon +0 -94
- data/script/ferret_service +0 -178
data/README
CHANGED
@@ -19,13 +19,9 @@ http://github.com/jkraemer/acts_as_ferret/tree/master .
|
|
19
19
|
|
20
20
|
=== Set up your Rails > 2.1 project to use the acts_as_ferret gem.
|
21
21
|
|
22
|
-
Add this to your project's config/environment.rb
|
22
|
+
Add this to your project's config/environment.rb:
|
23
23
|
|
24
|
-
<tt>
|
25
|
-
config.gem 'acts_as_ferret', :version => '~> 0.4.8'
|
26
|
-
config.after_initialize { ActsAsFerret::load_config }
|
27
|
-
config.to_prepare { ActsAsFerret::load_config }
|
28
|
-
</tt>
|
24
|
+
<tt>config.gem 'acts_as_ferret', :version => '~> 0.4.8'</tt>
|
29
25
|
|
30
26
|
With the gem installed, change into your RAILS_ROOT and run the supplied aaf_install script.
|
31
27
|
This will copy rake tasks, capistrano recipes and the ferret server config and startup script
|
data/bin/aaf_install
CHANGED
@@ -1,18 +1,23 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
#
|
2
3
|
# acts_as_ferret gem install script
|
3
|
-
#
|
4
|
+
#
|
5
|
+
# Call this from Rails.root to install start/stop script, sample config and
|
6
|
+
# Capistrano recipes into your rails project.
|
7
|
+
|
4
8
|
require 'fileutils'
|
5
9
|
|
6
10
|
@basedir = File.join(File.dirname(__FILE__), '..')
|
7
11
|
|
8
|
-
def install(src, target_dir, executable=false)
|
12
|
+
def install(src, target_dir, executable=false, overwrite=false)
|
9
13
|
puts "Installing: #{src}"
|
10
14
|
src = File.join(@basedir, src)
|
11
15
|
fname = File.basename(src)
|
12
16
|
target = File.join(target_dir, fname)
|
13
|
-
if File.exists?(target)
|
17
|
+
if !overwrite && File.exists?(target)
|
14
18
|
puts "#{target} already exists, skipping"
|
15
19
|
else
|
20
|
+
FileUtils.rm_f target
|
16
21
|
FileUtils.mkdir_p target_dir
|
17
22
|
FileUtils.cp src, target
|
18
23
|
FileUtils.chmod 0755, target if executable
|
@@ -20,10 +25,9 @@ def install(src, target_dir, executable=false)
|
|
20
25
|
end
|
21
26
|
|
22
27
|
|
23
|
-
install 'script/ferret_server', 'script', true
|
28
|
+
install 'script/ferret_server', 'script', true, true
|
24
29
|
install 'config/ferret_server.yml', 'config'
|
25
|
-
install '
|
26
|
-
install 'recipes/aaf_recipes.rb', 'lib/recipes'
|
30
|
+
install 'recipes/aaf_recipes.rb', 'lib/recipes', false, true
|
27
31
|
|
28
32
|
puts IO.read(File.join(@basedir, 'README'))
|
29
33
|
|
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
|
@@ -9,7 +9,7 @@ class Stats < ActiveRecord::Base
|
|
9
9
|
where kind=? group by time;
|
10
10
|
END
|
11
11
|
result = connection.execute sanitize_sql([sql, start_date, start_date, kind.to_s])
|
12
|
-
[]
|
12
|
+
returning [] do |res|
|
13
13
|
while row = result.fetch_row
|
14
14
|
data = row.last.split(',').map{|t|t.to_i}
|
15
15
|
median = data.size.odd? ? data[data.size/2] : ((data[data.size/2-1]+data[data.size/2]) / 2.0)
|
data/lib/acts_as_ferret.rb
CHANGED
@@ -20,33 +20,34 @@
|
|
20
20
|
|
21
21
|
require 'active_support'
|
22
22
|
require 'active_record'
|
23
|
+
|
23
24
|
require 'set'
|
24
25
|
require 'enumerator'
|
25
26
|
require 'ferret'
|
26
27
|
|
27
|
-
require 'ferret_find_methods'
|
28
|
-
require 'remote_functions'
|
29
|
-
require 'blank_slate'
|
30
|
-
require 'bulk_indexer'
|
31
|
-
require 'ferret_extensions'
|
32
|
-
require 'act_methods'
|
33
|
-
require 'search_results'
|
34
|
-
require 'class_methods'
|
35
|
-
require 'ferret_result'
|
36
|
-
require 'instance_methods'
|
37
|
-
require 'without_ar'
|
28
|
+
require 'acts_as_ferret/ferret_find_methods'
|
29
|
+
require 'acts_as_ferret/remote_functions'
|
30
|
+
require 'acts_as_ferret/blank_slate'
|
31
|
+
require 'acts_as_ferret/bulk_indexer'
|
32
|
+
require 'acts_as_ferret/ferret_extensions'
|
33
|
+
require 'acts_as_ferret/act_methods'
|
34
|
+
require 'acts_as_ferret/search_results'
|
35
|
+
require 'acts_as_ferret/class_methods'
|
36
|
+
require 'acts_as_ferret/ferret_result'
|
37
|
+
require 'acts_as_ferret/instance_methods'
|
38
|
+
require 'acts_as_ferret/without_ar'
|
38
39
|
|
39
|
-
require 'multi_index'
|
40
|
-
require 'remote_multi_index'
|
41
|
-
require 'more_like_this'
|
40
|
+
require 'acts_as_ferret/multi_index'
|
41
|
+
require 'acts_as_ferret/remote_multi_index'
|
42
|
+
require 'acts_as_ferret/more_like_this'
|
42
43
|
|
43
|
-
require 'index'
|
44
|
-
require 'local_index'
|
45
|
-
require 'remote_index'
|
44
|
+
require 'acts_as_ferret/index'
|
45
|
+
require 'acts_as_ferret/local_index'
|
46
|
+
require 'acts_as_ferret/remote_index'
|
46
47
|
|
47
|
-
require '
|
48
|
+
require 'acts_as_ferret/server/server'
|
48
49
|
|
49
|
-
require 'rdig_adapter'
|
50
|
+
require 'acts_as_ferret/rdig_adapter'
|
50
51
|
|
51
52
|
# The Rails ActiveRecord Ferret Mixin.
|
52
53
|
#
|
@@ -82,12 +83,14 @@ require 'rdig_adapter'
|
|
82
83
|
# whatever reason.
|
83
84
|
#
|
84
85
|
# 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
|
86
|
+
# config/ferret_server.yml contains a section for the current Rails.env
|
86
87
|
# Usually you won't need to touch this option - just configure DRb for
|
87
88
|
# production mode in ferret_server.yml.
|
88
89
|
#
|
89
90
|
module ActsAsFerret
|
90
91
|
|
92
|
+
require 'acts_as_ferret/railtie' if defined?(Rails)
|
93
|
+
|
91
94
|
class ActsAsFerretError < StandardError; end
|
92
95
|
class IndexNotDefined < ActsAsFerretError; end
|
93
96
|
class IndexAlreadyDefined < ActsAsFerretError; end
|
@@ -107,7 +110,7 @@ module ActsAsFerret
|
|
107
110
|
@@index_using_classes = {}
|
108
111
|
def self.index_using_classes; @@index_using_classes end
|
109
112
|
|
110
|
-
@@logger = Logger.new "#{
|
113
|
+
@@logger = Logger.new "#{Rails.root || '.'}/log/acts_as_ferret.log"
|
111
114
|
@@logger.level = ActiveRecord::Base.logger.level rescue Logger::DEBUG
|
112
115
|
mattr_accessor :logger
|
113
116
|
|
@@ -129,10 +132,10 @@ module ActsAsFerret
|
|
129
132
|
mattr_accessor :remote
|
130
133
|
def self.remote?
|
131
134
|
if @@remote.nil?
|
132
|
-
if ENV["FERRET_USE_LOCAL_INDEX"] || ActsAsFerret::
|
135
|
+
if ENV["FERRET_USE_LOCAL_INDEX"] || ActsAsFerret::Server::Server.running
|
133
136
|
@@remote = false
|
134
137
|
else
|
135
|
-
@@remote = ActsAsFerret::
|
138
|
+
@@remote = ActsAsFerret::Server::Config.new.uri rescue false
|
136
139
|
end
|
137
140
|
if @@remote
|
138
141
|
logger.info "Will use remote index server which should be available at #{@@remote}"
|
@@ -255,7 +258,7 @@ module ActsAsFerret
|
|
255
258
|
|
256
259
|
def self.load_config
|
257
260
|
# using require_dependency to make the reloading in dev mode work.
|
258
|
-
require_dependency "#{
|
261
|
+
require_dependency "#{Rails.root}/config/aaf.rb"
|
259
262
|
ActsAsFerret::logger.info "loaded configuration file aaf.rb"
|
260
263
|
rescue LoadError
|
261
264
|
ensure
|
@@ -456,8 +459,6 @@ module ActsAsFerret
|
|
456
459
|
# get objects for each model
|
457
460
|
id_arrays.each do |model, id_array|
|
458
461
|
next if id_array.empty?
|
459
|
-
# logger.debug "id array from index: #{id_array.inspect}"
|
460
|
-
|
461
462
|
model_class = model.constantize
|
462
463
|
|
463
464
|
# merge conditions
|
@@ -486,21 +487,20 @@ module ActsAsFerret
|
|
486
487
|
|
487
488
|
# order results as they were found by ferret, unless an AR :order
|
488
489
|
# option was given
|
489
|
-
# logger.debug "unsorted result: #{result.map{|a| "#{a.id} / #{a.title} / #{a.ferret_rank}"}.inspect}"
|
490
490
|
result.sort! { |a, b| a.ferret_rank <=> b.ferret_rank } unless find_options[:order]
|
491
|
-
# logger.debug "sorted result: #{result.map{|a| "#{a.id} / #{a.ferret_rank}"}.inspect}"
|
492
491
|
return result
|
493
492
|
end
|
494
493
|
|
495
494
|
# combine our conditions with those given by user, if any
|
496
495
|
def self.combine_conditions(conditions, additional_conditions = [])
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
496
|
+
returning conditions do
|
497
|
+
if additional_conditions && additional_conditions.any?
|
498
|
+
cust_opts = (Array === additional_conditions) ? additional_conditions.dup : [ additional_conditions ]
|
499
|
+
logger.debug "cust_opts: #{cust_opts.inspect}"
|
500
|
+
conditions.first << " and " << cust_opts.shift
|
501
|
+
conditions.concat(cust_opts)
|
502
|
+
end
|
502
503
|
end
|
503
|
-
return conditions
|
504
504
|
end
|
505
505
|
|
506
506
|
def self.build_field_config(fields)
|
@@ -521,10 +521,10 @@ module ActsAsFerret
|
|
521
521
|
|
522
522
|
|
523
523
|
# make sure the default index base dir exists. by default, all indexes are created
|
524
|
-
# under
|
524
|
+
# under Rails.root/index/Rails.env
|
525
525
|
def self.init_index_basedir
|
526
|
-
index_base = "#{
|
527
|
-
@@index_dir = "#{index_base}/#{
|
526
|
+
index_base = "#{Rails.root || '.'}/index"
|
527
|
+
@@index_dir = "#{index_base}/#{Rails.env}"
|
528
528
|
end
|
529
529
|
|
530
530
|
mattr_accessor :index_dir
|
@@ -591,3 +591,5 @@ end
|
|
591
591
|
# include acts_as_ferret method into ActiveRecord::Base
|
592
592
|
ActiveRecord::Base.extend ActsAsFerret::ActMethods
|
593
593
|
|
594
|
+
|
595
|
+
|
@@ -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
|
File without changes
|
File without changes
|
File without changes
|
@@ -94,20 +94,6 @@ module Ferret
|
|
94
94
|
flush()
|
95
95
|
end
|
96
96
|
end
|
97
|
-
|
98
|
-
# search for the first document with +arg+ in the +id+ field and return it's internal document number.
|
99
|
-
# The +id+ field is either :id or whatever you set
|
100
|
-
# :id_field parameter to when you create the Index object.
|
101
|
-
def doc_number(id)
|
102
|
-
@dir.synchronize do
|
103
|
-
ensure_reader_open()
|
104
|
-
term_doc_enum = @reader.term_docs_for(@id_field, id.to_s)
|
105
|
-
return term_doc_enum.next? ? term_doc_enum.doc : nil
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
private
|
110
|
-
|
111
97
|
|
112
98
|
# If +docs+ is a Hash or an Array then a batch delete will be performed.
|
113
99
|
# If +docs+ is an Array then it will be considered an array of +id+'s. If
|
@@ -148,7 +134,17 @@ module Ferret
|
|
148
134
|
end
|
149
135
|
return self
|
150
136
|
end
|
151
|
-
|
137
|
+
|
138
|
+
# search for the first document with +arg+ in the +id+ field and return it's internal document number.
|
139
|
+
# The +id+ field is either :id or whatever you set
|
140
|
+
# :id_field parameter to when you create the Index object.
|
141
|
+
def doc_number(id)
|
142
|
+
@dir.synchronize do
|
143
|
+
ensure_reader_open()
|
144
|
+
term_doc_enum = @reader.term_docs_for(@id_field, id.to_s)
|
145
|
+
return term_doc_enum.next? ? term_doc_enum.doc : nil
|
146
|
+
end
|
147
|
+
end
|
152
148
|
end
|
153
149
|
|
154
150
|
# add marshalling support to SortFields
|
@@ -179,7 +175,7 @@ module Ferret
|
|
179
175
|
# we exclude the last <DOC> sorting as it is appended by new anyway
|
180
176
|
if string =~ /^Sort\[(.*?)(<DOC>(!)?)?\]$/
|
181
177
|
sort_fields = $1.split(',').map do |value|
|
182
|
-
|
178
|
+
value.strip!
|
183
179
|
Ferret::Search::SortField._load value unless value.blank?
|
184
180
|
end
|
185
181
|
new sort_fields.compact
|
File without changes
|
File without changes
|
File without changes
|
@@ -125,7 +125,7 @@ module ActsAsFerret #:nodoc:
|
|
125
125
|
# fieldname => value pairs)
|
126
126
|
def to_doc
|
127
127
|
logger.debug "creating doc for class: #{self.ferret_key}"
|
128
|
-
Ferret::Document.new
|
128
|
+
returning Ferret::Document.new do |doc|
|
129
129
|
# store the id and class name of each item, and the unique key used for identifying the record
|
130
130
|
# even in multi-class indexes.
|
131
131
|
doc[:key] = self.ferret_key
|
@@ -16,9 +16,9 @@ module ActsAsFerret
|
|
16
16
|
# The 'real' Ferret Index instance
|
17
17
|
def ferret_index
|
18
18
|
ensure_index_exists
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
returning @ferret_index ||= Ferret::Index::Index.new(index_definition[:ferret]) do
|
20
|
+
@ferret_index.batch_size = index_definition[:reindex_batch_size]
|
21
|
+
@ferret_index.logger = logger
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -73,6 +73,9 @@ module ActsAsFerret
|
|
73
73
|
reader.tokenized_fields unless options[:tokenized_fields]
|
74
74
|
return qp.parse query
|
75
75
|
else
|
76
|
+
# work around ferret bug in #process_query (doesn't ensure the
|
77
|
+
# reader is open)
|
78
|
+
ferret_index.send(:ensure_reader_open)
|
76
79
|
return ferret_index.process_query(query)
|
77
80
|
end
|
78
81
|
end
|
@@ -148,7 +151,7 @@ module ActsAsFerret
|
|
148
151
|
return Ferret::Search::TermQuery.new(:key, key.to_s)
|
149
152
|
# if shared?
|
150
153
|
# raise InvalidArgumentError.new("shared index needs class_name argument") if class_name.nil?
|
151
|
-
# Ferret::Search::BooleanQuery.new
|
154
|
+
# returning bq = Ferret::Search::BooleanQuery.new do
|
152
155
|
# bq.add_query(Ferret::Search::TermQuery.new(:id, id.to_s), :must)
|
153
156
|
# bq.add_query(Ferret::Search::TermQuery.new(:class_name, class_name), :must)
|
154
157
|
# end
|
File without changes
|
File without changes
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'acts_as_ferret'
|
2
|
+
require 'rails'
|
3
|
+
|
4
|
+
module ActsAsFerret
|
5
|
+
|
6
|
+
class Railtie < Rails::Railtie
|
7
|
+
|
8
|
+
rake_tasks do
|
9
|
+
load File.join(File.dirname(__FILE__), '../../tasks/ferret.rake')
|
10
|
+
end
|
11
|
+
|
12
|
+
config.to_prepare { ActsAsFerret::load_config }
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
module ActsAsFerret
|
5
|
+
module Server
|
6
|
+
|
7
|
+
class Config
|
8
|
+
|
9
|
+
################################################################################
|
10
|
+
DEFAULTS = {
|
11
|
+
'host' => 'localhost',
|
12
|
+
'port' => '9009',
|
13
|
+
'cf' => "config/ferret_server.yml",
|
14
|
+
'pid_file' => "log/ferret_server.pid",
|
15
|
+
'log_file' => "log/ferret_server.log",
|
16
|
+
'log_level' => 'debug',
|
17
|
+
'socket' => nil,
|
18
|
+
'script' => nil
|
19
|
+
}
|
20
|
+
|
21
|
+
################################################################################
|
22
|
+
# load the configuration file and apply default settings
|
23
|
+
def initialize(file = DEFAULTS['cf'])
|
24
|
+
@everything = YAML.load(ERB.new(IO.read(abs_config_file_path(file))).result)
|
25
|
+
raise "malformed ferret server config" unless @everything.is_a?(Hash)
|
26
|
+
@config = DEFAULTS.merge(@everything[Rails.env] || {})
|
27
|
+
if @everything[Rails.env]
|
28
|
+
@config['uri'] = socket.nil? ? "druby://#{host}:#{port}" : "drbunix:#{socket}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def abs_config_file_path(path)
|
33
|
+
if path =~ /^\//
|
34
|
+
path
|
35
|
+
else
|
36
|
+
Rails.root.join(path).to_s
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
################################################################################
|
41
|
+
# treat the keys of the config data as methods
|
42
|
+
def method_missing (name, *args)
|
43
|
+
@config.has_key?(name.to_s) ? @config[name.to_s] : super
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
@@ -1,52 +1,18 @@
|
|
1
1
|
require 'drb'
|
2
2
|
require 'thread'
|
3
|
-
require 'yaml'
|
4
|
-
require 'erb'
|
5
3
|
|
6
|
-
|
7
|
-
|
8
|
-
module Remote
|
9
|
-
|
10
|
-
################################################################################
|
11
|
-
class Config
|
12
|
-
|
13
|
-
################################################################################
|
14
|
-
DEFAULTS = {
|
15
|
-
'host' => 'localhost',
|
16
|
-
'port' => '9009',
|
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
|
-
'log_level' => 'debug',
|
21
|
-
'socket' => nil,
|
22
|
-
'script' => nil
|
23
|
-
}
|
24
|
-
|
25
|
-
################################################################################
|
26
|
-
# load the configuration file and apply default settings
|
27
|
-
def initialize (file=DEFAULTS['cf'])
|
28
|
-
@everything = YAML.load(ERB.new(IO.read(file)).result)
|
29
|
-
raise "malformed ferret server config" unless @everything.is_a?(Hash)
|
30
|
-
@config = DEFAULTS.merge(@everything[RAILS_ENV] || {})
|
31
|
-
if @everything[RAILS_ENV]
|
32
|
-
@config['uri'] = socket.nil? ? "druby://#{host}:#{port}" : "drbunix:#{socket}"
|
33
|
-
end
|
34
|
-
end
|
4
|
+
require 'acts_as_ferret/server/unix_daemon'
|
5
|
+
require 'acts_as_ferret/server/config'
|
35
6
|
|
36
|
-
|
37
|
-
|
38
|
-
def method_missing (name, *args)
|
39
|
-
@config.has_key?(name.to_s) ? @config[name.to_s] : super
|
40
|
-
end
|
7
|
+
module ActsAsFerret
|
8
|
+
module Server
|
41
9
|
|
42
|
-
end
|
43
10
|
|
44
|
-
#################################################################################
|
45
11
|
# This class acts as a drb server listening for indexing and
|
46
12
|
# search requests from models declared to 'acts_as_ferret :remote => true'
|
47
13
|
#
|
48
14
|
# Usage:
|
49
|
-
# - modify
|
15
|
+
# - modify Rails.root/config/ferret_server.yml to suit your needs.
|
50
16
|
# - environments for which no section in the config file exists will use
|
51
17
|
# the index locally (good for unit tests/development mode)
|
52
18
|
# - run script/ferret_server to start the server:
|
@@ -55,41 +21,31 @@ module ActsAsFerret
|
|
55
21
|
# script/ferret_server -e production stop
|
56
22
|
#
|
57
23
|
class Server
|
58
|
-
|
59
|
-
#################################################################################
|
60
|
-
# FIXME include detection of OS and include the correct file
|
61
|
-
require 'unix_daemon'
|
62
|
-
include(ActsAsFerret::Remote::UnixDaemon)
|
24
|
+
include UnixDaemon
|
63
25
|
|
64
26
|
|
65
|
-
################################################################################
|
66
27
|
cattr_accessor :running
|
67
28
|
|
68
|
-
################################################################################
|
69
29
|
def initialize
|
70
|
-
|
71
|
-
require 'ar_mysql_auto_reconnect_patch'
|
72
|
-
@cfg = ActsAsFerret::Remote::Config.new
|
30
|
+
@cfg = Config.new
|
73
31
|
ActiveRecord::Base.logger = @logger = Logger.new(@cfg.log_file)
|
74
32
|
ActiveRecord::Base.logger.level = Logger.const_get(@cfg.log_level.upcase) rescue Logger::DEBUG
|
75
33
|
if @cfg.script
|
76
|
-
path = File.join(
|
34
|
+
path = File.join(Rails.root, @cfg.script)
|
77
35
|
load path
|
78
36
|
@logger.info "loaded custom startup script from #{path}"
|
79
37
|
end
|
80
38
|
end
|
81
39
|
|
82
|
-
################################################################################
|
83
40
|
# start the server as a daemon process
|
84
41
|
def start
|
85
|
-
raise "ferret_server not configured for #{
|
42
|
+
raise "ferret_server not configured for #{Rails.env}" unless (@cfg.uri rescue nil)
|
86
43
|
platform_daemon { run_drb_service }
|
87
44
|
end
|
88
45
|
|
89
|
-
################################################################################
|
90
46
|
# run the server and block until it exits
|
91
47
|
def run
|
92
|
-
raise "ferret_server not configured for #{
|
48
|
+
raise "ferret_server not configured for #{Rails.env}" unless (@cfg.uri rescue nil)
|
93
49
|
run_drb_service
|
94
50
|
end
|
95
51
|
|
@@ -103,7 +59,6 @@ module ActsAsFerret
|
|
103
59
|
raise
|
104
60
|
end
|
105
61
|
|
106
|
-
#################################################################################
|
107
62
|
# handles all incoming method calls, and sends them on to the correct local index
|
108
63
|
# instance.
|
109
64
|
#
|
@@ -227,7 +182,7 @@ module ActsAsFerret
|
|
227
182
|
:create => true,
|
228
183
|
:field_infos => ActsAsFerret::field_infos(index_definition),
|
229
184
|
:path => File.join(index_definition[:index_base_dir], 'rebuild')
|
230
|
-
Ferret::Index::Index.new(ferret_cfg)
|
185
|
+
returning Ferret::Index::Index.new(ferret_cfg) do |i|
|
231
186
|
i.batch_size = index_definition[:reindex_batch_size]
|
232
187
|
i.logger = @logger
|
233
188
|
end
|